记录YOLO v5 错误
train.py 报错一:a view of a leaf Variable that requires grad is being used in an in-place operation.
解决办法:找到在File "C:\Users\it possible\Documents\yolov5Project\yolov5-master\models\yolo.py"的line 145
将代码修改为:
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)
train.py报错二:AttributeError: module numpy has no attribute int .
解决办法:重新安装numpy
pip uninstall numpy
pip install numpy==1.22
dectect.py报错一:Backend QtAgg is interactive backend. Turning interactive mode on.
将matplotlib的backend设置为非交互式。
D:\Anaconda3\envs[your environment]\Lib\site-packages\matplotlib\mpl-data\matplotlibrc
You can also deploy your own backend outside of matplotlib by
referring to the module name (which must be in the PYTHONPATH) as
‘module://my_backend’.
#backend : Agg
去掉注释:backend : Agg
dectect.py报错二:tourch.nn.modules.module.ModuleAttributeError:‘Hardswish’ object has no attribute ‘inplace’
打开torch/nn/modules路径下的activation.py文件(具体路径可以看你的报错信息),定位到438行,去掉‘ self.inplace’
修改前
def forward(self, input: Tensor) -> Tensor:
return F.hardswish(input, self.inplace)
修改后
def forward(self, input: Tensor) -> Tensor:
return F.hardswish(input)
参考:
- https://blog.csdn.net/Xunuo1995/article/details/115454076
- https://blog.csdn.net/weixin_46669612/article/details/129624331
- https://codeleading.com/article/89025983578/
- https://blog.csdn.net/weixin_44942126/article/details/120184159