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)


目录
相关文章
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.
2358 0
|
机器学习/深度学习 数据采集
ValueError: Found input variables with inconsistent numbers of samples: [140, 1120] 怎么解决?
这个错误通常发生在机器学习模型的训练中,它表示输入数据的样本数量不一致。在你的情况下,你的输入数据中有两个变量,一个变量的样本数量为140,另一个变量的样本数量为1120,因此这个错误就出现了。 为了解决这个问题,你需要确保所有输入变量的样本数量是相同的。你可以通过以下几种方式来解决这个问题: 检查数据:检查数据是否正确加载,可能会导致数据样本数量不一致。 数据清洗:检查是否有重复的样本或者缺失的样本,如果有则需要对数据进行清洗。 数据对齐:如果你使用了多个数据源,那么你需要对它们进行对齐以确保它们的样本数量一致。 数据重采样:如果数据中有不均衡的样本数量,你可以考虑使用数据重采样方
765 0
|
自然语言处理
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
74 0
Reading the Manual: Event Extraction as Definition Comprehension, EMNLP 2020
|
机器学习/深度学习 PyTorch 算法框架/工具
解决Pytorch中RuntimeError: expected scalar type Double but found Float
解决Pytorch中RuntimeError: expected scalar type Double but found Float
2538 0
|
TensorFlow 算法框架/工具
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
243 0
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
|
数据格式
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
169 0
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]
成功解决ValueError: Found input variables with inconsistent numbers of samples: [86, 891]
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
解决办法:Type safety: The expression of type List needs unchecked conversion to conform
258 0
解决RuntimeError: running_mean should contain 36864 elements not 4096
一般在卷积层Conv2d后添加正则化BNBatchNormal,使得数据在relu激活前不会因为数据过大而导致网络不稳定,而我在代码中BatchNorm2d的输入通道数与前一层Conv2d的输出通道数不一致,导致报这个错,两者修改一直即可(这里修改为36864即可)。
969 0
the code place where the binding is converted to final value displayed in u
the code place where the binding is converted to final value displayed in u
110 0
the code place where the binding is converted to final value displayed in u