报错
在使用PaddlePaddle的FastDeploy部署图像分割时,需要验证目标电脑环境,所以先将预测代码predict.py用pyinstaller打包来试试,指令:
pyinstaller -D predict.py
打包完成,成功生成exe
运行时报错如下:
Traceback (most recent call last):
File "paddle\fluid\ir.py", line 24, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module>
ModuleNotFoundError: No module named 'framework_pb2'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "predict.py", line 18, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\__init__.py", line 57, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\distributed\__init__.py", line 15, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\distributed\spawn.py", line 24, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\distributed\utils.py", line 28, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\distributed\fleet\__init__.py", line 20, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\distributed\fleet\base\fleet_base.py", line 31, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\fluid\ir.py", line 28, in <module>
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "paddle\fluid\proto\pass_desc_pb2.py", line 16, in <module>
ModuleNotFoundError: No module named 'framework_pb2'
[11528] Failed to execute script 'predict' due to unhandled exception!
核心问题就是:ModuleNotFoundError: No module named 'framework_pb2'
找不到framework_pb2,参考网上的解决方法:
paddleocr infer_rec打包失败framework_pb2 · Issue #5326 · PaddlePaddle/PaddleOCR · GitHub
解决方法
1. 按照上面链接中提到的,修改image.py
然后重新用pyinstaller打包生成exe,运行发现还是报错,执行下面第2步。
2. 继续按照上面链接中提到的,将site-packages/paddle/fluid/中的proto文件夹复制到生成的dist/paddle/fluid/下
继续运行时,发现不会再提示No module named 'framework_pb2'。
3. 将模型文件、配置文件、图片等放到制定目录,然后命令行运行
predict.exe --config configs/quick_start/my_deeplabv3.yml --model_path output/best_model/model.pdparams --image_path data/C0402/JPEGImages/02.jpg --save_dir output/result