Conv2D Arithmetic: Parameters, Output Size and Compute

Reported in interviews at Tesla

Problem statement

You are reviewing the stem of an image backbone before it goes into a memory-constrained deployment. Inputs are RGB images of shape $3 \times 224 \times 224$ (channels, height, width). All convolutions are standard 2D convolutions with groups $= 1$ and square kernels, strides and padding.

  • Layer A: $C_{in} = 3$, $C_{out} = 64$, kernel $7 \times 7$, stride 2, padding 3, with a bias term.
  • Layer B (applied to layer A's output): $C_{in} = 64$, $C_{out} = 128$, kernel $3 \times 3$, stride 2, padding 1, without a bias term (a batch normalization layer follows it).

Answer the following:

  1. How do you calculate the parameter count of a CNN built from convolution layers (for example 3x3 kernels), and what else contributes parameters?
  2. How many learnable parameters does layer A have?
  3. How many learnable parameters does layer B have?
  4. A teammate proposes changing layer B to stride 1 and padding 0 to save parameters. What actually changes?
  5. Give the general output-size formula for a convolution and explain where it comes from.
  6. What is the spatial size of the feature map after layers A and B?
  7. What is padding, and which kinds of padding are used?
  8. How many multiply-accumulate operations does layer A perform for one image?
  9. Without framework convolution routines, how would you implement layer A's forward pass in NumPy, and how would you vectorize it?
Show hint

What does one filter look like, and how many of them does the layer hold?

Relevant roles: Deep Learning Engineer, ML Engineer and Research Scientist.

Related free problems