Editing a .pth file

Hello ,
I want to analyse a densenet-121 model code on my spyder 4.0
but the pth file I downloaded from a link from github is not opening properly
I dont want to “load” the model I want to edit it.
how should i go about it

Hi,

There files are saved with pickle so they are compressed. I don’t think you will be able to modify them without using a python environment that loads the model, do the modifications and save it back.

any step by step procedure or blog that you know of
i am using conda with spyder 4.0

What I have in mind is just the following:

old_model = torch.load("model.pth")
# Change the model here
new_model = your_change(old_model)
torch.save(new_model, "new_model.pth")

where can I get a noob friendly Densenet-121 pytorch code

You can find it in the models available in torchvision: https://pytorch.org/docs/stable/torchvision/models.html

1 Like