我在ConvNext small中添加了一个自定义的层块。我想用预先训练好的权重来训练它,但出现了错误
Traceback (most recent call last):
File "C:\Users\Ali\PycharmProjects\pythonProject1\ConvNext_Custom_FromGitHubCode.py", line 187, in <module>
model = convnext_small(pretrained=True, in_22k=False)
File "C:\Users\Ali\PycharmProjects\pythonProject1\ConvNext_Custom_FromGitHubCode.py", line 184, in convnext_small
model.load_state_dict(checkpoint["model"])
File "C:\Users\Ali\anaconda3\envs\py38\lib\site-packages\torch\nn\modules\module.py", line 1604, in load_state_dict
raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for ConvNeXt:
Missing key(s) in state_dict: "custom_block.conv1.weight", "custom_block.conv1.bias", "custom_block.conv2.weight", "custom_block.conv2.bias", "custom_block.multihead_attention.in_proj_weight", "custom_block.multihead_attention.in_proj_bias", "custom_block.multihead_attention.out_proj.weight", "custom_block.multihead_attention.out_proj.bias", "custom_block.linear.weight", "custom_block.linear.bias".
个字符
2条答案
按热度按时间h7appiyu1#
您可以使用
strict=False
禁用重量检查:字符串
这将禁用不兼容和丢失的关键字检查在加载状态指令。
a64a0gku2#
您可以使用following更新
convnext_small
函数:字符串
上面的代码将通过过滤掉不匹配的键并加载权重来更新
state_dict
。