Trying to covert a .pth file into CSV

(Comparatively new to PyTorch)

I have a standalone .pth (PyTorch) file. I want to convert the tensor weights into CSV to understand the file. What is the step-by-step procedure to convert it into a CSV file?

CSV file only stores table-liked object, so basically it depends on the data content in the .pth file.
Can you give an example of the content of the .pth file? You could load it with torch.load("mytorchfile.pth")

Yes, I loaded the data on the terminal. This array appeared. I am not able to interpret it as I do not have the model’s knowledge (attaching a screenshot if that is fine) -

Hi, although it may be exhaustive, you can make sense of the model by looking into the serialized layers and weights shape.

Yes, I was trying to make sense out of it. Wish I was able to see the parameters but I only have the Tensor weightages.

So I guess your .pth file is a model checkpoint, isn’t it?
Your screenshot just shows the parameters. I don’t understand why you want to convert the parameters into csv. Or if you don’t want the massive output, maybe use this

checkpoint = torch.load('mypth.pth')
for key, param in checkpoint.items():
    print(f"param name: {key} | param shape: {param.size()}")
1 Like

It does show the parameters (mistook it) but I wanted to have the massive output just to match my ideas with it. I was checking if it was going along with any mathematical expressions of my thinking. As I have other two models and those are working finely but a particular one has some problems with arguments in it. So, I was trying to understand the same.