Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: Input type (float) and bias type (c10::Half) should be the same #18

Open
Zzzz1zzz opened this issue Apr 24, 2023 · 2 comments

Comments

@Zzzz1zzz
Copy link

使用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`
@Zzzz1zzz
Copy link
Author

运行环境:pytorch2.0 python=3.8

@YOSHIKII666
Copy link

yolov7在训练的时候是混合精度训练,测试或者验证的时候用的是半精度推理,生成位置掩码position那个变量在验证的时候是float32的,此时卷积权重是float16的,你position转成float16就好了。另外pytorch里面nn.conv是可以兼容float32和float16的,但是yolo里test.py里面写了model=model.half(),这个时候就只能算输入为float16的tensor。
最后说一下这个模块加到yolov7里面效果一般,计算量挺大的,推理速度有点慢。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants