title: What's the difference between these two code for inference with toy MNIST example
body: <p>I found that there're different accuracy values between those two codes.
  I think that those are the same codes but give different values.
  Why are the results of the two codes different?</p>
  <p><strong>[ code 1 ]</strong></p>
  <pre><code>def mytest(model, data_loader):
      with torch.no_grad():
          corrected_sample = 0
          for x_test, y_test in data_loader:
              x_test, y_test = x_test.to(device), y_test.to(device)
              x_test = x_test.view(-1,28*28).float()
              prediction = model(x_test)
              #predicted_class = prediction.max(1)[1]
              predicted_class = torch.argmax(prediction, 1)
              corrected_sample += (predicted_class==y_test).float().sum().item()
      accuracy = corrected_sample / len(data_loader.dataset)
      print(&quot;Accuracy : {}&quot;.format(accuracy))
  
  data_loader_test = torch.utils.data.DataLoader(mnist_test, batch_size=1, shuffle=False)
  mytest(model, data_loader_test)
  </code></pre>
  <blockquote>
  <blockquote>
  <p>Accuracy : 0.92232</p>
  </blockquote>
  </blockquote>
  <p><strong>[ code 2 ]</strong></p>
  <pre><code>with torch.no_grad():
      x_test = mnist_test.test_data.view(-1,28*28).float().to(device)
      y_test = mnist_test.test_labels.to(device)
  
      prediction = model(x_test)
      correct_prediction = torch.argmax(prediction,1) == y_test
      accuracy = correct_prediction.float().mean()
      print(&quot;Accuracy &quot;, accuracy.item())
  </code></pre>
  <blockquote>
  <blockquote>
  <p>Accuracy  0.8826999664306641</p>
  </blockquote>
  </blockquote>