Debug:RuntimeError: expected scalar type Half but found Float


  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())  # 转换

然后仔细看了一下输出的网络结构,发现网络结构配置文件有问题。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值