Changing the out_features of an already initialized module won’t work:
resnet18.fc.out_features = 3

since the internal parameters were already created.
You should create a new nn.Linear module and assign it to the .fc attribute:
model = models.resnet18()
mdoel.fc = nn.Linear(512, 3)