ACmix
ACmix copied to clipboard
RuntimeError: Input type (float) and bias type (c10::Half) should be the same
使用YOLOv7结合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`
运行环境:pytorch2.0 python=3.8
yolov7在训练的时候是混合精度训练,测试或者验证的时候用的是半精度推理,生成位置掩码position那个变量在验证的时候是float32的,此时卷积权重是float16的,你position转成float16就好了。另外pytorch里面nn.conv是可以兼容float32和float16的,但是yolo里test.py里面写了model=model.half(),这个时候就只能算输入为float16的tensor。 最后说一下这个模块加到yolov7里面效果一般,计算量挺大的,推理速度有点慢。