复现BEVDepth报错
File "BEVDepth/bevdepth/layers/backbones/base_lss_fpn.py", line 309, in forward
x = self.reduce_conv(x)
RuntimeError: Input type (torch.cuda.HalfTensor) and weight type (torch.cuda.FloatTensor) should be the same
原因
由于在使用PyTorch的自动混合精度训练(AMP)时,输入张量和权重张量的数据类型不一致所致。在这种情况下,输入是半精度浮点数(HalfTensor),而权重是单精度浮点数(FloatTensor)。
解决办法
@autocast(Flase)
def forward(self, x):
x = self.reduce_conv(x)
x = self.conv(x) + x
x = self.out_conv(x)
return x
改为
@autocast(True)
def forward(self, x):
x = self.reduce_conv(x)
x = self.conv(x) + x
x = self.out_conv(x)
return x