L1aoXingyu/code-of-learn-deep-learning-with-pytorch

Chapter_3_LogisticRegression_block15

bgbofficial opened this issue · 1 comments

change:

acc = (mask == y_data).sum().data[0] / y_data.shape[0]
if (e + 1) % 200 == 0:
print('epoch: {}, Loss: {:.5f}, Acc: {:.5f}'.format(e+1, loss.data[0], acc))
)

to

acc = (mask == y_data).sum().numpy() / y_data.size()[0]
if (e + 1) % 200 == 0:
print('epoch: {}, Loss: {:.5f}, Acc: {:.5f}'.format(e+1, loss.detach().numpy(), acc)

change:

acc = (mask == y_data).sum().data[0] / y_data.shape[0]
if (e + 1) % 200 == 0:
print('epoch: {}, Loss: {:.5f}, Acc: {:.5f}'.format(e+1, loss.data[0], acc))
)

to

acc = (mask == y_data).sum().numpy() / y_data.size()[0]
if (e + 1) % 200 == 0:
print('epoch: {}, Loss: {:.5f}, Acc: {:.5f}'.format(e+1, loss.detach().numpy(), acc)

Thanks!