Ravindra BagaleCourses & study guides मराठी Track your progress

48. Small CNN Image Project in PyTorch

Data Science

48.4 Holdout Check

Why. Always check a fresh batch — Chapter 38 overfit lesson applies to nets too.

What. Build a new batch with the same rules; evaluate with model.eval() and torch.no_grad().

How.

Holdout check

  1. make_batch(64) as test.
  2. Predict argmax classes.
  3. Print accuracy.
model.eval()
X_test, y_test = make_batch(64)
with torch.no_grad():
 pred = model(X_test).argmax(1)
print("test acc", float((pred == y_test).float().mean()))

Ravindra Bagale's Tip

This easy synthetic task is mainly for learning the PyTorch API. Real photos will need much more data, and later also data augmentation, which means making extra training images by flipping, rotating or cropping them.