# 1079863482/paddle2torch_ppocrv3 architecture

> Architecture diagram of the GitHub repository 1079863482/paddle2torch_ppocrv3, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-07-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/1079863482/paddle2torch_ppocrv3
- Repository: https://github.com/1079863482/paddle2torch_ppocrv3

## Overview

##### Project type and purpose
- This is a conversion and inference utility for PaddleOCRv3. Its goal is to take pretrained PaddleOCRv3 detection and recognition models, convert them to PyTorch format, and provide simple inference scripts (including an ONNX route).

##### File structure
- Top-level scripts:
- paddle2torch_ppocrv3_det.py – converts Paddle detection model → PyTorch
- paddle2torch_ppocrv3_rec.py – converts Paddle recognition model → PyTorch
- onnx_infer.py – exports or loads an ONNX version for inference
- torch_det_infer.py & torch_rec_infer.py – run inference using the converted PyTorch models
- Folders:
- det/ – detection model definitions and helper modules (CommonModules.py, DB_fpn.py, DetDbHead.py, DetMobilenetV3.py, DetModel.py)
- rec/ – recognition model definitions (RNN.py, RecCTCHead.py, RecModel.py, RecMv1_enhance.py, RecSARHead.py, RecSVTR.py)
- weights/ – directory to drop downloaded PaddleOCRv3 weights (and a label file)
- det_images/ & rec_images/ – sample image folders for inference
- No service layers or databases; it is a library/CLI tool.

##### README insights
- Confirms that you download PaddleOCRv3 train-time files into weights/ and run the conversion scripts.
- Points to a blog post for the conversion logic details.

a. Main components
- Input: PaddleOCRv3 weight files (weights/)
- Conversion modules:
– DetConverter (paddle2torch_ppocrv3_det.py + det/*.py)
– RecConverter (paddle2torch_ppocrv3_rec.py + rec/*.py)
- Output: PyTorch models (saved state_dict)
- Inference modules:
– TorchDetInfer (torch_det_infer.py)
– TorchRecInfer (torch_rec_infer.py)
– ONNX path (onnx_infer.py)
- Sample data: det_images/, rec_images/
b. Relationships and data flow
- Converter modules load Paddle weights, apply mapping logic (CommonModules etc.), emit PyTorch .pth files
c. Architectural patterns & principles
- Modular separation: detection vs. recognition codebases
- Single-responsibility scripts: one script for conversion, one for inference
- Shared common utilities (CommonModules) to avoid duplication
d. Technologies, frameworks, libraries
- PaddlePaddle loader (implicit in conversion)
- PyTorch model definitions & torch.save/torch.load
- ONNX export via torch.onnx or onnxruntime for inference
- NumPy/OpenCV (likely) in infer scripts for image I/O

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Artifacts
    Weights[(PaddleOCRv3 Weights\nweights/)]:::data
    PyTorchModels[(PyTorch Models\n*.pth)]:::data
    ONNXModel[(ONNX Model\n*.onnx)]:::data
    DetImages[/det_images/]:::data
    RecImages[/rec_images/]:::data

    %% Conversion Subgraphs
    subgraph "Detection Conversion" 
        direction TB
        DetConv["DetConverter\npaddle2torch_ppocrv3_det.py"]:::detection
        subgraph "Det Model Definitions"
            direction TB
            CommonModules["CommonModules.py"]:::util
            DB_fpn["DB_fpn.py"]:::detection
            DetDbHead["DetDbHead.py"]:::detection
            DetMobilenetV3["DetMobilenetV3.py"]:::detection
            DetModel["DetModel.py"]:::detection
        end
    end

    subgraph "Recognition Conversion"
        direction TB
        RecConv["RecConverter\npaddle2torch_ppocrv3_rec.py"]:::recognition
        subgraph "Rec Model Definitions"
            direction TB
            RNN["RNN.py"]:::recognition
            RecCTCHead["RecCTCHead.py"]:::recognition
            RecModel["RecModel.py"]:::recognition
            RecMv1_enhance["RecMv1_enhance.py"]:::recognition
            RecSARHead["RecSARHead.py"]:::recognition
            RecSVTR["RecSVTR.py"]:::recognition
        end
    end

    %% Inference Subgraphs
    subgraph "Inference"
        direction TB
        TorchDetInfer["TorchDetInfer\ntorch_det_infer.py"]:::detection
        TorchRecInfer["TorchRecInfer\ntorch_rec_infer.py"]:::recognition
        ONNXInfer["ONNXInfer\nonnx_infer.py"]:::data
    end

    %% Flow Edges
    Weights -->|"*.pdparams"| DetConv
    Weights -->|"*.pdparams"| RecConv

    DetConv -->|"state_dict"| PyTorchModels
    RecConv -->|"state_dict"| PyTorchModels

    PyTorchModels -->|"torch.load"| TorchDetInfer
    PyTorchModels -->|"torch.load"| TorchRecInfer
    PyTorchModels -->|"torch.onnx export"| ONNXModel
    ONNXModel -->|"onnxruntime"| ONNXInfer

    DetImages -->|"input image"| TorchDetInfer
    RecImages -->|"input image"| TorchRecInfer

    %% Shared Utilities
    DetConv --> CommonModules
    RecConv --> CommonModules

    %% Click Events
    click Weights "https://github.com/1079863482/paddle2torch_ppocrv3/tree/main/weights/"
    click DetConv "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/paddle2torch_ppocrv3_det.py"
    click CommonModules "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/det/CommonModules.py"
    click DB_fpn "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/det/DB_fpn.py"
    click DetDbHead "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/det/DetDbHead.py"
    click DetMobilenetV3 "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/det/DetMobilenetV3.py"
    click DetModel "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/det/DetModel.py"
    click RecConv "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/paddle2torch_ppocrv3_rec.py"
    click RNN "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/rec/RNN.py"
    click RecCTCHead "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/rec/RecCTCHead.py"
    click RecModel "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/rec/RecModel.py"
    click RecMv1_enhance "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/rec/RecMv1_enhance.py"
    click RecSARHead "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/rec/RecSARHead.py"
    click RecSVTR "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/rec/RecSVTR.py"
    click TorchDetInfer "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/torch_det_infer.py"
    click TorchRecInfer "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/torch_rec_infer.py"
    click ONNXInfer "https://github.com/1079863482/paddle2torch_ppocrv3/blob/main/onnx_infer.py"
    click DetImages "https://github.com/1079863482/paddle2torch_ppocrv3/tree/main/det_images/"
    click RecImages "https://github.com/1079863482/paddle2torch_ppocrv3/tree/main/rec_images/"

    %% Styles
    classDef detection fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef recognition fill:#E0FFD8,stroke:#22863a,color:#22863a
    classDef data fill:#FFE4B5,stroke:#d73a49,color:#d73a49
    classDef util fill:#FFDFAE,stroke:#735c0f,color:#735c0f
```
