目录
报错
OpenCV can't augment image: 608 x 608
The size of tensor a (19) must match the size of tensor b (76) at non-singleton dimension 3
NotImplementedError: Create your own 'get_image_id' function"
view size is not compatible with input tensor’s size and stride
CUDA error: an illegal memory access was encountered
can't convert cuda:0 device type tensor to numpy.
知识点
YOLOv5超参介绍
YOLOv5n6.yaml文件介绍
报错
OpenCV can't augment image: 608 x 608
opencv版本问题,装的太高,降级:
代码语言:javascript复制pip install opencv_python==3.4.4.19
The size of tensor a (19) must match the size of tensor b (76) at non-singleton dimension 3
train.py文件中:
代码语言:javascript复制self.strides = [8, 16, 32] t改为 self.strides = [32, 16]
for i in range(3): 改为 for i in range(len(self.strides)):
NotImplementedError: Create your own 'get_image_id' function"
dataset.py文件中get_image_id函数:
先注释掉前面的:
代码语言:javascript复制raise NotImplementedError("Create your own 'get_image_id' function")
再根据自己图片的命名规则,提取名称中的id,如对于图片“level1_123.jpg”,可以这样写:
代码语言:javascript复制lv, no = os.path.splitext(os.path.basename(filename))[0].split("_")
lv = lv.replace("level", "")
no = f"{int(no):04d}"
view size is not compatible with input tensor’s size and stride
yolo_layer.py文件中,在view()前面加上contiguous(),如:
代码语言:javascript复制det_confs = det_confs.contiguous().view(output.size(0), num_anchors * output.size(2) * output.size(3), 1)
或者就用reshape来代替view(推荐):
代码语言:javascript复制det_confs = det_confs.reshape(output.size(0), num_anchors * output.size(2) * output.size(3), 1)
CUDA error: an illegal memory access was encountered
升级pytorch,我是从1.8.0直接升到最新的1.10.0,就好了。
代码语言:javascript复制pip3 install torch==1.10.0 cu113 torchvision==0.11.1 cu113 torchaudio===0.10.0 cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
can't convert cuda:0 device type tensor to numpy.
utils/plots.py文件中,注释“if isinstance(output, torch.Tensor):”。需要这句:
代码语言:javascript复制output = output.cpu().numpy()
知识点
YOLOv5超参介绍
代码语言:javascript复制# Hyperparameter evolution metadata (mutation scale 0-1, lower_limit, upper_limit)
meta = {'lr0': (1, 1e-5, 1e-1), # 初始学习率(SGD=1E-2, Adam=1E-3)
'lrf': (1, 0.01, 1.0), # 余弦退火超参数学习率(lr0 * lrf)
'momentum': (0.3, 0.6, 0.98), # SGD学习率动量/Adam beta1
'weight_decay': (1, 0.0, 0.001), # 优化器权重衰减系数
'warmup_epochs': (1, 0.0, 5.0), # 预热学习epoch(fractions ok)
'warmup_momentum': (1, 0.0, 0.95), # 预热学习率动量
'warmup_bias_lr': (1, 0.0, 0.2), # 初始预热学习率
'box': (1, 0.02, 0.2), # giou损失的系数
'cls': (1, 0.2, 4.0), # 分类损失的系数
'cls_pw': (1, 0.5, 2.0), # 分类BCELoss中正样本的权重
'obj': (1, 0.2, 4.0), # obj损失的系数(像素级缩放)
'obj_pw': (1, 0.5, 2.0), # 物体BCELoss中正样本的权重
'iou_t': (0, 0.1, 0.7), # 标签与anchors的iou阈值
'anchor_t': (1, 2.0, 8.0), # 标签的长h宽w/anchor的长h_a宽w_a阈值, 即h/h_a, w/w_a都要在(1/2.0, 8.0)之间
'anchors': (2, 2.0, 10.0), # 每个输出网格的锚点(0为忽略)
# 下面是一些数据增强的系数, 包括颜色空间和图片空间
'fl_gamma': (0, 0.0, 2.0), # 焦点损失gamma(efficientDet默认gamma=1.5)
'hsv_h': (1, 0.0, 0.1), # 图像hsv -色调增强(小数)
'hsv_s': (1, 0.0, 0.9), # 图像hsv -饱和度增强(小数)
'hsv_v': (1, 0.0, 0.9), # 图像hsv -明度增强(小数)
'degrees': (1, 0.0, 45.0), # 图像旋转( /- 角度 )
'translate': (1, 0.0, 0.9), # 图像水平和垂直平移 ( /- 小数)
'scale': (1, 0.0, 0.9), # 图像缩放( /- 比例)
'shear': (1, 0.0, 10.0), # 图像剪切( /- 程度)
'perspective': (0, 0.0, 0.001), # 图像透视变换( /- 小数),范围0-0.001
'flipud': (1, 0.0, 1.0), # 图像上下翻转 (probability)
'fliplr': (0, 0.0, 1.0), # 图像左右翻转 (probability)
'mosaic': (1, 0.0, 1.0), # 图像马赛克 (probability)
'mixup': (1, 0.0, 1.0), # 图像混合 (probability)
'copy_paste': (1, 0.0, 1.0)} # 段复制粘贴 (probability)
}
YOLOv5n6.yaml文件介绍
代码语言:javascript复制# YOLOv5