Created
November 21, 2019 18:02
-
-
Save n0obcoder/c136bdb3534ec8cf9a0875dbec3544e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.nn as nn | |
| from torchvision import models | |
| # Defining the model | |
| model = models.resnet34(pretrained = True) | |
| # The original architecture of resnet34 has 1000 neurons(corresponding to 1000 classes on which it was originally trained on) in the final layer. | |
| # So we need to change the final layer according to the number of classes that we have in our dataset | |
| print('model.fc before: ', model.fc) | |
| model_fc_in_features = model.fc.in_features | |
| model.fc = nn.Linear(model_fc_in_features, len(dataset.classes)) | |
| print('model.fc after : ', model.fc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| model.fc before: Linear(in_features=512, out_features=1000, bias=True) | |
| model.fc after : Linear(in_features=512, out_features=6, bias=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment