3d_vsg icon indicating copy to clipboard operation
3d_vsg copied to clipboard

Issue when running the Inference script

Open Yasoo-sh opened this issue 1 year ago • 2 comments

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

Yasoo-sh avatar Jun 23 '23 21:06 Yasoo-sh

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

ilileun avatar Aug 22 '24 17:08 ilileun

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()
    

ilileun avatar Aug 23 '24 11:08 ilileun