Hi,
I am playing around with the Pytorch library and trying to use Transfer Learning.
My code is as follows:
# get the model with pre-trained weights
resnet18 = models.resnet18(pretrained=True)
# freeze all the layers
for param in resnet18.parameters():
param.requires_grad = False
# print and check what the last FC layer is:
# Linear(in_features=512, out_features=1000, bias=True)
print(resnet18)
# set the final FC layer to what we require for our problem
resnet18.fc = nn.Linear(512, 10)
# unfreeze the last layer so it learns on our dataset
for param in resnet18.fc.parameters():
param.requires_grad = True
I set the optimizer as:
# set optimizer
lr = 1e-2
optimizer = torch.optim.SGD(resnet18.parameters(), lr=lr, momentum=0.5)
Training this model on CIFAR10 gives me a very poor training accuracy of 44%.
Am I doing transfer learning correctly here? I would have expected much better results.
I followed the tutorial here:
https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html