YOLOv5 训练报错记录(持续更新中...)

1、AttributeError: Can’t get attribute ‘C3’

AttributeError: Can’t get attribute ‘C3’ on <module ‘models.common’ from ‘/root/deepstream_yolov5/yolov5/models/common.py’>

models/common.py 中没有 C3,全局查找,发现在 models/experimental.py 里,把这个类粘过来就行了

2、RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

Traceback (most recent call last):
  File "train.py", line 453, in <module>
    train(hyp, opt, device, tb_writer)
  File "train.py", line 70, in train
    model = Model(opt.cfg or ckpt['model'].yaml, ch=3, nc=nc).to(device)  # create
  File "/home/zhangli/code/yolov5.3/models/yolo.py", line 85, in __init__
    self._initialize_biases()  # only run once
  File "/home/zhangli/code/yolov5.3/models/yolo.py", line 143, in _initialize_biases
    b[:, 4] += math.log(8 / (640 / s) ** 2)  # obj (8 objects per 640 image)
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

修改 models/yolo.py 中的 _initialize_biases 函数为:

def _initialize_biases(self, cf=None):  # initialize biases into Detect(), cf is class frequency
    # cf = torch.bincount(torch.tensor(np.concatenate(dataset.labels, 0)[:, 0]).long(), minlength=nc) + 1.
    m = self.model[-1]  # Detect() module
    for mi, s in zip(m.m, m.stride):  # from
        b = mi.bias.view(m.na, -1)  # conv.bias(255) to (3,85)
        with torch.no_grad():
            b[:, 4] += math.log(8 / (640 / s) ** 2)  # obj (8 objects per 640 image)
            b[:, 5:] += math.log(0.6 / (m.nc - 0.99)) if cf is None else torch.log(cf / cf.sum())  # cls
        mi.bias = torch.nn.Parameter(b.view(-1), requires_grad=True)

3、AssertionError: WARNING: No labels found in xxx… Can not train without labels.

WARNING: No labels found in /home/zhangli/data/voc/Allride_2D_20210804/JPEGImages/. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
Traceback (most recent call last):
  File "train.py", line 453, in <module>
    train(hyp, opt, device, tb_writer)
  File "train.py", line 161, in train
    dataloader, dataset = create_dataloader(train_path, imgsz, batch_size, gs, opt, hyp=hyp, augment=True,
  File "/home/zhangli/code/yolov5.3/utils/datasets.py", line 53, in create_dataloader
    dataset = LoadImagesAndLabels(path, imgsz, batch_size,
  File "/home/zhangli/code/yolov5.3/utils/datasets.py", line 432, in __init__
    assert not augment, '%s. Can not train without labels.' % s
AssertionError: WARNING: No labels found in /home/zhangli/data/voc/Allride_2D_20210804/JPEGImages/. See https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data. Can not train without labels.

找到 utils/datasets.py,搜索 Define labels,将 images 修改为 JPEGImages,修改后如下

# Define labels
self.label_files = [x.replace('JPEGImages', 'labels').replace(os.path.splitext(x)[-1], '.txt') for x in self.img_files]

4、PyTorch版本降级 / 安装指定版本PyTorch

https://pytorch.org/get-started/previous-versions/

5、AttributeError: Can’t get attribute ‘SiLU’

Traceback (most recent call last):
  File "train.py", line 453, in <module>
    train(hyp, opt, device, tb_writer)
  File "train.py", line 69, in train
    ckpt = torch.load(weights, map_location=device)  # load checkpoint
  File "/home/zhangli/anaconda3/envs/yolov5.3/lib/python3.8/site-packages/torch/serialization.py", line 584, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/home/zhangli/anaconda3/envs/yolov5.3/lib/python3.8/site-packages/torch/serialization.py", line 842, in _load
    result = unpickler.load()
AttributeError: Can't get attribute 'SiLU' on torch.nn.modules.activation' from '/home/zhangli/anaconda3/envs/yolov5.3/lib/python3.8/site-packages/torch/nn/modules/activation.py'>

pytorch版本问题(1.7以上似乎不会有这个问题),可将SiLU粘过来

class SiLU(Module):  # export-friendly version of nn.SiLU()
    @staticmethod
    def forward(x):
        return x * torch.sigmoid(x)

6、RuntimeError: Unable to find a valid cuDNN algorithm to run convolution

batch-size过大,调小即可

7、non-normalized or out of bounds coordinate labels

坐标没有归一化,把YOLOv5-v5.0里的相关内容拿过来,若数据存在non-normalized or out of bounds coordinate labels问题,忽略即可

你可能感兴趣的:(python,图像处理,视觉检测,深度学习)