本人用YOLOv7加入ACmix注意力机制进行目标检测训练时遇到问题如下问题,在git上也发了问题,开始不知道如何解决,后受到以下博主的debug启发RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.cuda.HalfTensor) should be._XC___XC的博客-CSDN博客ACmix如何加入就不介绍了,下面放遇到的报错:
`Traceback (most recent call last):
File "/home/liu/桌面/zwx/YOLOv7-main/train.py", line 613, in <module>
train(hyp, opt, device, tb_writer)
File "/home/liu/桌面/zwx/YOLOv7-main/train.py", line 415, in train
results, maps, times = test.test(data_dict,
File "/home/liu/桌面/zwx/YOLOv7-main/test.py", line 110, in test
out, train_out = model(img, augment=augment) # inference and training outputs
File "/home/liu/anaconda3/envs/yolo-torch2/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/liu/桌面/zwx/YOLOv7-main/models/yolo.py", line 320, in forward
return self.forward_once(x, profile) # single-scale inference, train
File "/home/liu/桌面/zwx/YOLOv7-main/models/yolo.py", line 346, in forward_once
x = m(x) # run
File "/home/liu/anaconda3/envs/yolo-torch2/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/liu/桌面/zwx/YOLOv7-main/models/common.py", line 530, in forward
pe = self.conv_p(position(h, w, x.is_cuda))
File "/home/liu/anaconda3/envs/yolo-torch2/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "/home/liu/anaconda3/envs/yolo-torch2/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 463, in forward
return self._conv_forward(input, self.weight, self.bias)
File "/home/liu/anaconda3/envs/yolo-torch2/lib/python3.8/site-packages/torch/nn/modules/conv.py", line 459, in _conv_forward
return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Input type (float) and bias type (c10::Half) should be the `same`
意思是说 type不同,输入type是float32 ,而bias的type是16。
解决方法:将YOLOv7的 test.py(不是train.py)中第40行处的 half_precision = true参数改为False,
我认为设置为False 就是 不进行半精度的运算