RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel

简介: RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future rel

项目场景:


提示:新版python在pytorch中张量与原始数据的除法计算问题。


问题描述


报错


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)


目录
打赏
0
0
0
0
691
分享
相关文章
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.
2577 0
【Python】已解决:ValueError: Length mismatch: Expected axis has 5 elements, new values have 4 elements
【Python】已解决:ValueError: Length mismatch: Expected axis has 5 elements, new values have 4 elements
668 9
|
8月前
|
CDN
Iconfont——Error: <path> attribute d: Expected number, "MNaNNaNaNaNNaNNaN…".
Iconfont——Error: <path> attribute d: Expected number, "MNaNNaNaNaNNaNNaN…".
76 0
【完美解决】RuntimeError: one of the variables needed for gradient computation has been modified by an inp
将loss.backward()函数内的参数retain_graph值设置为True, loss.backward(retain_graph=True),如果retain_graph设置为False,计算过程中的中间变量使用完即被释放掉。
1950 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
320 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
error: implicit declaration of function ‘RAND_egd’ [-Werror=implicit-function-declaration]
error: implicit declaration of function ‘RAND_egd’ [-Werror=implicit-function-declaration]
154 0
error: implicit declaration of function ‘VerifyFixClassname‘ is invalid in C99 [-Werror,-Wimplicit-f
error: implicit declaration of function ‘VerifyFixClassname‘ is invalid in C99 [-Werror,-Wimplicit-f
170 0
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'
498 0
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等