一、錯(cuò)誤1
Can't get attribute 'SPPF' on <module 'models.common' from 'D:\\Pycharm\\Code\\yolov5-5.0\\models\\common.py'>
解決方案1
你可以去github上,這兒我用的是YOLOv5.5的版本,就去Tags6里面的model/common.py里面去找到這個(gè)SPPF的類,把它拷過來到你這個(gè)Tags5的model/common.py里面,這樣你的代碼就也有這個(gè)類了,還要引入一個(gè)warnings包就行了
點(diǎn)開common.py文件
import warnings
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))
將這個(gè)復(fù)制到對應(yīng)的類就行了。
二、 錯(cuò)誤2
剛解決了上一個(gè)問題,結(jié)果又出現(xiàn)了問題,我也很崩潰,差了半天,也沒有找到解決辦法,最終,我找到了,哈哈,讓我笑一會?。?!下面看錯(cuò)誤:文章來源:http://www.zghlxwxcb.cn/news/detail-601100.html
RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton
解決方案2:
注意看這兩個(gè)是否對應(yīng):
因?yàn)槲疫\(yùn)行代碼的是后模型沒有下載下來,所以自己去github上下載的模型,然后出錯(cuò)了,就是模型錯(cuò)了,這兒給出地址:
https://github.com/ultralytics/yolov5/releases/download/v5.0/yolov5s.pt
下載到
如圖同級目錄下就行了,然后就可以運(yùn)行了!文章來源地址http://www.zghlxwxcb.cn/news/detail-601100.html
到了這里,關(guān)于【解決問題】RuntimeError: The size of tensor a (80) must match the size of tensor b (56) at non-singleton的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!