Take a look at this example: here I’m changing the first layer to accomodate 4 channel input, but the kind of modifications you’ve to do is the same.
# Tweak Resnet to support multiple channels
nChannels = 4
learn.model[0][0]=nn.Conv2d(nChannels,64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
learn.model.cuda();
NOTE: LAYER GROUPS
learn.model[GROUP_ID][LAYER_IN_GROUP_ID]
- GROUP_ID: id of the group. Layer groups are used to “manage” multiple layers at once (ie: freezing or lr tweaking). The number of groups depends on the kind of model you’re using (AFAIR resnet34 has 3 groups). For your problem you’ve to work in the last group.
- LAYER_IN_GROUP_ID: id of layer inside the group.