DL0024 Fixed-size Input in CNN

What is the “dilemma of fixed-size input” for CNNs? How is it typically resolved?

Answer

The dilemma of fixed-size input is the constraint that classic CNN classifiers (VGG, early ResNets) only accept images of one predetermined resolution: the fully connected head has a weight matrix whose input dimension equals the flattened feature-map size, and that size is only constant if every input image has the same H \times W. Real-world images arrive in arbitrary sizes, so they must be resized or cropped first, distorting aspect ratios, discarding small objects, or cutting content away.

(1) The FC Head Is the Bottleneck: Convolutions themselves handle any spatial size; only the flatten + FC stage pins the input dimensions.
(2) Preprocessing Costs Information: Resizing squishes content and can erase small objects; cropping keeps resolution but discards everything outside the window.
(3) Structural Fixes Exist: Replace or decouple the FC head (GAP, fully convolutional designs, or adaptive pooling) and the network accepts variable sizes natively.

Three panels showing an original scene with one large and several small objects, a heavily downsampled version where the small objects disappear, and a center crop where objects near the edges are cut away.

Figure 1: Both standard fixes hurt: downsampling erases small objects; cropping amputates anything near the border.

Mathematical Formulation (Why the FC Head Fixes the Size):
z = W \cdot \mathrm{vec}(X) + b, \quad X \in \mathbb{R}^{H \times W \times C}
\mathrm{GAP}(X)_c = \frac{1}{HW} \sum_{h=1}^{H} \sum_{w=1}^{W} X_{hwc}

Where:

  • X is the final feature volume; \mathrm{vec}(X) flattens it to HWC values, so W exists only for one specific H \times W.
  • \mathrm{GAP}(X)_c averages channel c over all spatial positions, yielding a C-dimensional vector for any input size.

Common Solutions: (1) Global Average Pooling: replace the flatten with a per-channel average, so the classifier sees exactly C values regardless of resolution; (2) Fully Convolutional Networks: remove FC layers entirely and let the output scale with the input (standard for segmentation); (3) Adaptive Pooling: pool to a fixed k \times k grid no matter the input size (e.g., nn.AdaptiveAvgPool2d in PyTorch).

Diagram of a variable-size input feeding three solution paths, global average pooling, fully convolutional network, and adaptive pooling, all converging to a fixed classifier head that accepts any input size.

Figure 2: Three structural escapes (GAP, FCN, and adaptive pooling) all remove the fixed-size constraint at its source: the FC head.


Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *