Skip to content

Instantly share code, notes, and snippets.

@Mehdi-Amine
Last active June 22, 2020 20:33
Show Gist options
  • Save Mehdi-Amine/c084b4ecf05662dae957f53400957010 to your computer and use it in GitHub Desktop.
Save Mehdi-Amine/c084b4ecf05662dae957f53400957010 to your computer and use it in GitHub Desktop.
investigating nn with the first three instances of the test set
test_dl = DataLoader(test_ds, batch_size=3) # Step 1
net.eval()
with torch.no_grad():
for testx, testy in test_dl:
print("batch: ", testx, testy)
linout = net(testx) # Step 2
print("linear outputs: ", linout)
prob = F.softmax(linout, dim=1) # Step 3
print("softmax probabilities:", prob)
_, pred = torch.max(prob,1) # Step 4
print("predictions:", pred)
break # breaking the loop after the first batch
'''
Out:
batch: tensor([[-1.2074, 1.3340, 1.0000],
[-0.1828, 0.8066, 1.0000],
[-1.0836, -0.6887, 0.0000]]) tensor([1, 1, 0])
linear outputs: tensor([[ -8.5264, 7.5463],
[-10.7886, 10.3464],
[ 4.5804, -5.5217]])
softmax probabilities: tensor([[1.0464e-07, 1.0000e+00],
[6.6248e-10, 1.0000e+00],
[9.9996e-01, 4.0994e-05]])
predictions: tensor([1, 1, 0])
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment