Premium problem69. Tiny CNN Classifier

Medium Locked

Build this classifier and return the logits it produces for x, which has shape (B, C, H, W):

  • Conv2d(C, 4, kernel_size=3, padding=1)
  • ReLU
  • AdaptiveAvgPool2d(1)
  • Flatten
  • Linear(4, num_classes)

Call torch.manual_seed(seed) immediately before building the layers, so the weights are reproducible, and run the model in evaluation mode under torch.no_grad(). Return the (B, num_classes) output.

Returning the model itself would not work: two models with identical weights are different objects, and the grader compares values.

Input

x =
tensor([[[[0.0000, 0.0312, 0.0625, 0.0938],
          [0.1250, 0.1562, 0.1875, 0.2188],
          [0.2500, 0.2812, 0.3125, 0.3438],
          [0.3750, 0.4062, 0.4375, 0.4688]]],


        [[[0.5000, 0.5312, 0.5625, 0.5938],
          [0.6250, 0.6562, 0.6875, 0.7188],
          [0.7500, 0.7812, 0.8125, 0.8438],
          [0.8750, 0.9062, 0.9375, 0.9688]]]])
num_classes = 3
seed = 0

Output

tensor([[0.1514, 0.1003, 0.4262],
        [0.2119, 0.1763, 0.4660]])

Premium problem

This one's part of Premium. Unlock the full PyTorch track plus every other premium problem on the site.

Implement solve(...)