YOLOR -自己踩得坑

YOLOR -自己踩得坑

代码地址:https://github.com/WongKinYiu/yolor

  • 跑通 YOLOR-main

1.数据集: PASCAL VOC
数据集部分:我的是一开始就是YOLO格式,但是这个项目需要labels和图片放在同一个文件夹中,
或者自己改一下代码部,更改地址: utils -> datasets.py 文件中(373行)

sa, sb = os.sep + 'images' + os.sep, os.sep + 'labels' + os.sep  # /images/, /labels/ substrings
return [x.replace(sa, sb, 1).replace(x.split('.')[-1], 'txt') for x in img_paths]
  1. 自己需要在wandb.id中注册一个账号,训练一开始需要输入自己的 wandb_id
  2. 我遇到的各种报错如下(搞了一天了我都忘记了):
  • can’t convert cuda:0 device type tensor to numpy when using distributed gpu with large batch size
    *解决办法:注释掉 test.py 中以下这一块代码
 # Plot images
        if plots and batch_i < 3:
            f = save_dir / f'test_batch{batch_i}_labels.jpg'  # filename
            plot_images(img, targets, paths, f, names)  # labels
            f = save_dir / f'test_batch{batch_i}_pred.jpg'
            plot_images(img, output_to_target(output, width, height), paths, f, names)  # predictions
  • Images sizes do not match. This will causes images to be display incorrectly
  • FileNotFoundError: [Errno 2] No such file or directory: ‘r’
  • FileNotFoundError: [Errno 2] No such file or directory: ‘y’
  • FileNotFoundError: [Errno 2] No such file or directory: ‘h’
    *解决办法:更改 test.py 中代码
 try:
        ckpt = torch.load(weights, map_location=device)  # load checkpoint  更改weights[0]  保存的模型文件。
        ckpt['model'] = {k: v for k, v in ckpt['model'].items() if model.state_dict()[k].numel() == v.numel()}
        model.load_state_dict(ckpt['model'], strict=False)
    except:
        print('11', weights)
        load_darknet_weights(model, weights)   # 更改weights[0]  解析并加载存储在'weights'中的权重
    imgsz = check_img_size(imgsz, s=64)  # check img_size
  • 因为权重文件有两种—— “.pt” 和 “.weights"结尾的,以”.pt"结尾的文件需要用 torch.load()来读取,以 ".weights"结尾的文件需要用 load_darknet_weights()来读取.
  • finetuning时候报错如下:
 File "train.py", line 545, in <module>
    train(hyp, opt, device, tb_writer, wandb)
  File "train.py", line 404, in train
    'wandb_id': wandb_run.id if wandb else None}

*解决办法: 在 train.py 我就自己手动加上 wandb_id, 更改如下:

  ckpt = {'epoch': epoch,
           'best_fitness': best_fitness,
           'best_fitness_p': best_fitness_p,
           'best_fitness_r': best_fitness_r,
           'best_fitness_ap50': best_fitness_ap50,
           'best_fitness_ap': best_fitness_ap,
           'best_fitness_f': best_fitness_f,
           'training_results': f.read(),
           'model': ema.ema.module.state_dict() if hasattr(ema, 'module') else ema.ema.state_dict(),
           'optimizer': None if final_epoch else optimizer.state_dict(),
           'wandb_id': 'f4c0d9a5c52db44ec548217c0c0bbaa********'  #  这里写上自己的wadb id      
           # 'wandb_id': wandb_run.id if wandb else None   # 这里我注释掉了
         }

  • 报错wandb没有初始化,在test.py 文件一开始加上以下代码:
 import wandb
 wandb.init()
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值