A team is training a convolutional neural network (CNN) on a dataset of greyscale medical images. Each image is 256x256 pixels, stored in channels-last (NHWC) format. Which tensor shape correctly represents a single training batch of 32 images when fed into the first convolutional layer?
- A(32, 3, 256, 256) - batch size, channels, height, width
- B(32, 256, 256, 1) - batch size, height, width, channels Correct
- C(32, 256, 256) - batch size, height, width only
- D(1, 32, 256, 256) - channels, batch size, height, width
Why A is wrong: Tempting because NCHW format is valid in some frameworks such as PyTorch, and 3 is the channel count for RGB images. However, greyscale images have 1 channel, not 3, making this shape doubly wrong for this task.
Why B is correct: A greyscale image has exactly one channel. The standard NHWC (batch, height, width, channels) format places the channel count last, giving (32, 256, 256, 1). This matches the expected input shape for most deep learning frameworks in channels-last mode.
Why C is wrong: Omitting the channel dimension is a common shorthand in data pre-processing scripts, but a CNN layer requires an explicit channel dimension. Passing a 3-D tensor without a channel axis causes a shape mismatch error at the convolution operation.
Why D is wrong: The channel count of 1 is numerically correct for greyscale, but placing it in the first axis and the batch size in the second axis inverts the standard batch-first convention, which causes incorrect layer behaviour and gradient computation.