PaddleOCR
PaddleOCR copied to clipboard
OSError: cannot open resource
请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem
- 系统环境/System Environment:baidu aistudio V100 32GB
- 版本号/Version:Paddle:2.2.2.post101 PaddleOCR:2.6.1.0 问题相关组件/Related components:PIL
- 运行指令/Command Code:python predict_system.py
- 完整报错/Complete Error Message: `
[2022/11/02 14:26:23] ppocr DEBUG: 乳酸脱氢酶, 0.979 [2022/11/02 14:26:23] ppocr DEBUG: 167, 1.000 [2022/11/02 14:26:23] ppocr DEBUG: 114--240, 0.980 [2022/11/02 14:26:23] ppocr DEBUG: U/L, 0.996 [2022/11/02 14:26:23] ppocr DEBUG: ADA, 0.998 [2022/11/02 14:26:23] ppocr DEBUG: 腺甘脱氨酶, 0.973 [2022/11/02 14:26:23] ppocr DEBUG: 12. 6, 0.924 [2022/11/02 14:26:23] ppocr DEBUG: 4--24, 0.993 [2022/11/02 14:26:23] ppocr DEBUG: U/L, 0.970 Traceback (most recent call last): File "predict_system.py", line 262, in
main(args) File "predict_system.py", line 219, in main font_path=font_path) File "/home/aistudio/OCR/tools/infer/utility.py", line 421, in draw_ocr_box_txt img_right_text = draw_box_txt_fine((w, h), box, txt, font_path) File "/home/aistudio/OCR/tools/infer/utility.py", line 449, in draw_box_txt_fine font = create_font(txt, (box_width, box_height), font_path) File "/home/aistudio/OCR/tools/infer/utility.py", line 470, in create_font font = ImageFont.truetype(font_path, font_size, encoding="utf-8") File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/PIL/ImageFont.py", line 648, in truetype return freetype(font) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/PIL/ImageFont.py", line 645, in freetype return FreeTypeFont(font, size, index, encoding, layout_engine) File "/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/PIL/ImageFont.py", line 194, in init font, size, index, encoding, layout_engine=layout_engine OSError: cannot open resource `
先在./tools/infer/utility.py
文件中配置好模型等,根据文本检测、方向分类和文字识别串联推理,使用的方向分类器(python3 tools/infer/predict_system.py --image_dir="./doc/imgs/00018069.jpg" --det_model_dir="./ch_PP-OCRv3_det_infer/" --cls_model_dir="./cls/" --rec_model_dir="./ch_PP-OCRv3_rec_infer/" --use_angle_cls=true
),运行即会出现该报错
环境:
pip install --upgrade pip
pip install paddleocr
git clone https://gitee.com/paddlepaddle/PaddleOCR
pip install -r requirements.txt
看报错是可视化加载字体的时候报错了,你有修改代码吗,我这边测试运行是正常的
@LDOUBLEV 我没有修改代码呀,我就是把模型通过配置文件加载,因为参数加载不利于我这边后续调用。然后其他地方都没动,而且是使用飞桨提供的免费GPU
请问报错原因该在哪里定位呢?你说加载字体问题,我这边看不出来,只知道是PIL库问题,请求帮忙一起解决,谢谢
@LDOUBLEV 刘威威? 对了,我记起来我下载 方向矫正 模型,解压时有一个报错,但鉴于最终模型可以解压出来,所以就没管(多次换环境解压都会出错,但最终文件好像没损坏)
@LDOUBLEV 刘威威? 对了,我记起来我下载 方向矫正 模型,解压时有一个报错,但鉴于最终模型可以解压出来,所以就没管(多次换环境解压都会出错,但最终文件好像没损坏)
这个做了实验,跟这个无关,模型不使用 方向矫正,也会出现同样报错
知道原因了,字体文件缺失
使用绝对路径即可解决问题!亲测!
https://github.com/PaddlePaddle/PaddleOCR/blob/0525f6bb01bfed401f767894619f6a25ee750892/tools/infer_kie_token_ser.py#L153
edit this line as:
img_res = draw_ser_results(img_path, result, config['Global']['font_path'])
and add font file path in config yaml file like:
Global:
font_path: PaddleOCR-release-2.7/doc/fonts/simfang.ttf
是我傻了