PaddlePaddle / PaddleX

All-in-One Development Tool based on PaddlePaddle(飞桨低代码开发工具)
Apache License 2.0
4.91k stars 958 forks source link

模型导出后用load_model加载出错 #816

Open thinkall opened 3 years ago

thinkall commented 3 years ago

问题类型:模型部署

训练过程中保存的模型可以推理,但导出模型后载入出错。

导出模型

(paddle2.1) liuyu@ai-Super-Server:~/jli/paddlexs$ paddlex --export_inference --model_dir=./output/faster_rcnn_r50_fpn/best_model --save_dir=./inference_model

导出后目录

(paddle2.1) liuyu@ai-Super-Server:~/jli/paddlexs$ ls inference_model/inference_model/
model.pdiparams  model.pdiparams.info  model.pdmodel  model.yml

测试脚本

(paddle2.1) liuyu@ai-Super-Server:~/jli/paddlexs$ cat run_predict.py 
import paddlex as pdx
test_jpg = './insect_det/JPEGImages/0209.jpg'
#model = pdx.load_model('output/faster_rcnn_r50_fpn/best_model')  # 用这个是OK的
model = pdx.load_model('./inference_model/inference_model/')

# predict接口并未过滤低置信度识别结果,用户根据需求按score值进行过滤
result = model.predict(test_jpg)
print(result)

测试结果

(paddle2.1) liuyu@ai-Super-Server:~/jli/paddlexs$ python run_predict.py 
/home/liuyu/anaconda3/envs/paddle2.1/lib/python3.8/site-packages/paddle/distributed/parallel.py:118: UserWarning: Currently not a parallel execution environment, `paddle.distributed.init_parallel_env` will not do anything.
  warnings.warn(
/home/liuyu/anaconda3/envs/paddle2.1/lib/python3.8/site-packages/paddle/tensor/creation.py:125: DeprecationWarning: `np.object` is a deprecated alias for the builtin `object`. To silence this warning, use `object` by itself. Doing this will not modify any behavior and is safe. 
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  if data.dtype == np.object:
W0608 17:56:26.915074  1070 device_context.cc:404] Please NOTE: device: 0, GPU Compute Capability: 6.1, Driver API Version: 10.1, Runtime API Version: 10.1
W0608 17:56:26.916905  1070 device_context.cc:422] device: 0, cuDNN Version: 8.0.
/home/liuyu/anaconda3/envs/paddle2.1/lib/python3.8/site-packages/paddle/fluid/backward.py:1666: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
  return list(x) if isinstance(x, collections.Sequence) else [x]
Traceback (most recent call last):
  File "run_predict.py", line 5, in <module>
    model = pdx.load_model('./inference_model/inference_model/')
  File "/home/liuyu/anaconda3/envs/paddle2.1/lib/python3.8/site-packages/paddlex/cv/models/load_model.py", line 81, in load_model
    net_state_dict = paddle.load(
  File "/home/liuyu/anaconda3/envs/paddle2.1/lib/python3.8/site-packages/paddle/framework/io.py", line 840, in load
    load_result = _legacy_load(path, **configs)
  File "/home/liuyu/anaconda3/envs/paddle2.1/lib/python3.8/site-packages/paddle/framework/io.py", line 875, in _legacy_load
    load_result = _load_state_dict_from_save_inference_model(model_path,
  File "/home/liuyu/anaconda3/envs/paddle2.1/lib/python3.8/site-packages/paddle/framework/io.py", line 82, in _load_state_dict_from_save_inference_model
    assert structured_name is not None, "Cannot find saved variable (%s)'s structured name in saved model." % var_name
AssertionError: Cannot find saved variable (generated_tensor_1)'s structured name in saved model.
will-jl944 commented 3 years ago

你好,这个是已知问题,目前正在修复中,修复后我们会在第一时间更新。感谢反馈。

thinkall commented 3 years ago

你好,这个是已知问题,目前正在修复中,修复后我们会在第一时间更新。感谢反馈。

谢谢。建议有个专门的文档列出正在修复中的已知bug。这个问题我在issue里也搜索了,没搜到,不然就不会重复提了 :-)