欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

yolov5报错解决合集

时间:2023-05-24

报错1:Can't get attribute 'SPPF' on

解决方法:在models/common.py下加入如下代码:

class SPPF(nn.Module): # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher def __init__(self, c1, c2, k=5): # equivalent to SPP(k=(5, 9, 13)) super().__init__() c_ = c1 // 2 # hidden channels self.cv1 = Conv(c1, c_, 1, 1) self.cv2 = Conv(c_ * 4, c2, 1, 1) self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2) def forward(self, x): x = self.cv1(x) with warnings.catch_warnings(): warnings.simplefilter('ignore') # suppress torch 1.9.0 max_pool2d() warning y1 = self.m(x) y2 = self.m(y1) return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

并且在开头引用:

import warnings

报错2:RuntimeError: Given groups=1, weight of size 【512, 1024, 1, 1】, expected input【1, 512, 8, 8】 to have 1024 channels, but got 512 channels instead

解决方法:修改cfg参数如下:

parser.add_argument('--cfg', type=str, default='models/yolov5s.yaml', help='model.yaml path')

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。