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

Issue when running the Inference script #6

Open
Yasoo-sh opened this issue Jun 23, 2023 · 2 comments
Open

Issue when running the Inference script #6

Yasoo-sh opened this issue Jun 23, 2023 · 2 comments

Comments

@Yasoo-sh
Copy link

Hi, I trained the model successfully however, when I wanted to run !python -m src.scripts.inference I get this error RuntimeError: Error(s) in loading state_dict for SimpleMPGNN: Missing key(s) in state_dict: "conv1.lin.weight", "conv2.lin.weight". Unexpected key(s) in state_dict: "conv1.root", "conv2.root".
Can you please help me solve this issue? Thanks

@ilileun
Copy link

ilileun commented Aug 22, 2024

I encountered the same error. I would appreciate it if you could provide a solution.
image

@ilileun
Copy link

ilileun commented Aug 23, 2024

I encountered the same error. I would appreciate it if you could provide a solution. image

I'm not sure... I just modified the code like this :

model = SimpleMPGNN(dataset.num_node_features, dataset.num_classes, dataset.num_edge_features,
                    hyperparams["hidden_layers"])

state_dict = torch.load(model_path, map_location=torch.device(device))

# Rename keys to match the current model definition
state_dict['conv1.lin.weight'] = state_dict.pop('conv1.root')
state_dict['conv2.lin.weight'] = state_dict.pop('conv2.root')

# Transpose the weights if necessary
state_dict['conv1.lin.weight'] = state_dict['conv1.lin.weight'].transpose(0, 1)
state_dict['conv2.lin.weight'] = state_dict['conv2.lin.weight'].transpose(0, 1)

model.load_state_dict(state_dict)
model.eval()

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