Argmax returns the position where values are highest. In multicategory image classification, it turns a model’s ten-value output into the predicted class index. section 2.4.2
Listing 2.10 Testing the trained model on five images
plt.figure(dpi=300,figsize=(5,1))
for i in range(5): #1
ax=plt.subplot(1,5, i + 1)
img=test_set[i][0]
label=test_set[i][1]
img=img/2+0.5
img=img.reshape(28, 28)
plt.imshow(img, cmap="binary")
plt.axis('off')
plt.title(text_labels[label]+f"; {label}", fontsize=8)
plt.show()
for i in range(5):
img,label = test_set[i] #2
img=img.reshape(-1,28*28).to(device)
pred=model(img) #3
index_pred=torch.argmax(pred,dim=1) #4
idx=index_pred.item()
print(f"the label is {label}; the prediction is {idx}") #5
The test loop applies torch.argmax(pred, dim=1) to five clothing images and prints each predicted index beside its actual label. section 2.4.2

