KeyError: 'g_a.0.weight' in Model update
See original GitHub issueHi all,
I am trying to finetune a pre-trained model on my dataset. The packages version I used are listed as follows:
PyTorch: Version: 1.8.1+cu111
CompressAI: Version: 1.1.4
I mainly modified one line in examples/train.py
and changed it to finetune.py
. The line I modified changed to the following:
net = models[args.model](quality=args.quality, metric="mse", pretrained=True)
And I used the following script to finetune the pretrained model and save it to a checkpoint.
python finetune.py -m cheng2020-anchor -q 1 -d ../../test-pictures-finetuned --save --cuda
And it successfully generates the checkpoints I need. Then, I follow the steps provided in the tutorial. To update the CDF, and export the checkpoint. I did it with the following command.
python -m compressai.utils.update_model --architecture mean-scale-hyperprior -n cheng2020-anchor-finetuned -d ../updated-checkpoints checkpoint_best_loss.pth.tar
And the error occurred:
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.8/dist-packages/compressai/utils/update_model/__main__.py", line 139, in <module>
main(sys.argv[1:])
File "/usr/local/lib/python3.8/dist-packages/compressai/utils/update_model/__main__.py", line 110, in main
net = model_cls.from_state_dict(state_dict)
File "/usr/local/lib/python3.8/dist-packages/compressai/models/priors.py", line 274, in from_state_dict
N = state_dict["g_a.0.weight"].size(0)
KeyError: 'g_a.0.weight'
I changed the --architecture
to all other architectures, {factorized-prior,jarhp,mean-scale-hyperprior,scale-hyperprior}
. None of these works. Could you help me with this?
Thanks a lot!
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
KeyError: 'model.0.weight' · Issue #22 · n00mkrad/cupscale
I downloaded a few models to test it out, and whenever I select a model and then click on Refresh Preview, it gives...
Read more >Problem with missing and unexpected keys while loading my ...
Unexpected key(s) in state_dict: "features.0.weight", "features.0.bias", "features.3.weight", "features.
Read more >How to Fix KeyError Exceptions in Python - Rollbar
The Python KeyError is an exception that occurs when an attempt is made to access an item in a dictionary that does not...
Read more >How to Fix in Pandas: KeyError: "['Label'] not found in axis"
This error usually occurs when you attempt to drop a column from a pandas DataFrames and forget to specify axis=1. By default, the...
Read more >BERT model not working (KeyError: 'sample_weight_mode')
The model reads OK, and the predictor node seems to load the table of ... ERROR BERT Predictor 0:393 Execute failed: 'sample_weight_mode'
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Great 😃.
Hi Jean @jbegaint , Never mind. I found I just need to regenerate the checkpoint and then it can be updated using the updated pip package. Thanks for the help.