In one table, record each Layer's name, predicted output shape, and actual output shape. Fill in predictions before running the code. If any row differs, explain which operation changed the dimensions.
2. Batch size and parameters
Feed inputs with Batch Sizes to the same CNN built in the previous activity. Keep the other input axes at (1,28,28) and run in model.eval() mode.
Record , final output shape, and Parameter count in three columns. Compute the Parameter count with sum(p.numel() for p in model.parameters()); model is the CNN you built.
Check whether each row has output shape (N,10) and whether the Parameter count is the same across all three rows. Also distinguish which Layers have trainable Parameters.
Submission and saving
Include code, actual outputs and plots, and your own interpretation. Submit through KLAS; check the semester schedule and latest announcements for the deadline.
Filename: Name_StudentID_Week9.ipynb.
Restart the runtime, run all code from the top, then save.
Optional practice
When input image size does not match Linear input size
After running the small model in the first example, add a Code Cell at the bottom of the notebook and run the following code.
for side in [32, 28]:
debug_image = torch.randn(1, 1, side, side)
with torch.no_grad():
debug_features = small[:-1](debug_image)
print("Input:", debug_image.shape,
"Flatten:", debug_features.shape,
"Linear in_features:", small[-1].in_features)
try:
print("Output:", small(debug_image).shape)
except (RuntimeError, ValueError) as error:
print(type(error).__name__, str(error))
In a Text Cell, tabulate the Flatten shape and execution success for each image size. Find which of the two cases matches the input count required by Linear, and record how many inputs were supplied in the failing case.