Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.6.6 评价net在data_iter上的准确性 #163

Open
CKing111 opened this issue Nov 28, 2020 · 0 comments
Open

3.6.6 评价net在data_iter上的准确性 #163

CKing111 opened this issue Nov 28, 2020 · 0 comments

Comments

@CKing111
Copy link

CKing111 commented Nov 28, 2020

正常copy,出现下面问题,不知道怎么处理,求帮助

def evaluate_accuracy(data_iter, net):
acc_sum, n = 0.0, 0
for X, y in data_iter:
acc_sum += (net(X).argmax(dim=1) == y).float().sum().item()
n += y.shape[0]
return acc_sum / n
print(evaluate_accuracy(test_iter, net))


RuntimeError Traceback (most recent call last)
in
6 n += y.shape[0]
7 return acc_sum / n
----> 8 print(evaluate_accuracy(test_iter, net))

in evaluate_accuracy(data_iter, net)
3 acc_sum, n = 0.0, 0
4 for X, y in data_iter:
----> 5 acc_sum += (net(X).argmax(dim=1) == y).float().sum().item()
6 n += y.shape[0]
7 return acc_sum / n

in net(X)
1 def net(X):
----> 2 return softmax(torch.mm(X.view((-1, num_inputs)), W) + b)

RuntimeError: The size of tensor a (10) must match the size of tensor b (3) at non-singleton dimension 1
版本信息
pytorch:
torchvision:
torchtext:
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant