AutoPercenty3/test/paddle2onnx/PaddleOCR/deploy/slim/prune
9700X_PC 256b2cd6e5 기존 설치 폴더 삭제 로직 개선: 강제 삭제 시도 및 재시도 로직 추가, 사용자 데이터 백업 후 삭제 확인 절차 강화. ARM 아키텍처에 최적화된 OCR 초기화 로직 추가 및 모듈 초기화 시 예외 처리 개선. 불필요한 로그 메시지 주석 처리 및 이미지 처리 모듈 통합. 업데이트 로그에 클린 설치 및 모듈 누락 추가. 2025-09-02 15:44:27 +09:00
..
README.md 기존 설치 폴더 삭제 로직 개선: 강제 삭제 시도 및 재시도 로직 추가, 사용자 데이터 백업 후 삭제 확인 절차 강화. ARM 아키텍처에 최적화된 OCR 초기화 로직 추가 및 모듈 초기화 시 예외 처리 개선. 불필요한 로그 메시지 주석 처리 및 이미지 처리 모듈 통합. 업데이트 로그에 클린 설치 및 모듈 누락 추가. 2025-09-02 15:44:27 +09:00
README_en.md 기존 설치 폴더 삭제 로직 개선: 강제 삭제 시도 및 재시도 로직 추가, 사용자 데이터 백업 후 삭제 확인 절차 강화. ARM 아키텍처에 최적화된 OCR 초기화 로직 추가 및 모듈 초기화 시 예외 처리 개선. 불필요한 로그 메시지 주석 처리 및 이미지 처리 모듈 통합. 업데이트 로그에 클린 설치 및 모듈 누락 추가. 2025-09-02 15:44:27 +09:00
export_prune_model.py 기존 설치 폴더 삭제 로직 개선: 강제 삭제 시도 및 재시도 로직 추가, 사용자 데이터 백업 후 삭제 확인 절차 강화. ARM 아키텍처에 최적화된 OCR 초기화 로직 추가 및 모듈 초기화 시 예외 처리 개선. 불필요한 로그 메시지 주석 처리 및 이미지 처리 모듈 통합. 업데이트 로그에 클린 설치 및 모듈 누락 추가. 2025-09-02 15:44:27 +09:00
sensitivity_anal.py 기존 설치 폴더 삭제 로직 개선: 강제 삭제 시도 및 재시도 로직 추가, 사용자 데이터 백업 후 삭제 확인 절차 강화. ARM 아키텍처에 최적화된 OCR 초기화 로직 추가 및 모듈 초기화 시 예외 처리 개선. 불필요한 로그 메시지 주석 처리 및 이미지 처리 모듈 통합. 업데이트 로그에 클린 설치 및 모듈 누락 추가. 2025-09-02 15:44:27 +09:00

README_en.md

PP-OCR Models Pruning

Generally, a more complex model would achieve better performance in the task, but it also leads to some redundancy in the model. Model Pruning is a technique that reduces this redundancy by removing the sub-models in the neural network model, so as to reduce model calculation complexity and improve model inference performance.

This example uses PaddleSlim providedAPIs of Pruning to compress the OCR model. PaddleSlim, an open source library which integrates model pruning, quantization (including quantization training and offline quantization), distillation, neural network architecture search, and many other commonly used and leading model compression technique in the industry.

It is recommended that you could understand following pages before reading this example

  1. PaddleOCR training methods
  2. The demo of prune

Quick start

Five steps for OCR model prune:

  1. Install PaddleSlim
  2. Prepare the trained model
  3. Sensitivity analysis and tailoring training
  4. Export model, predict deployment

1. Install PaddleSlim

git clone https://github.com/PaddlePaddle/PaddleSlim.git
cd PaddleSlim
git checkout develop
python3 setup.py install

2. Download Pre-trained Model

Model prune needs to load pre-trained models. PaddleOCR also provides a series of models. Developers can choose their own models or use their own models according to their needs.

3. Pruning sensitivity analysis

After the pre-trained model is loaded, sensitivity analysis is performed on each network layer of the model to understand the redundancy of each network layer, and save a sensitivity file which named: sen.pickle. After that, user could load the sensitivity file via the methods provided by PaddleSlim and determining the pruning ratio of each network layer automatically. For specific details of sensitivity analysis, seeSensitivity analysis The data format of sensitivity file

sen.pickle(Dict){
              'layer_weight_name_0': sens_of_each_ratio(Dict){'pruning_ratio_0': acc_loss, 'pruning_ratio_1': acc_loss}
              'layer_weight_name_1': sens_of_each_ratio(Dict){'pruning_ratio_0': acc_loss, 'pruning_ratio_1': acc_loss}
          }
example
          {
              'conv10_expand_weights': {0.1: 0.006509952684312718, 0.2: 0.01827734339798862, 0.3: 0.014528405644659832, 0.6: 0.06536008804270439, 0.8: 0.11798612250664964, 0.7: 0.12391408417493704, 0.4: 0.030615754498018757, 0.5: 0.047105205602406594}
              'conv10_linear_weights': {0.1: 0.05113190831455035, 0.2: 0.07705573833558801, 0.3: 0.12096721757739311, 0.6: 0.5135061352930738, 0.8: 0.7908166677143281, 0.7: 0.7272187676899062, 0.4: 0.1819252083008504, 0.5: 0.3728054727792405}
          }
  The function would return a dict after loading the sensitivity file. The keys of the dict are name of parameters in each layer. And the value of key is the information about pruning sensitivity of corresponding layer. In example, pruning 10% filter of the layer corresponding to conv10_expand_weights would lead to 0.65% degradation of model performance. The details could be seen at: [Sensitivity analysis](https://github.com/PaddlePaddle/PaddleSlim/blob/release/2.0-alpha/docs/zh_cn/algo/algo.md)

The function would return a dict after loading the sensitivity file. The keys of the dict are name of parameters in each layer. And the value of key is the information about pruning sensitivity of corresponding layer. In example, pruning 10% filter of the layer corresponding to conv10_expand_weights would lead to 0.65% degradation of model performance. The details could be seen at: Sensitivity analysis

Enter the PaddleOCR root directoryperform sensitivity analysis on the model with the following command

python3 deploy/slim/prune/sensitivity_anal.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml -o Global.pretrained_model="your trained model"  Global.save_model_dir=./output/prune_model/

5. Export inference model and deploy it

We can export the pruned model as inference_model for deployment:

python deploy/slim/prune/export_prune_model.py -c configs/det/ch_ppocr_v2.0/ch_det_mv3_db_v2.0.yml  -o Global.pretrained_model=./output/det_db/best_accuracy  Global.save_inference_dir=./prune/prune_inference_model

Reference for prediction and deployment of inference model:

  1. inference model python prediction
  2. inference model C++ prediction