gpt4 book ai didi

python - 在状态字典 : 0. 0.weight"、 "0.1.weight"、 "0.1.bias"、 "0.1.running_mean"中遇到缺少 key

转载 作者:行者123 更新时间:2023-12-01 07:11:07 27 4
gpt4 key购买 nike

我正在尝试为我的大学项目开发​​电话分类器模型。我已经训练了我的模型,当我尝试通过执行 python app/server.pyserve 来部署模型时遇到了问题。我读了一篇文章( https://forums.fast.ai/t/unexpected-key-s-in-state-dict-model-opt/39745 )我怀疑问题是由于我的 anaconda 和 Google Colab 之间运行的 fast.ai 版本不同所致。

因此,我尝试使用 pip list fastai、conda list fastai 和 import fastai 来检查我电脑中 fastai 的版本;我的 Google colab 中的 fastai.版本(我使用 Google Colab 来开发我的模型),但结果是相同的(fastai 版本 = 1.0.59)。我什至尝试在 Google Colab 中更新我的 fastai 版本,但没有成功。这是异常代码:

Traceback (most recent call last):
File "app/server.py", line 37, in <module>
learn = loop.run_until_complete(asyncio.gather(*tasks))[0]
File "C:\ProgramData\Anaconda3\lib\asyncio\base_events.py", line 584, in run_until_complete
return future.result()
File "app/server.py", line 32, in setup_learner
learn.load(model_file_name)
File "C:\ProgramData\Anaconda3\lib\site-packages\fastai\basic_train.py", line 279, in load
get_model(self.model).load_state_dict(state, strict=strict)
File "C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 845, in load_state_dict
self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for Sequential:
Missing key(s) in state_dict: "0.0.weight", "0.1.weight", "0.1.bias", "0.1.running_mean", "0.1.running_var", "0.4.0.conv1.weight", "0.4.0.bn1.weight", "0.4.0.bn1.bias", "0.4.0.bn1.running_mean", "0.4.0.bn1.running_var", "0.4.0.conv2.weight", "0.4.0.bn2.weight", "0.4.0.bn2.bias", "0.4.0.bn2.running_mean", "0.4.0.bn2.running_var", "0.4.1.conv1.weight", "0.4.1.bn1.weight", "0.4.1.bn1.bias", "0.4.1.bn1.running_mean", "0.4.1.bn1.running_var", "0.4.1.conv2.weight", "0.4.1.bn2.weight", "0.4.1.bn2.bias", "0.4.1.bn2.running_mean", "0.4.1.bn2.running_var", "0.4.2.conv1.weight", "0.4.2.bn1.weight", "0.4.2.bn1.bias", "0.4.2.bn1.running_mean", "0.4.2.bn1.running_var", "0.4.2.conv2.weight", "0.4.2.bn2.weight", "0.4.2.bn2.bias", "0.4.2.bn2.running_mean", "0.4.2.bn2.running_var", "0.5.0.conv1.weight", "0.5.0.bn1.weight", "0.5.0.bn1.bias", "0.5.0.bn1.running_mean", "0.5.0.bn1.running_var", "0.5.0.conv2.weight", "0.5.0.bn2.weight", "0.5.0.bn2.bias", "0.5.0.bn2.running_mean", "0.5.0.bn2.running_var", "0.5.0.downsample.0.weight", "0.5.0.downsample.1.weight", "0.5.0.downsample.1.bias", "0.5.0.downsample.1.running_mean", "0.5.0.downsample.1.running_var", "0.5.1.conv1.weight", "0.5.1.bn1.weight", "0.5.1.bn1.bias", "0.5.1.bn1.running_mean", "0.5.1.bn1.running_var", "0.5.1.conv2.weight", "0.5.1.bn2.weight", "0.5.1.bn2.bias", "0.5.1.bn2.running_mean", "0.5.1.bn2.running_var", "0.5.2.conv1.weight", "0.5.2.bn1.weight", "0.5.2.bn1.bias", "0.5.2.bn1.running_mean", "0.5.2.bn1.running_var", "0.5.2.conv2.weight", "0.5.2.bn2.weight", "0.5.2.bn2.bias", "0.5.2.bn2.running_mean", "0.5.2.bn2.running_var", "0.5.3.conv1.weight", "0.5.3.bn1.weight", "0.5.3.bn1.bias", "0.5.3.bn1.running_mean", "0.5.3.bn1.running_var", "0.5.3.conv2.weight", "0.5.3.bn2.weight", "0.5.3.bn2.bias", "0.5.3.bn2.running_mean", "0.5.3.bn2.running_var", "0.6.0.conv1.weight", "0.6.0.bn1.weight", "0.6.0.bn1.bias", "0.6.0.bn1.running_mean", "0.6.0.bn1.running_var", "0.6.0.conv2.weight", "0.6.0.bn2.weight", "0.6.0.bn2.bias", "0.6.0.bn2.running_mean", "0.6.0.bn2.running_var", "0.6.0.downsample.0.weight", "0.6.0.downsample.1.weight", "0.6.0.downsample.1.bias", "0.6.0.downsample.1.running_mean", "0.6.0.downsample.1.running_var", "0.6.1.conv1.weight", "0.6.1.bn1.weight", "0.6.1.bn1.bias", "0.6.1.bn1.running_mean", "0.6.1.bn1.running_var", "0.6.1.conv2.weight", "0.6.1.bn2.weight", "0.6.1.bn2.bias", "0.6.1.bn2.running_mean", "0.6.1.bn2.running_var", "0.6.2.conv1.weight", "0.6.2.bn1.weight", "0.6.2.bn1.bias", "0.6.2.bn1.running_mean", "0.6.2.bn1.running_var", "0.6.2.conv2.weight", "0.6.2.bn2.weight", "0.6.2.bn2.bias", "0.6.2.bn2.running_mean", "0.6.2.bn2.running_var", "0.6.3.conv1.weight", "0.6.3.bn1.weight", "0.6.3.bn1.bias", "0.6.3.bn1.running_mean", "0.6.3.bn1.running_var", "0.6.3.conv2.weight", "0.6.3.bn2.weight", "0.6.3.bn2.bias", "0.6.3.bn2.running_mean", "0.6.3.bn2.running_var", "0.6.4.conv1.weight", "0.6.4.bn1.weight", "0.6.4.bn1.bias", "0.6.4.bn1.running_mean", "0.6.4.bn1.running_var", "0.6.4.conv2.weight", "0.6.4.bn2.weight", "0.6.4.bn2.bias", "0.6.4.bn2.running_mean", "0.6.4.bn2.running_var", "0.6.5.conv1.weight", "0.6.5.bn1.weight", "0.6.5.bn1.bias", "0.6.5.bn1.running_mean", "0.6.5.bn1.running_var", "0.6.5.conv2.weight", "0.6.5.bn2.weight", "0.6.5.bn2.bias", "0.6.5.bn2.running_mean", "0.6.5.bn2.running_var", "0.7.0.conv1.weight", "0.7.0.bn1.weight", "0.7.0.bn1.bias", "0.7.0.bn1.running_mean", "0.7.0.bn1.running_var", "0.7.0.conv2.weight", "0.7.0.bn2.weight", "0.7.0.bn2.bias", "0.7.0.bn2.running_mean", "0.7.0.bn2.running_var", "0.7.0.downsample.0.weight", "0.7.0.downsample.1.weight", "0.7.0.downsample.1.bias", "0.7.0.downsample.1.running_mean", "0.7.0.downsample.1.running_var", "0.7.1.conv1.weight", "0.7.1.bn1.weight", "0.7.1.bn1.bias", "0.7.1.bn1.running_mean", "0.7.1.bn1.running_var", "0.7.1.conv2.weight", "0.7.1.bn2.weight", "0.7.1.bn2.bias", "0.7.1.bn2.running_mean", "0.7.1.bn2.running_var", "0.7.2.conv1.weight", "0.7.2.bn1.weight", "0.7.2.bn1.bias", "0.7.2.bn1.running_mean", "0.7.2.bn1.running_var", "0.7.2.conv2.weight", "0.7.2.bn2.weight", "0.7.2.bn2.bias", "0.7.2.bn2.running_mean", "0.7.2.bn2.running_var", "1.2.weight", "1.2.bias", "1.2.running_mean", "1.2.running_var", "1.4.weight", "1.4.bias", "1.6.weight", "1.6.bias", "1.6.running_mean", "1.6.running_var", "1.8.weight", "1.8.bias".
Unexpected key(s) in state_dict: "opt_func", "loss_func", "metrics", "true_wd", "bn_wd", "wd", "train_bn", "model_dir", "callback_fns", "cb_state", "model", "data", "cls".

我的 fastai 版本与 Google colab 中的 fastai 相同,但我仍然遇到同样的问题。我希望我的模型能够部署在我的本地服务器上。

最佳答案

感谢 mrfabulous1,我明白了造成这种情况的原因,因此,我将他的回复分享给将来想要在本地部署模型的人。

根据我在桌面上的 Google Colab 和 Anaconda 之间创建至少 20 个应用的经验,除非您的 Anaconda 环境与 Colab 环境 100% 匹配,否则应用无法运行。

实际上,这意味着当您在 Colab 上执行 !pip 列出您训练模型的位置时。应用程序中的 requests.txt 文件中使用的所有文件库版本都必须更改为匹配您在 Colab 上执行 !pip list 时收到的版本。

如果您尝试在 Anaconda 环境中的桌面上运行模型/应用程序,应用程序将会失败,除非您的 anaconda 环境中的所有文件版本号与 Colab 版本匹配。

有时,第 2 点甚至会失败,因为库可以进行安全修补或进行尚未公布的微小更改,并且没有与之关联的版本号。

这意味着您每次在 Google Colab 上训练模型时都需要创建一个新的 Anaconda 环境,并且任何库版本都与您当前的 Anaconda 环境不同。

如果您更改当前的 Anaconda 环境库版本,那么使用该环境创建的所有现有应用程序可能/将会崩溃。

总之,每次 Colab 上的库与 Anaconda 上的库不同时,都要创建新的环境。

干杯mrfabulous1附:我现在使用 Docker 来解决这个问题。

关于python - 在状态字典 : 0. 0.weight"、 "0.1.weight"、 "0.1.bias"、 "0.1.running_mean"中遇到缺少 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58211519/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com