How to crop weight file to use as pre-trained model?

hi everyone,
I have created autoencoder model with use ResNet backbone. Then I trained this model. I want to subtract the weight of the encoder part to load it into my normal ResNet model. But I don’t know how to do.
I tried crop autoencoder’s encoder parts model after load autoencoder weight file then I saved this model. But layers name changed and I could not load weight into normal ResNet model.

How can I do ?

By subtract the weights you mean, you want to remove the weights from the autoencoder or you want to take those weights out and place them into your ResNet model?

I want to take those weights out and place them into your ResNet model (just encoder part weights)

You can take out the model state dict from your encoder part and add then take out the other part from the ResNet model.

Encoder = encoder.__dict__

you can then take out the first layer like:

first_layer = Encoder._modules['layer1']

and then you can either take out the layers that you need from your resnet or you can just change the layers.

resnet = torchvision.models.__dict__(resnet50)(pretrained=true)
final_layer = resnet._modules['layer4']

and then pass combine these two. Hope this helps :slight_smile:

I will try. Thanks for your help