YOLOv5_OBB_KLD icon indicating copy to clipboard operation
YOLOv5_OBB_KLD copied to clipboard

detect报错

Open Pearliz opened this issue 3 years ago • 7 comments

大佬大佬,请问要怎么样解决? 使用TPH训练,使用检测命令加载该训练权重时 python detect.py --weights runs_swin/exp/weights/best.pt 出现报错 Fusing layers... Traceback (most recent call last): File "detect.py", line 350, in detect(kld_flag=opt.kld) File "detect.py", line 54, in detect model = attempt_load(weights, map_location=device) # load FP32 model File "/content/drive//YOLOv5_OBB_KLD/models/experimental.py", line 150, in attempt_load model.append(torch.load(w, map_location=map_location)['model'].float().fuse().eval()) # load FP32 model File "/content/drive//YOLOv5_OBB_KLD/models/yolo_new.py", line 165, in fuse if isinstance(m, (Conv, DWConv)) and hasattr(m, 'bn'): # 如果函数层名为Conv标准卷积层,且同时 层中包含‘bn’属性名 TypeError: isinstance() arg 2 must be a type or tuple of types

Pearliz avatar Dec 15 '21 07:12 Pearliz

models/common_new.py 中 class Conv(nn.Module):中将 def forward_fuse(self, x) 函数名改成 与models/common.py中Conv一样的fuseforward的名字。 YOLOv5_OBB_KLD/models/yolo_new.py 中 改成 for m in self.model.modules(): if type(m) is Conv and hasattr(m, 'bn'): # 如果函数层名为Conv标准卷积层,且同时 层中包含‘bn’属性名 m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatability m.conv = fuse_conv_and_bn(m.conv, m.bn) # update conv delattr(m, 'bn') # remove batchnorm 将'bn'属性删除 m.forward = m.fuseforward # update forward self.info()

lx-cly avatar Dec 16 '21 06:12 lx-cly

哇谢谢大佬回复,重新git pull了代码,又产生如下问题: (1)train时未开启kld,还有角度信息angle Epoch gpu_mem box obj cls angle total targets img_size 95/99 7.28G 0.8553 0.04603 0.01225 0.2448 1.158 101 1024: 100% 11/11 [00:10<00:00, 1.04it/s] train时开启kld,每个epoch的angle为0 Epoch gpu_mem box obj cls angle total targets img_size 91/99 7.29G 0.4632 0.06264 0.01249 0 0.5384 62 1024: 100% 11/11 [00:08<00:00, 1.27it/s]

(2)detect时,使用上面tph.yaml产生的权重报错 Fusing layers... Model Summary: 382 layers, 4.64237e+07 parameters, 0 gradients Traceback (most recent call last): File "detect.py", line 350, in detect(kld_flag=opt.kld) File "detect.py", line 96, in detect _ = model(img.half() if half else img) if device.type != 'cpu' else None # run once File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/content/drive/My Drive/YOLOv5_OBB_KLD/models/yolo_new.py", line 122, in forward return self.forward_once(x, profile) # single-scale inference, train File "/content/drive/My Drive/YOLOv5_OBB_KLD/models/yolo_new.py", line 140, in forward_once x = m(x) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/content/drive/My Drive/YOLOv5_OBB_KLD/models/common_new.py", line 480, in forward return self.cv3(torch.cat((self.m(self.cv1(x)), self.cv2(x)), dim=1)) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/content/drive/My Drive/YOLOv5_OBB_KLD/models/common_new.py", line 432, in forward x = self.tr(x) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(input, **kwargs) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/container.py", line 117, in forward input = module(input) File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(input, **kwargs) File "/content/drive/My Drive/YOLOv5_OBB_KLD/models/common_new.py", line 398, in forward attn_windows = self.attn(x_windows, mask=attn_mask) # [nWB, MhMw, C] File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 722, in call_impl result = self.forward(*input, **kwargs) File "/content/drive/My Drive/YOLOv5_OBB_KLD/models/common_new.py", line 319, in forward x = (attn @ v).transpose(1, 2).reshape(B, N, C) RuntimeError: Expected object of scalar type Float but got scalar type Half for argument #2 'mat2' in call to _th_bmm_out

求大佬不吝指教~~

Pearliz avatar Dec 17 '21 13:12 Pearliz

1)train时未开启kld,使用的是CSL法,1类为1°,角度信息用分类来获取,angle loss 就是那180个类loss。开启kld之后,角度加上bbox 5参数,一起回归,loss就放在了bbox loss里面了。因为代码基础是根据CSL上改的,所以你开启KLD之后,angle loss 为0。 2)tph.yaml 中模型有用到 Tansformer编码块,我用的代码不支持使用float16。当你要用tansformer的时候,可以在detect 把 half 弄成Flase.

lx-cly avatar Dec 18 '21 02:12 lx-cly

大佬,请问可以和6.0版合并吗,看介绍说6.0版在各方面提升了不少。

Pearliz avatar Mar 25 '22 15:03 Pearliz

大佬,请问可以和6.0版合并吗,看介绍说6.0版在各方面提升了不少。

你看看最新上传的yolov5_obb的代码,具体实验指标还在测试,你可以先试试跑跑看。

lx-cly avatar Mar 26 '22 09:03 lx-cly

好的,请问在yolov5_obb的utils中是不是少了部分文件呀

Pearliz avatar Mar 26 '22 12:03 Pearliz

好的,请问在yolov5_obb的utils中是不是少了部分文件呀

重新上传了文件。

lx-cly avatar Mar 27 '22 03:03 lx-cly