|
5 | 5 | - toc |
6 | 6 | --- |
7 | 7 |
|
| 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 | + |
8 | 138 | 1. **Prediction error: got an unexpected keyword argument 'gradient_clip'** |
9 | 139 | 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. |
10 | 140 |
|
|
0 commit comments