Can I ask, when I tried to add another additional linear layer, but it came out with
RuntimeError: Error(s) in loading statam e_dict for ResNet: size mismatch for fc.2.weight: copying a param with shape torch.Size([20, 100]) from checkpoint, the shape in current model is torch.Size([60, 100]). size mismatch for fc.2.bias: copying a parwith shape torch.Size([20]) from checkpoint, the shape in current model is torch.Size([60]). size mismatch for fc.5.weight: copying a param with shape torch.Size([4, 20]) from checkpoint, the shape in current model is torch.Size([20]). size mismatch for fc.5.bias: copying a param with shape torch.Size([4]) from checkpoint, the shape in current model is torch.Size([20]).
I’ve already state strict = False, when i load my model. What else could I be doing wrong?
def initModel4():
resnetbase = models.resnet34(pretrained=True).to(device)
for param in resnetbase.parameters(): #Freeze all the layers and train only the last layer
param.requires_grad = False
#   add in dropout layer
fc_layers = nn.Sequential(
nn.Linear(resnetbase.fc.in_features,100),
nn.Hardswish(),
nn.Linear(100, 20),
nn.BatchNorm1d(20),
nn.Dropout(0.12),
nn.Linear(20, 10),
nn.Linear(10, 4),
).to(device)
##weights for background imgs, tanks, floating head tanks, tank clusters
class_weights = torch.FloatTensor([0.1,0.5,0.3,2.0]).to(device)
loss_function = nn.CrossEntropyLoss(torch.FloatTensor([0.2,0.6,0.4,2.0])).to(device)
optimizer = torch.optim.Adam(resnetbase.parameters(), lr=lr)
scheduler = torch.optim.lr_scheduler.StepLR(optimizer, step_size=3, gamma=0.1)
return