Problems
Loading...
Step 3 of 6
VGG Classifier Head
Easy

Implement the VGG classifier. Flatten each NHWC feature tensor, apply two supplied affine layers with ReLU, then apply a final affine layer without activation. Return raw class logits as a float64 NumPy array with shape (B, C_classes).

Loading visualization...

Examples

Input: features = [[[[1,-1]]]], W1 = [[0.5,-0.2],[0.3,0.4]], b1 = [0.1,0], W2 = [[1,-0.5],[0.2,0.3]], b2 = [0,0.1], W3 = [[0.4,-0.1],[0.5,0.2]], b3 = [0.05,-0.05]

Output: [[0.17,-0.08]]

Explanation: Flattening converts the spatial feature volume into one vector before the three affine layers.

Input: features = [[[[1],[2]],[[3],[4]]]], W1 = [[1],[0.5],[-0.5],[0.25]], b1 = [0], W2 = [[2]], b2 = [-1], W3 = [[0.3,-0.2,0.1]], b3 = [0,0.1,-0.1]

Output: [[0.6,-0.3,0.1]]

Input: features = [[[[1,0]]],[[[-1,2]]]], W1 = [[1,-1],[0.5,1]], b1 = [0,0], W2 = [[1],[0.5]], b2 = [0.1], W3 = [[1,-1]], b3 = [0.2,0.3]

Output: [[1.3,-0.8],[1.8,-1.3]]

Hint 1

Reshape features to (batch_size, -1).

Hint 2

Apply np.maximum(0.0, value) after the first two layers only.

Requirements

  • Use NumPy.
  • Flatten all non-batch dimensions in row-major order.
  • Apply ReLU after the first and second affine layers only.
  • Return float64 raw logits.

Constraints

  • features has NHWC layout and dtype float64.
  • W1 matches the flattened feature width.
  • W2 and W3 match adjacent hidden widths.
  • Every bias matches its layer output width.
  • Every supplied array has dtype float64.