解决pytorch报错RuntimeError: exp_vml_cpu not implemented for 'Byte’问题:
在调试代码过程中遇到报错:
RuntimeError
: exp_vml_cpu
not implemented
for 'Byte'
通过提示可知,报错是因为exp_vml_cpu 不能用于Byte类型计算,这里通过 .dtype 来查看要运算的tensor类型:
print(outputs
.dtype
)
输出:
torch
.uint8
而在计算中,默认采用 torch.float32 进行计算,因此需要将tensor类型进行变换。pytorch官方文档中有各个类型转换的方法:
https://pytorch.org/docs/stable/tensors.html
从中选择相匹配的类型进行转换即可,例如:
outputs
= torch
.cuda
.FloatTensor
(outputs
)
此时输出为:
torch
.float32