question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError: 'weight' when using resnet18 following mpc_cifar.py code

See original GitHub issue

I run into this error, when I try using CrypTen with resnet18 model for my code

KeyError                                  Traceback (most recent call last)
<ipython-input-11-8baf0b8ce013> in <module>
     16 
     17             input_size = get_input_size(val_loader, batch_size)
---> 18             private_model = construct_private_model(input_size, hosp_models[i])
     19             validate(loader=val_loader, model=private_model)
     20             print('\n')

<ipython-input-5-19f29188bd4f> in construct_private_model(input_size, model)
     15     else:
     16         model_upd = LeNet()
---> 17     private_model = crypten.nn.from_pytorch(model_upd, dummy_input).encrypt(src=0)
     18     return private_model
     19 

~/Downloads/mila project/udacity_DP_FL/CrypTen/crypten/nn/onnx_converter.py in from_pytorch(pytorch_model, dummy_input)
     35     # construct CrypTen model:
     36     f = _from_pytorch_to_bytes(pytorch_model, dummy_input)
---> 37     crypten_model = from_onnx(f)
     38     f.close()
     39 

~/Downloads/mila project/udacity_DP_FL/CrypTen/crypten/nn/onnx_converter.py in from_onnx(onnx_string_or_file)
    122     """Converts an onnx model to a CrypTen model"""
    123     converter = FromOnnx(onnx_string_or_file)
--> 124     crypten_model = converter.to_crypten()
    125     return crypten_model
    126 

~/Downloads/mila project/udacity_DP_FL/CrypTen/crypten/nn/onnx_converter.py in to_crypten(self)
    184             # add CrypTen module to graph
    185             crypten_module = crypten_class.from_onnx(
--> 186                 parameters=parameters, attributes=attributes
    187             )
    188             node_output_name = list(node.output)[0]

~/Downloads/mila project/udacity_DP_FL/CrypTen/crypten/nn/module.py in from_onnx(parameters, attributes)
   1584 
   1585         # initialize module:
-> 1586         in_channels = parameters["weight"].size(1)
   1587         out_channels = parameters["weight"].size(0)
   1588         module = Conv2d(

KeyError: 'weight'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gmurarucommented, Nov 2, 2020

Also, got the email - will look now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Key error in giving weights to nodes in python - Stack Overflow
Let's assume the loop to assign weight to the parent starts with node 457. par then is 45 which has more than one...
Read more >
'unexpected key "module.module.module.conv1.weight" in ...
I am getting the following error while trying to load a saved model. KeyError: 'unexpected key "module.encoder.embedding.weight" in state_dict' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found