task.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:cloud-ml-sdk 作者: XiaoMi 项目源码 文件源码
def test(epoch):
  model.eval()
  test_loss = 0
  correct = 0
  for data, target in test_loader:
    if args.cuda:
      data, target = data.cuda(), target.cuda()
    data, target = Variable(data, volatile=True), Variable(target)
    output = model(data)
    test_loss += F.nll_loss(output, target).data[0]
    pred = output.data.max(1)[1]  # get the index of the max log-probability
    correct += pred.eq(target.data).cpu().sum()

  test_loss = test_loss
  test_loss /= len(
      test_loader)  # loss function already averages over batch size
  print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n'.format(
      test_loss, correct, len(test_loader.dataset), 100. * correct / len(
          test_loader.dataset)))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号