I have been trying to teach myself Pytorch using some Kaggle data on the seedlings competition. My code was working but taking a long time to run so decided to try to freeze all layers except the last, so I added the below code:
All code: https://github.com/christopher-ell/Deep_Learning_Begin/blob/master/fastai_Lecture%202%20-%20Seedlings%20(Pytorch%20only).ipynb 5
Code that started the problem:
num_ftrs = resnet34.fc.in_features

## Freeze all but the last layers
for param in resnet34.parameters():
    ## Each tensor has the flag requires_grad, setting it to false allows freezes
    ## the parmaeter associated with it
    param.requires_grad = False
    
# Parameters of newly constructed modules have requires_grad=True by default
## Create new modules that will become final layer
num_ftrs = resnet34.fc.in_features
print(num_ftrs)
## Give final layers a linear transform with twelve outputs one for each category
resnet34.fc = nn.Linear(num_ftrs, 12)

Any other pointers for my code would also be appreciated.
Thanks