Saving the weights of a Pytorch .pth model into a .txt or .json
I am trying to save the the weights of a pytorch model into a .txt or .json. When writing it to a .txt,
#import torch
model = torch.load(&quot;model_path&quot;)
string = str(model)
with open('some_file.txt', 'w') as fp:
     fp.write(string)

I get a file where not all the weights are saved, i.e there are ellipsis throughout the textfile. I cannot write it to a JSON since the model has tensors, which are not JSON serializable [unless there is a way that I do not know?] How can I save the weights in the .pth file to some format such that no information is lost, and can be easily seen?
Thanks

When you are doing str(model.state_dict()), it recursively uses str method of elements it contains. So the problem is how individual element string representations are build. You should increase the limit of lines printed in individual string representation:
torch.set_printoptions(profile=&quot;full&quot;)

See the difference with this:
import torch
import torchvision.models as models
mobilenet_v2 = models.mobilenet_v2()
torch.set_printoptions(profile=&quot;default&quot;)
print(mobilenet_v2.state_dict()['features.2.conv.0.0.weight'])
torch.set_printoptions(profile=&quot;full&quot;)
print(mobilenet_v2.state_dict()['features.2.conv.0.0.weight'])

Tensors are currently not JSON serializable.
