Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyTorch: File does not contain root module or state dictionary #236

Closed
Moadab-AI opened this issue Mar 11, 2019 · 3 comments
Closed

PyTorch: File does not contain root module or state dictionary #236

Moadab-AI opened this issue Mar 11, 2019 · 3 comments

Comments

@Moadab-AI
Copy link

Moadab-AI commented Mar 11, 2019

Hi. thanks for the repository.

I'm failing to visualize a PyTorch model that I save with the following line:

torch.save(model.state_dict(), 'model.pth')

and then I get this Error from Netron :

"Error loading PyTorch model. File does not contain a model graph. Use 'torch.save()' to save both the graph and tensor data."

But when I convert it to ONNX in the following way, I'm able to visualize the ONNX model :
torch.onnx.export(model, img, 'model.onnx')

Also when I tried to save the full model in PyTorch (without the ".state_dict()" part), I don't get the error but it doesn't show the correct Graph and only a single-node graph basically is displayed.

Any clue how to resolve this issue?

@lutzroeder
Copy link
Owner

.pth does not save the full graph but only top level nodes as the rest is encoded in Python modules. Using .onnx will save the full graph.

@lutzroeder
Copy link
Owner

lutzroeder commented Apr 11, 2021

Duplicate of #133.

@lutzroeder lutzroeder marked this as a duplicate of #133 Apr 11, 2021
@lutzroeder lutzroeder changed the title Not able to visualize PyTorch model PyTorch: File does not contain root module or state dictionary. Sep 16, 2023
@lutzroeder lutzroeder changed the title PyTorch: File does not contain root module or state dictionary. PyTorch: File does not contain root module or state dictionary Sep 16, 2023
@lutzroeder
Copy link
Owner

Duplicate of #543

@lutzroeder lutzroeder marked this as a duplicate of #543 Jul 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants