load_state_dict中的strict
时间: 2023-10-30 16:23:08 浏览: 90
在load_state_dict`函数中,参数`strict`是一个布尔值,用于控制是否严格匹配加载模型的字典与当前模型的参数字典。当`strict=True`时,加载模型的字典中的参数名称必须严格与当前模型的参数名称匹配,否则会抛出`KeyError`异常。而当`strict=False`时,加载模型的字典中与当前模型不匹配的参数会被忽略,而匹配的参数会被载入。这样可以在一定程度上允许加载不完全匹配的模型参数。 <span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [torch.nn.Module.load_state_dict(state_dict, strict=True)](https://blog.csdn.net/m0_46653437/article/details/112649201)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [关于Pytorch加载模型参数的避坑指南](https://blog.csdn.net/qq_24193303/article/details/124215697)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [pytorch载入预训练模型后,实现训练指定层](https://download.csdn.net/download/weixin_38663701/13760583)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文