I guess the author wanted to reinitialize the first linear layer, as it’s using the same config, and create a smaller feature space with only 10 outputs for the CIFAR10 dataset, but you might want to ask the author of this code about their intention.
The layers are modified and the original .classifier module is defined as:
Thanks! It someone wanted to be less ambitious, and just append one new layer
to knock down the number of classes, would they replace those 3 Linear layers lines
with just this one modification?..
model.classifier[7] = torch.nn.Linear(1000,10)
From your print(model.classifier) output, it looks like this would be a clean way to just
tweak the number of AlexNet outputs without messing with AlexNet’s architecture no?
No, this won’t work as you will get an indexing error.
You could append layers to model.classifier instead.
However, note that appending a new classification layer after the original one is not a common approach as you would rather replace the last classification layer with your own one.
The reason to do so is to be able to use the features to train the model for your use case instead of using the logits for 1000 classes to train your 10 classes.