Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fine-tune 之后,使用预测后的模型报错 #2274

Open
wb-hwang opened this issue Jul 10, 2023 · 0 comments
Open

Fine-tune 之后,使用预测后的模型报错 #2274

wb-hwang opened this issue Jul 10, 2023 · 0 comments
Assignees

Comments

@wb-hwang
Copy link

wb-hwang commented Jul 10, 2023

欢迎您反馈PaddleHub使用问题,非常感谢您对PaddleHub的贡献!
在留下您的问题时,辛苦您同步提供如下信息:

  • 版本、环境信息
    1)PaddleHub和PaddlePaddle版本:PaddlePaddle 2.4.0,paddleHub 2.3.0
    2)系统环境:AIStudio,python 1.7.4,
  • 复现信息:如为报错,请给出复现环境、复现步骤
    直接运行教程里面迁移学习-图像分类 的代码,完成迁移学习后,加载模型报错。
    使用AIstudio、本地 运行都出现一样的错误。

迁移学习成功:

[2023-07-10 11:45:44,857] [    EVAL] - Saving best model to img_classification_ckpt/best_model [best acc=0.6710]
[2023-07-10 11:45:44,860] [    INFO] - Saving model checkpoint to img_classification_ckpt/epoch_1

加载模型的代码:

import paddle
import paddlehub as hub

if __name__ == '__main__':

    model = hub.Module(name='resnet50_vd_imagenet_ssld', label_list=["roses", "tulips", "daisy", "sunflowers", "dandelion"], load_checkpoint='img_classification_ckpt/')
    result = model.predict(['flower.jpg']) 

报错:

/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/setuptools/depends.py:2: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
Traceback (most recent call last):
  File "untitled.py", line 6, in <module>
    model = hub.Module(name='resnet50_vd_imagenet_ssld', label_list=["roses", "tulips", "daisy", "sunflowers", "dandelion"], load_checkpoint='img_classification_ckpt/')
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/module/module.py", line 396, in __new__
    **kwargs)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddlehub/module/module.py", line 511, in init_with_name
    return user_module_cls(**kwargs)
  File "/home/aistudio/.paddlehub/modules/resnet50_vd_imagenet_ssld/module.py", line 240, in __init__
    self.model_dict = paddle.load(load_checkpoint)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/framework/io.py", line 1103, in load
    load_result = _legacy_load(path, **configs)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/framework/io.py", line 1150, in _legacy_load
    load_result = _load_state_dict_from_save_params(model_path)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/framework/io.py", line 147, in _load_state_dict_from_save_params
    attrs={'file_path': os.path.join(model_path, name)},
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/tracer.py", line 314, in trace_op
    stop_gradient, inplace_map)
  File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/tracer.py", line 176, in eager_legacy_trace_op
    returns = function_ptr(*arg_list, *attrs_list)
ValueError: (InvalidArgument) Deserialize to tensor failed, maybe the loaded file is not a paddle model(expected file format: 0, but 1667433344 found).
  [Hint: Expected version == 0U, but received version:1667433344 != 0U:0.] (at /paddle/paddle/phi/core/serialization.cc:106)
  [operator < load > error]

迁移学习后,生成的文件结构是:

-img_classification_ckpy/
  -- best_model/
    --- model.pdopt
    --- model.pdparams
  -- epoch_1/
  -- visualization/
  -- metrics.pkl

做过以下尝试,依旧不行

  1. 切换paddle-gpu、paddle-cpu
  2. AIstudio、本地(windows 11)跑
  3. 切换paddle 版本到2.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants