Skip to content

Commit 877e43f

Browse files
NJX-njxSWHL
andauthored
docs: 优化了FAQ文档(docs/FAQ.md & docs/FAQ.en.md)、模块文档(docs/version3.x/module_usage/text_detection.md)、产线文档 (docs/version3.x/pipeline_usage/OCR.md) (#16598)
Co-authored-by: SWHL <liekkaskono@163.com>
1 parent 830dc63 commit 877e43f

File tree

4 files changed

+450
-2
lines changed

4 files changed

+450
-2
lines changed

docs/FAQ.en.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,136 @@ hide:
55
- toc
66
---
77

8+
> 🎉 **Welcome to PaddleOCR FAQ!**
9+
> This document compiles common issues and solutions from GitHub Issues and Discussions, providing reference for OCR developers.
10+
11+
## 1. Installation and Environment Setup
12+
13+
### 1.1 Basic Installation Issues
14+
15+
#### Q: PaddleOCR installation failed with dependency conflicts
16+
17+
**A**: This is a common issue that can be resolved by:
18+
(1) Create a new virtual environment: `conda create -n paddleocr python=3.8`, then activate and install
19+
(2) Install with specific versions: `pip install paddleocr==3.2.0 --no-deps`, then install dependencies separately
20+
(3) If using conda, try: `conda install -c conda-forge paddleocr`
21+
22+
#### Q: GPU environment configuration issues, CUDA version mismatch
23+
24+
**A**: First check CUDA version: `nvidia-smi`, then install corresponding PaddlePaddle version:
25+
- CUDA 11.8: `pip install paddlepaddle-gpu==3.0.0 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html`
26+
- CUDA 12.0: `pip install paddlepaddle-gpu==3.0.0 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html`
27+
Verify GPU availability: `python -c "import paddle; print(paddle.is_compiled_with_cuda())"`
28+
29+
#### Q: Model download failed or slow download
30+
31+
**A**: Can be resolved by:
32+
(1) Set model download source: `os.environ['PADDLE_PDX_MODEL_SOURCE'] = 'BOS'` (use Baidu Cloud Storage)
33+
(2) Manual model download: directly access model links to download and extract to local directory
34+
(3) Use local models: specify `model_dir` parameter pointing to local model path during initialization
35+
36+
#### Q: How to run on Windows or Mac?
37+
38+
**A**: PaddleOCR has completed adaptation to Windows and MAC systems. Two points should be noted during operation:
39+
1. In [Quick installation](./installation_en.md), if you do not want to install docker, you can skip the first step and start with the second step.
40+
2. When downloading the inference model, if wget is not installed, you can directly click the model link or copy the link address to the browser to download, then extract and place it in the corresponding directory.
41+
42+
## 2. Model Usage and Configuration
43+
44+
### 2.1 Model Selection
45+
46+
#### Q: How to choose the right model?
47+
48+
**A**: Choose based on application scenario:
49+
- Server high accuracy: Use `PP-OCRv5_server` series, highest accuracy
50+
- Mobile deployment: Use `PP-OCRv5_mobile` series, small model fast speed
51+
- Real-time processing: Use `PP-OCRv5_mobile` series, fast inference speed
52+
- Batch processing: Use `PP-OCRv5_server` series, high accuracy
53+
- Multi-language recognition: Use `PP-OCRv5_multi_languages`, supports 37 languages
54+
55+
#### Q: Local model path configuration, how to use in isolated network environment?
56+
57+
**A**: Can be configured by:
58+
(1) Use local model path: specify `model_dir` parameter during initialization
59+
(2) Set model download source: `os.environ['PADDLE_PDX_MODEL_SOURCE'] = 'BOS'`
60+
(3) Manual model download: download models from official links and extract locally
61+
(4) Example code:
62+
```python
63+
ocr = PaddleOCR(
64+
det_model_dir='./models/PP-OCRv5_server_det_infer/',
65+
rec_model_dir='./models/PP-OCRv5_server_rec_infer/',
66+
cls_model_dir='./models/PP-OCRv5_cls_infer/',
67+
use_angle_cls=True,
68+
lang='ch'
69+
)
70+
```
71+
72+
## 3. Performance Optimization
73+
74+
### 3.1 GPU Optimization
75+
76+
#### Q: Slow GPU inference speed, how to optimize performance?
77+
78+
**A**: Can be optimized by:
79+
(1) Enable high-performance inference: set `enable_hpi=True`, automatically select optimal acceleration strategy
80+
(2) Enable TensorRT acceleration: set `use_tensorrt=True`, requires CUDA 11.8+ and TensorRT 8.6+
81+
(3) Use half precision: set `precision="fp16"`, can significantly improve speed
82+
(4) Adjust batch size: set appropriate `batch_size` based on GPU memory
83+
(5) Use mobile models: use `PP-OCRv5_mobile` series when accuracy requirements are not high
84+
85+
#### Q: GPU memory insufficient (CUDA out of memory) what to do?
86+
87+
**A**: Can be resolved by:
88+
(1) Reduce batch size: set `batch_size` to 1
89+
(2) Reduce image size: set `det_limit_side_len=640`
90+
(3) Enable memory optimization: set `enable_memory_optim=True`
91+
(4) Limit GPU memory usage: set `gpu_mem=200`
92+
(5) Use mobile models: switch to `PP-OCRv5_mobile` series models
93+
94+
## 4. Deployment Issues
95+
96+
### 4.1 Service Deployment
97+
98+
#### Q: How to deploy PaddleOCR as a web service?
99+
100+
**A**: Can be deployed by:
101+
(1) Use Flask deployment: create simple Web API service
102+
(2) Use gunicorn deployment: `gunicorn -w 4 -b 0.0.0.0:5000 app:app`
103+
(3) Use asynchronous processing: combine asyncio and ThreadPoolExecutor
104+
(4) Example code:
105+
```python
106+
from flask import Flask, request, jsonify
107+
from paddleocr import PaddleOCR
108+
109+
app = Flask(__name__)
110+
ocr = PaddleOCR(use_angle_cls=True, lang='ch')
111+
112+
@app.route('/ocr', methods=['POST'])
113+
def ocr_api():
114+
file = request.files['image']
115+
result = ocr.ocr(file, cls=True)
116+
return jsonify({'result': result})
117+
```
118+
119+
#### Q: C++ deployment common issues and solutions?
120+
121+
**A**: Common issues and solutions:
122+
(1) Cannot find dynamic library: set `export LD_LIBRARY_PATH=/path/to/paddle/lib:$LD_LIBRARY_PATH`
123+
(2) OpenCV version mismatch: ensure OpenCV version matches compilation time
124+
(3) Model format issues: ensure correct inference model format
125+
(4) Compilation issues: ensure CMake configuration is correct, use `cmake .. -DCMAKE_BUILD_TYPE=Release`
126+
127+
#### Q: Service performance optimization suggestions?
128+
129+
**A**: Can be optimized by:
130+
(1) Enable high-performance inference: set `enable_hpi=True`
131+
(2) Use batch processing: set appropriate `batch_size`
132+
(3) Enable TensorRT: set `use_tensorrt=True`
133+
(4) Use asynchronous processing: avoid blocking requests
134+
(5) Load balancing: use multiple service instances
135+
136+
## 5. Legacy Issues (for reference)
137+
8138
1. **Prediction error: got an unexpected keyword argument 'gradient_clip'**
9139
The installed version of paddle is incorrect. Currently, this project only supports Paddle 1.7, which will be adapted to 1.8 in the near future.
10140

docs/FAQ.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,27 @@ export FLAGS_initial_cpu_memory_in_mb=2000 # 设置初始化内存约2G左右
275275
(1)在快速安装时,如果不想安装docker,可跳过第一步,直接从第二步安装paddle开始。
276276
(2)inference模型下载时,如果没有安装wget,可直接点击模型链接或将链接地址复制到浏览器进行下载,并解压放置到相应目录。
277277

278+
#### Q:PaddleOCR安装失败,提示依赖冲突怎么办?
279+
280+
**A**:这是常见问题,可以通过以下方式解决:
281+
(1)创建新的虚拟环境:`conda create -n paddleocr python=3.8`,然后激活环境安装
282+
(2)使用指定版本安装:`pip install paddleocr==3.2.0 --no-deps`,然后单独安装依赖
283+
(3)如果使用conda,可以尝试:`conda install -c conda-forge paddleocr`
284+
285+
#### Q:GPU环境配置问题,CUDA版本不匹配怎么办?
286+
287+
**A**:首先检查CUDA版本:`nvidia-smi`,然后安装对应版本的PaddlePaddle:
288+
- CUDA 11.8:`pip install paddlepaddle-gpu==3.0.0 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html`
289+
- CUDA 12.0:`pip install paddlepaddle-gpu==3.0.0 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html`
290+
验证GPU是否可用:`python -c "import paddle; print(paddle.is_compiled_with_cuda())"`
291+
292+
#### Q:模型下载失败或下载缓慢怎么办?
293+
294+
**A**:可以通过以下方式解决:
295+
(1)设置模型下载源:`os.environ['PADDLE_PDX_MODEL_SOURCE'] = 'BOS'`(使用百度云存储)
296+
(2)手动下载模型:直接访问模型链接下载并解压到本地目录
297+
(3)使用本地模型:在初始化时指定`model_dir`参数指向本地模型路径
298+
278299
### 2.3 数据量说明
279300

280301
#### Q:简单的对于精度要求不高的OCR任务,数据集需要准备多少张呢?
@@ -496,6 +517,50 @@ checkpoints:指之前训练的中间结果,例如前一次训练到了100个
496517
检测框存在很多漏检问题,可以减小DB检测后处理的阈值参数det_db_box_thresh,防止一些检测框被过滤掉,也可以尝试设置det_db_score_mode为'slow';
497518
其他方法可以选择use_dilation为True,对检测输出的feature map做膨胀处理,一般情况下,会有效果改善;
498519

520+
#### Q: GPU推理速度慢,如何优化性能?
521+
522+
**A**:可以通过以下方式优化:
523+
(1)启用高性能推理:设置`enable_hpi=True`,自动选择最优加速策略
524+
(2)启用TensorRT加速:设置`use_tensorrt=True`,需要CUDA 11.8+和TensorRT 8.6+
525+
(3)使用半精度:设置`precision="fp16"`,可以显著提升速度
526+
(4)调整批处理大小:根据显存大小设置合适的`batch_size`
527+
(5)使用移动端模型:在精度要求不高时使用`PP-OCRv5_mobile`系列模型
528+
529+
#### Q: GPU内存不足(CUDA out of memory)怎么办?
530+
531+
**A**:可以通过以下方式解决:
532+
(1)减小批处理大小:将`batch_size`设置为1
533+
(2)减小图像尺寸:设置`det_limit_side_len=640`
534+
(3)启用内存优化:设置`enable_memory_optim=True`
535+
(4)限制GPU内存使用:设置`gpu_mem=200`
536+
(5)使用移动端模型:切换到`PP-OCRv5_mobile`系列模型
537+
538+
#### Q: 如何选择合适的模型?
539+
540+
**A**:根据应用场景选择:
541+
- 服务器高精度场景:使用`PP-OCRv5_server`系列,精度最高
542+
- 移动端部署:使用`PP-OCRv5_mobile`系列,模型小速度快
543+
- 实时处理:使用`PP-OCRv5_mobile`系列,推理速度快
544+
- 批量处理:使用`PP-OCRv5_server`系列,精度高
545+
- 多语言识别:使用`PP-OCRv5_multi_languages`,支持37种语言
546+
547+
#### Q: 本地模型路径配置问题,如何在隔离网络环境下使用?
548+
549+
**A**:可以通过以下方式配置:
550+
(1)使用本地模型路径:在初始化时指定`model_dir`参数
551+
(2)设置模型下载源:`os.environ['PADDLE_PDX_MODEL_SOURCE'] = 'BOS'`
552+
(3)手动下载模型:从官方链接下载模型并解压到本地
553+
(4)示例代码:
554+
```python
555+
ocr = PaddleOCR(
556+
det_model_dir='./models/PP-OCRv5_server_det_infer/',
557+
rec_model_dir='./models/PP-OCRv5_server_rec_infer/',
558+
cls_model_dir='./models/PP-OCRv5_cls_infer/',
559+
use_angle_cls=True,
560+
lang='ch'
561+
)
562+
```
563+
499564
#### Q:同一张图通用检测出21个条目,轻量级检测出26个 ,难道不是轻量级的好吗?
500565

501566
**A**:可以主要参考可视化效果,通用模型更倾向于检测一整行文字,轻量级可能会有一行文字被分成两段检测的情况,不是数量越多,效果就越好。
@@ -730,6 +795,44 @@ ocr_system: 检测识别串联预测
730795

731796
**A**: 近期PaddleOCR新增了[多进程预测控制参数](https://github.com/PaddlePaddle/PaddleOCR/blob/a312647be716776c1aac33ff939ae358a39e8188/tools/infer/utility.py#L103)`use_mp`表示是否使用多进程,`total_process_num`表示在使用多进程时的进程数。具体使用方式请参考[文档](https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.1/doc/doc_ch/inference.md#1-%E8%B6%85%E8%BD%BB%E9%87%8F%E4%B8%AD%E6%96%87ocr%E6%A8%A1%E5%9E%8B%E6%8E%A8%E7%90%86)
732797

798+
#### Q: 如何部署PaddleOCR为Web服务?
799+
800+
**A**:可以通过以下方式部署:
801+
(1)使用Flask部署:创建简单的Web API服务
802+
(2)使用gunicorn部署:`gunicorn -w 4 -b 0.0.0.0:5000 app:app`
803+
(3)使用异步处理:结合asyncio和ThreadPoolExecutor
804+
(4)示例代码:
805+
```python
806+
from flask import Flask, request, jsonify
807+
from paddleocr import PaddleOCR
808+
809+
app = Flask(__name__)
810+
ocr = PaddleOCR(use_angle_cls=True, lang='ch')
811+
812+
@app.route('/ocr', methods=['POST'])
813+
def ocr_api():
814+
file = request.files['image']
815+
result = ocr.ocr(file, cls=True)
816+
return jsonify({'result': result})
817+
```
818+
819+
#### Q: C++部署常见问题及解决方案?
820+
821+
**A**:常见问题及解决方案:
822+
(1)找不到动态库:设置`export LD_LIBRARY_PATH=/path/to/paddle/lib:$LD_LIBRARY_PATH`
823+
(2)OpenCV版本不匹配:确保OpenCV版本与编译时一致
824+
(3)模型格式问题:确保使用正确的推理模型格式
825+
(4)编译问题:确保CMake配置正确,使用`cmake .. -DCMAKE_BUILD_TYPE=Release`
826+
827+
#### Q: 服务性能优化建议?
828+
829+
**A**:可以通过以下方式优化:
830+
(1)启用高性能推理:设置`enable_hpi=True`
831+
(2)使用批处理:合理设置`batch_size`
832+
(3)启用TensorRT:设置`use_tensorrt=True`
833+
(4)使用异步处理:避免阻塞请求
834+
(5)负载均衡:使用多个服务实例
835+
733836
#### Q: 怎么解决paddleOCR在T4卡上有越预测越慢的情况?
734837

735838
**A**

0 commit comments

Comments
 (0)