File "D:\Anaconda\envs\yolov5_mster\lib\site-packages\torch\nn\modules\conv.py", line 460, in forward
return self._conv_forward(input, self.weight, self.bias)
File "D:\Anaconda\envs\yolov5_mster\lib\site-packages\torch\nn\modules\conv.py", line 456, in _conv_forward
return F.conv2d(input, weight, bias, self.stride,
RuntimeError: expected scalar type Half but found Float
在450行左右:
def _conv_forward(self, input: Tensor, weight: Tensor, bias: Optional[Tensor]):
if self.padding_mode != 'zeros':
return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=self.padding_mode),
weight, bias, self.stride,
_pair(0), self.dilation, self.groups)
input = input.to(torch.float16) # 或者 input = input.half()
weight = weight.to(torch.float16) # 或者 weight = weight.half()
return F.conv2d(input, weight, bias, self.stride,
self.padding, self.dilation, self.groups)
然后又报错:
File "D:\anaconda3\envs\yolov5_master\lib\site-packages\torch\nn\modules\upsampling.py", line 157, in forward
return F.interpolate(input, self.size, self.scale_factor, self.mode, self.align_corners,
File "D:\anaconda3\envs\yolov5_master\lib\site-packages\torch\nn\functional.py", line 4001, in interpolate
return torch._C._nn.upsample_nearest2d(input, output_size, scale_factors)
RuntimeError: "upsample_nearest2d_channels_last" not implemented for 'Half'
然后又改了回来,
然后在linear,115行左右,这个改不改无所谓 主要是网络配置结构有问题
def forward(self, input: Tensor) -> Tensor:
# input = input.half()
# self.weight = torch.nn.Parameter(self.weight.half()) # 确保是半精度
# if self.bias is not None:
# self.bias = torch.nn.Parameter(self.bias.half()) # 转换
然后仔细看了一下输出的网络结构,发现网络结构配置文件有问题。