Error(s) pytorch 加载checkpoint state_dict出错:Missing key(s) && Unexpected key(s) in state_dict

ERROR:

REASON:

image

The problem is the module is load with dataparallel activated and you are trying to load it without data parallel. That's why there's an extra module at the beginning of each key!

错误原因就是net.load_state_dict的时候,net的状态不是处在gpu并行状态,而存储的net模型checkpoint是在gpu并行状态下的!

SOLVE:

在net.load_state_dict前将net的状态设置成gpu并行模式就好了。

image


AIEarth是一个由众多领域内专家博主共同打造的学术平台,旨在建设一个拥抱智慧未来的学术殿堂!【平台地址: https://devpress.csdn.net/aiearth 】 很高兴认识你!加入我们共同进步!

加载模型出现-RuntimeError: Error(s) in loading state_dict for Net:unexpected key(s) in state_dict: XXX
加载模型出现-RuntimeError: Error(s) in loading state_dict for Net:unexpected key(s) in state_dict: XXX
raise RuntimeError(‘Error(s) in loading state_dict for {}:\n\t{}‘.format( RuntimeError: Error(s)..报错
即load_state_dict(fsd,strict=False) 属性strict;当strict=True,要求预训练练权重层数的键值与新构建的模型中的权重层数名称完全吻合;
【在虚拟环境下完美解决】1698: error: (-215:Assertion failed) empty() in function cv::CascadeClassifier
首先我们要找到那个分类器所在的路径,我们可以在Cmd中直接输入【若是虚拟环境的话,则需要切换到对于虚拟环境中,再去查找对应的opencv版本与位置信息】
node-redis:ErrorReply: ERR wrong number of arguments for ‘auth‘ command
node-redis:ErrorReply: ERR wrong number of arguments for ‘auth‘ command
[Vue warn]: Duplicate keys detected: ‘0‘. This may cause an update error.
首先Duplicate keys detected: '0'. This may cause an update error是vue发现key不是唯一的而引发的错误. 译为中文大概是 : 检测到重复键 : '0'. '0'可能会导致一个更新错误. 解决办法网上找的其他也有一些.通过手动进行修改:key进而解决,比如说进行拼接字符串.因为为了解决不报错,而手动修改了数据.个人感觉不应该是这样的.
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决TypeError: tf__update_state() got an unexpected keyword argument ‘sample_weight‘
解决办法:RuntimeError: dictionary changed size during iteration
解决办法:RuntimeError: dictionary changed size during iteration
【已解决】npm start 报错 Could not freeze ...: cannot read properties of undefined (reading ‘hash‘)
npm start 报错 Could not freeze ...: cannot read properties of undefined (reading ‘hash‘)
ES报错:“type“=>“cluster_block_exception“, “reason“=>“blocked by: [FORBIDDEN/12/index read-only / allow
ES报错:“type“=>“cluster_block_exception“, “reason“=>“blocked by: [FORBIDDEN/12/index read-only / allow
报错:应用json.parseObject()方法时JSONException: syntax error, expect {, actual [, pos 0
报错:应用json.parseObject()方法时JSONException: syntax error, expect {, actual [, pos 0
opencv出错:error: (-213:The function/feature is not implemented) Unknown/unsupported array type
opencv出错:error: (-213:The function/feature is not implemented) Unknown/unsupported array type
报错:pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 7, saw 2
报错:pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 7, saw 2
解决Invalid prop: type check failed for prop “model“. Expected Object, got Array问题
解决Invalid prop: type check failed for prop “model“. Expected Object, got Array问题
成功解决TypeError: sequence item 0: expected str instance, list found
成功解决TypeError: sequence item 0: expected str instance, list found
成功解决raise ValueError(‘No model found in config file.‘) ValueError: No model found in config file.
成功解决raise ValueError(‘No model found in config file.‘) ValueError: No model found in config file.
Constrained Output Embeddings for End-to-End Code-Switching Speech Recognition with Only Monolingual Data
低代码开发师(初级)实战教程
阿里巴巴DevOps 最佳实践手册