【发布时间】:2020-08-27 05:19:34
【问题描述】:
我正在处理 BERT 的文本分类问题。在本地机器上训练时一切正常,但切换到服务器时,出现以下错误:
<ipython-input-28-508d35ac5f5f> in flat_accuracy(preds, labels)
5 pred_flat = np.argmax(preds, axis=1).flatten()
6 labels_flat = labels.flatten()
----> 7 return np.sum(pred_flat == labels_flat) / len(labels_flat)
8
9 # Function to calculate the f1_score of our predictions vs labels
TypeError: eq() received an invalid combination of arguments - got (numpy.ndarray), but expected one of:
* (Tensor other)
didn't match because some of the arguments have invalid types: (numpy.ndarray)
* (Number other)
didn't match because some of the arguments have invalid types: (numpy.ndarray)
代码:
def flat_accuracy(preds, labels):
pred_flat = np.argmax(preds, axis=1).flatten()
labels_flat = labels.flatten()
return np.sum(pred_flat == labels_flat) / len(labels_flat)
本地机器上的 Torch 版本:1.4.0
服务器上的 Torch 版本:1.3.1
任何帮助将不胜感激!
【问题讨论】:
标签: numpy machine-learning pytorch tensor