使用BCEWithLogitsLoss()时RuntimeError: result type Float can‘t be cast to the desired output type Long

使用BCEWithLogitsLoss()时RuntimeError: result type Float can't be cast to the desired output type Long

使用BCEWithLogitsLoss(output,target),output 为float类型,target为int64,报错RuntimeError: result type Float can't be cast to the desired output type Long

参考提问,提到

改成BCEWithLogitsLoss(output,target.float())

我理解的是output和target的数据类型应一致,原本target为long类型,output为float,但是无法将output转为long,只能将target转为float。

 


版权声明:本文为langtaosha1996原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。