Skip to content

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

Closed
@Moadab-AI

Description

@Moadab-AI

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?

Activity

lutzroeder

lutzroeder commented on Mar 11, 2019

@lutzroeder
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

lutzroeder commented on Apr 11, 2021

@lutzroeder
Owner

Duplicate of #133.

marked this as a duplicate of PyTorch support #133 on Apr 11, 2021
changed the title [-]Not able to visualize PyTorch model[/-] [+]PyTorch: File does not contain root module or state dictionary.[/+] on Sep 16, 2023
changed the title [-]PyTorch: File does not contain root module or state dictionary.[/-] [+]PyTorch: File does not contain root module or state dictionary[/+] on Sep 16, 2023

2 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lutzroeder@Moadab-AI

        Issue actions

          PyTorch: File does not contain root module or state dictionary · Issue #236 · lutzroeder/netron