Learn Before
Feature Extraction in Fully Convolutional Networks
When utilizing a pretrained convolutional neural network, such as ResNet-18, for feature extraction in a Fully Convolutional Network (FCN), the final classification layers must be removed. Specifically, the global average pooling layer and the fully connected layer are discarded because they collapse spatial dimensions and are unnecessary for dense pixel-level predictions. The remaining layers form the feature extraction backbone of the FCN, which produces feature maps with reduced spatial dimensions. For example, given an input with a height of and width of , the forward propagation reduces the spatial dimensions by a factor of , resulting in an output shape of . This extraction process can be implemented in frameworks like PyTorch or MXNet by explicitly selecting all layers except the final pooling and dense layers.
# PyTorch net = nn.Sequential(*list(pretrained_net.children())[:-2])
# MXNet net = nn.HybridSequential() for layer in pretrained_net.features[:-2]: net.add(layer)
0
1
Tags
D2L
Dive into Deep Learning @ D2L