AttributeError: Can’t get attribute ‘SPPF’ on
打开项目-models-common.py,在class SPP前面加入:
class SPPF(nn.Module):
def __init__(self, c1, c2, k=5):
super().__init__()
c_ = c1 // 2
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')
y1 = self.m(x)
y2 = self.m(y1)
return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))
OSError: [WinError 1455] 页面文件太小,无法完成操作。 Error loading
打开项目-utils-datasets.py文件(约81行处):
修改dataloader中的num_workers=0
RuntimeError: result type Float can‘t be cast to the desired output type __int64
打开错误信息中的loss.py文件,最后那段for函数,将其整体替换为yolov5-master版中loss.py最后一段for函数,替换函数如下:
for i in range(self.nl):
anchors, shape = self.anchors[i], p[i].shape
gain[2:6] = torch.tensor(shape)[[3, 2, 3, 2]] # xyxy gain
# Match targets to anchors
t = targets * gain # shape(3,n,7)
if nt:
# Matches
r = t[..., 4:6] / anchors[:, None] # wh ratio
j = torch.max(r, 1 / r).max(2)[0] < self.hyp['anchor_t'] # compare
# j = wh_iou(anchors, t[:, 4:6]) > model.hyp['iou_t'] # iou(3,n)=wh_iou(anchors(3,2), gwh(n,2))
t = t[j] # filter
# Offsets
gxy = t[:, 2:4] # grid xy
gxi = gain[[2, 3]] - gxy # inverse
j, k = ((gxy % 1 < g) & (gxy > 1)).T
l, m = ((gxi % 1 < g) & (gxi > 1)).T
j = torch.stack((torch.ones_like(j), j, k, l, m))
t = t.repeat((5, 1, 1))[j]
offsets = (torch.zeros_like(gxy)[None] + off[:, None])[j]
else:
t = targets[0]
offsets = 0
# Define
bc, gxy, gwh, a = t.chunk(4, 1) # (image, class), grid xy, grid wh, anchors
a, (b, c) = a.long().view(-1), bc.long().T # anchors, image, class
gij = (gxy - offsets).long()
gi, gj = gij.T # grid indices
# Append
indices.append((b, a, gj.clamp_(0, shape[2] - 1), gi.clamp_(0, shape[3] - 1))) # image, anchor, grid
tbox.append(torch.cat((gxy - gij, gwh), 1)) # box
anch.append(anchors[a]) # anchors
tcls.append(c) # class
NotImplementedError: Could not run ‘torchvision::nms’ with arguments from the ‘CUDA’ backend.
版本不匹配/不能调用CUDA
先查看自己的显卡,cuda版本,重新安装cuda,cudnn
当时没有继续报错,第二天又出现此报错!
卸载重装torch和torchvision
查看自己的python版本,根据版本下载再安装
下载网址:https://download.pytorch.org/whl/torch_stable.html
下载时应注意如下:
#先卸载原来的
pip uninstall torch
pip uninstall torchvision
#把下载的文件移到pytorch环境下
#在pytorch环境下安装新的
pip install torch-1.13.0+cu117-cp39-cp39-win_amd64.whl
pip install torchvision-0.14.0+cu117-cp39-cp39-win_amd64.whl
#查看是否安装成功,安装成功即可看见torch和torchvision版本号
conda list
#进入python查看是否可以用gpu训练,Ture则表示成功
python
import torch
print(torch.cuda.is_available())
Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.
将NumPy卸载重装,如果重装失败,检查是不是安装目录有重复的包,删除后重新安装即可
pip uninstall -y numpy
pip uninstall -y setuptools
pip install setuptools
pip install numpy
ImportError: DLL load failed while importing _imaging: 找不到指定的模块。
更新Pillow
python -m pip install --upgrade Pillow
ImportError: DLL load failed while importing ft2font: 找不到指定的模块
把matplotlib换成低版本,进入python环境
python
import matplotlib
print(matplotlib.__version__)#查看当前matplotlib的版本
exit()
pip uninstall matplotlib
pip install matplotlib==3.3.3
LooseVersion = distutils.version.LooseVersion AttributeError: module ‘distutils’ has no attribute ‘version’
setuptools版本过高导致,把setuptools换成低版本
pip uninstall setuptools
pip install setuptools==59.5.0 //需要比之前的低