RuntimeError: Expected tensor for argument #1 ‘indices‘ to have scalar type Long; but got CUDAFloatT

使用torchsummary 中的 summary函数时,模型中有Embedding层的时候,会报错。原因是Embedding 需要整型的Tensor。

pip install 的torchsummary 不行,没有dtypes这个参数。
所以你下载这里提供的 torchsummary.py 放在你的代码一个目录里即可。

链接: https://pan.baidu.com/s/1HKUZi7Eps1KaA0KvPWfO6A
密码: vku4

这么使用即可:

from torchsummary import summary
summary(model, (1, 100, 8), dtypes=[torch.LongTensor], device='cpu')

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