プリンキピア

第4章分類のための線形ニューラルネットワーク

4.4.5. Prediction4.4.5 予測

Now that training is complete, our model is ready to classify some images.
英語のヒント
訓練が終わったので、モデルはいくつかの画像を分類する準備ができた。
X, y = next(iter(data.val_dataloader()))
preds = model(X).argmax(axis=1)
preds.shape
torch.Size([256])
We are more interested in the images we label incorrectly. We visualize them by comparing their actual labels (first line of text output) with the predictions from the model (second line of text output).
英語のヒント
もっと興味があるのは、間違ったラベルを付けてしまう画像である。実際のラベル(文字出力の1行目)とモデルの予測(文字出力の2行目)を比べることで、それらを可視化する。
wrong = preds.type(y.dtype) != y
X, y, preds = X[wrong], y[wrong], preds[wrong]
labels = [a+'\n'+b for a, b in zip(
    data.text_labels(y), data.text_labels(preds))]
data.visualize([X, y], labels=labels)