python升级版本之后不再支持通过/符号进行张量和python原数据的运算处理,需要用函数实现。
报错信息:
RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future release div will perform true division as in Python 3. Use true_divide or floor_divide (// in Python) instead.
出错代码:(100 * correct / total)
其中correct为张量,total为常量。
解决方案:(100 * torch.true_divide(correct,total))
使用pytorch模型提供的处理函数实现即可。
举一反三&总结:
/符号,精确除法,替代函数: torch.true_divide(a,b)
//符号,整除,替代函数:torch.floor_divide(a,b)