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

加--fp16训练老师模型后,再训练学生模型报错 #3

Open
LiangYongAI opened this issue Jul 20, 2022 · 1 comment
Open

Comments

@LiangYongAI
Copy link

@xiao-hua-sheng 在训练老师模型时加--fp16,然后再用老师模型指导学生模型训练,也加--fp16,在训练开始的时候报错,Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same,完整错误如下所示:

File "/opt/YOLOX-Distill/yolox/core/trainer.py", line 105, in train_one_iter
self.T_pre = self.T_model(inps)
│ │ │ │ └ tensor([[[[112., 112., 112., ..., 77., 77., 77.],
│ │ │ │ [113., 111., 111., ..., 73., 75., 75.],
│ │ │ │ [114., ...
│ │ │ └ YOLOX(
│ │ │ (backbone): YOLOPAFPN(
│ │ │ (backbone): CSPDarknet(
│ │ │ (stem): Focus(
│ │ │ (conv): BaseConv(
│ │ │ (conv): ...
│ │ └ <yolox.core.trainer.Trainer object at 0x7f4baf145ed0>
│ └ None
└ <yolox.core.trainer.Trainer object at 0x7f4baf145ed0>

File "/home/ubuntu/anaconda3/envs/yolox/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
│ │ └ {}
│ └ (tensor([[[[112., 112., 112., ..., 77., 77., 77.],
│ [113., 111., 111., ..., 73., 75., 75.],
│ [114.,...
└ <bound method YOLOX.forward of YOLOX(
(backbone): YOLOPAFPN(
(backbone): CSPDarknet(
(stem): Focus(
(conv...

File "/opt/YOLOX-Distill/yolox/models/yolox.py", line 31, in forward
fpn_outs = self.backbone(x)
│ └ tensor([[[[112., 112., 112., ..., 77., 77., 77.],
│ [113., 111., 111., ..., 73., 75., 75.],
│ [114., ...
└ YOLOX(
(backbone): YOLOPAFPN(
(backbone): CSPDarknet(
(stem): Focus(
(conv): BaseConv(
(conv): ...

File "/home/ubuntu/anaconda3/envs/yolox/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
│ │ └ {}
│ └ (tensor([[[[112., 112., 112., ..., 77., 77., 77.],
│ [113., 111., 111., ..., 73., 75., 75.],
│ [114.,...
└ <bound method YOLOPAFPN.forward of YOLOPAFPN(
(backbone): CSPDarknet(
(stem): Focus(
(conv): BaseConv(
(c...

File "/opt/YOLOX-Distill/yolox/models/yolo_pafpn.py", line 93, in forward
out_features = self.backbone(input)
│ └ tensor([[[[112., 112., 112., ..., 77., 77., 77.],
│ [113., 111., 111., ..., 73., 75., 75.],
│ [114., ...
└ YOLOPAFPN(
(backbone): CSPDarknet(
(stem): Focus(
(conv): BaseConv(
(conv): Conv2d(12, 48, kernel_size=(3...

File "/home/ubuntu/anaconda3/envs/yolox/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
│ │ └ {}
│ └ (tensor([[[[112., 112., 112., ..., 77., 77., 77.],
│ [113., 111., 111., ..., 73., 75., 75.],
│ [114.,...
└ <bound method CSPDarknet.forward of CSPDarknet(
(stem): Focus(
(conv): BaseConv(
(conv): Conv2d(12, 48, kernel_si...

File "/opt/YOLOX-Distill/yolox/models/darknet.py", line 170, in forward
x = self.stem(x)
│ └ tensor([[[[112., 112., 112., ..., 77., 77., 77.],
│ [113., 111., 111., ..., 73., 75., 75.],
│ [114., ...
└ CSPDarknet(
(stem): Focus(
(conv): BaseConv(
(conv): Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1...

File "/home/ubuntu/anaconda3/envs/yolox/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
│ │ └ {}
│ └ (tensor([[[[112., 112., 112., ..., 77., 77., 77.],
│ [113., 111., 111., ..., 73., 75., 75.],
│ [114.,...
└ <bound method Focus.forward of Focus(
(conv): BaseConv(
(conv): Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), paddi...

File "/opt/YOLOX-Distill/yolox/models/network_blocks.py", line 210, in forward
return self.conv(x)
│ └ tensor([[[[112., 112., 113., ..., 77., 77., 77.],
│ [114., 112., 114., ..., 76., 76., 75.],
│ [115., ...
└ Focus(
(conv): BaseConv(
(conv): Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
(bn)...

File "/home/ubuntu/anaconda3/envs/yolox/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
│ │ └ {}
│ └ (tensor([[[[112., 112., 113., ..., 77., 77., 77.],
│ [114., 112., 114., ..., 76., 76., 75.],
│ [115.,...
└ <bound method BaseConv.forward of BaseConv(
(conv): Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=...

File "/opt/YOLOX-Distill/yolox/models/network_blocks.py", line 51, in forward
return self.act(self.bn(self.conv(x)))
│ │ │ └ tensor([[[[112., 112., 113., ..., 77., 77., 77.],
│ │ │ [114., 112., 114., ..., 76., 76., 75.],
│ │ │ [115., ...
│ │ └ BaseConv(
│ │ (conv): Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
│ │ (bn): BatchNorm2d(48, eps...
│ └ BaseConv(
│ (conv): Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
│ (bn): BatchNorm2d(48, eps...
└ BaseConv(
(conv): Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
(bn): BatchNorm2d(48, eps...

File "/home/ubuntu/anaconda3/envs/yolox/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl
return forward_call(*input, **kwargs)
│ │ └ {}
│ └ (tensor([[[[112., 112., 113., ..., 77., 77., 77.],
│ [114., 112., 114., ..., 76., 76., 75.],
│ [115.,...
└ <bound method Conv2d.forward of Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)>
File "/home/ubuntu/anaconda3/envs/yolox/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 447, in forward
return self._conv_forward(input, self.weight, self.bias)
│ │ │ │ └ Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
│ │ │ └ Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
│ │ └ tensor([[[[112., 112., 113., ..., 77., 77., 77.],
│ │ [114., 112., 114., ..., 76., 76., 75.],
│ │ [115., ...
│ └ <function Conv2d._conv_forward at 0x7f4bc0e67d40>
└ Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
File "/home/ubuntu/anaconda3/envs/yolox/lib/python3.7/site-packages/torch/nn/modules/conv.py", line 444, in _conv_forward
self.padding, self.dilation, self.groups)
│ │ │ │ │ └ 1
│ │ │ │ └ Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
│ │ │ └ (1, 1)
│ │ └ Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
│ └ (1, 1)
└ Conv2d(12, 48, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)

RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same

@xiao-hua-sheng
Copy link
Owner

--fp16暂时只能为False,工作毕竟忙,后面有时间在修改

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