A target domain is the new dataset or problem where a pretrained model is adapted. In the ResNet example, cats-versus-dogs classification is the target domain, replacing ImageNet's 1,000-class output with two outputs. section 13.2
Use the target domain to guide transfer-learning changes:
- Replace the pretrained network's final classifier so its outputs match the target classes. section 13.2
- Prefer a source dataset that is larger and sufficiently relevant, because reusable learned patterns can reduce what must be learned from scratch. section 13.2.1
Cats-versus-dogs adaptation
Instantiate ResNet-18, retain its learned feature layers, and replace its 1,000-output classifier with nn.Linear(model.fc.in_features, 2). Train the resulting model with CrossEntropyLoss. section 13.2
Figure 13.3 The left side shows a summary of ResNet. We want to alter it to look like the right side, where only the last nn.Linear layer has been changed. The input to each nn.Linear layer is 512 because the final convolutional layer has C = 512 channels, and using adaptive average pooling down to just 1 × 1 means there are only 512 values in the output, regardless of the size of the original image.
Compare the original ResNet classifier with the adapted two-output classifier and see why adaptive pooling preserves a fixed feature width. section 13.2
