Changing a layer inside torch.nn.Sequential wrapper

Viewed 1053

I was working with a transfer learning task.

Inadvertently, to make things easier, I put all the last layers in a torch.nn.Sequential wrapper like this-

self.fc=nn.Sequential(
            nn.Linear(24*24*64,80),
            nn.ReLU(True),
            nn.Linear(80,964),
        )

Now what I wanted to do is to change the last 80-unit linear layer with an identity mapping. I had trained this network and saved the weights, and I don't want to train it again (time-consuming :( ).

Is there any way I can replace the Linear layer inside ?

I know the usual outer layer replacement with model.fc1=nn.Identity(), but I just do not think this can happen here, as the last fc individual layers are not single objects, and wrapped in the Sequential layer object.

Perhaps, another hack around ? I have all the time amidst the coronavirus crisis :), any other solution would do ?

0 Answers
Related