The error code is as follows:
# Error code!
model = model.load_state_dict(state_dict_var)
out = model(input)
There are some problems on the Internet because the saved model uses state_ DCIT() to load, or vice versa.
The error here is different from the above because xxx.load_state_Dict() does not require a return value to receive.
Amend to read as follows:
# Correct code!
model.load_state_dict(state_dict_var)
out = model(input)
I hope it will help more people.
Read More:
- [Solved] AttributeError: ‘_IncompatibleKeys‘ object has no attribute ‘parameters‘
- Pytorch Loading model error: RuntimeError: Error(s) in loading state_dict for Model: Missing key(s) in state_dict
- pytorch RuntimeError: Error(s) in loading state_ Dict for dataparall… Import model error solution
- [Solved] Error(s) in loading state_dict for GeneratorResNet
- pytorch model.load_state_dict Error [How to Solve]
- urllib.error.URLError: <urlopen error [Errno -3] Temporary failure in name resolution>
- [Solved] HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/saved_model
- [Solved] Pytorch-transformers Error: AttributeError: ‘str‘ object has no attribute ‘shape‘
- [Solved] AttributeError: ‘DataParallel‘ object has no attribute ‘save‘
- [Solved] RuntimeError: Error(s) in loading state_dict for BertForTokenClassification
- [Solved] AttributeError: Manager isn‘t available; ‘auth.User‘ has been swapped for ‘
- How to Solve keras load_model() Error
- Python errors: valueerror: if using all scalar values, you must pass an index (four solutions)
- The lenet model trained by Python failed to predict its own handwritten pictures
- [Solved] RuntimeError: Input type (torch.FloatTensor) and weight type (torch.cuda.FloatTensor) should be the
- [How to Solve] Python TypeError: ‘int‘ object is not subscriptable
- Gensim Error: AttributeError: The vocab attribute was removed from KeyedVector in Gensim 4.0.0.
- [Solved] AttributeError: module ‘pandas‘ has no attribute ‘rolling_count‘
- Keras import a custom metric model error: unknown metric function: Please ensure this object is passed to`custom_object‘
- [Solved] Python 3.6 Error: ‘dict’ object has no attribute ‘has_key’