You could set the required_grad property to False for the freezed layers:
model.g1[2].weight.requires_grad = False
...

Based on your code you could also set it in the loop where you assign the pre-trained weights to the parameter.
Also, you could just pass the trainable parameters to the optimizer:
optimizer = optim.SGD(filter(lambda p: p.requires_grad, model.parameters()), lr=0.1)