model = torchvision.models.resnet18(pretrained=True)
for param in model.parameters():
    param.requires_grad = False
# Replace the last fully-connected layer
# Parameters of newly constructed modules have requires_grad=True by default
model.fc = nn.Linear(512, 100)

# Optimize only the classifier
optimizer = optim.SGD(model.fc.parameters(), lr=1e-2, momentum=0.9)

What’s difference if I use optimizer = optim.SGD(model.parameters(), lr=1e-2, momentum=0.9).
Also if I have a network with conv1-ReLU-conv2-ReLU-conv3, then I want to fix the weights of conv2.
# set the weights of conv2 requires_grad False.

# Then put the weights of whole network in SGD ?