### Docker Compose output example Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL-NVIDIA-Blackwell.html Example output after successfully starting the server with Docker Compose, indicating the Uvicorn server is running. ```text paddleocr-vl-api | INFO: Started server process [1] paddleocr-vl-api | INFO: Waiting for application startup. paddleocr-vl-api | INFO: Application startup complete. paddleocr-vl-api | INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit) ``` -------------------------------- ### Quick Start with Command Line Source: https://www.paddleocr.ai/latest/version3.x/module_usage/doc_vlm.html?q= This command-line example demonstrates how to quickly use the DocVLM module to process an image and query its content. ```APIDOC ## Quick Start To quickly experience the DocVLM module, you can use the following command-line instruction: ```bash paddleocr doc_vlm -i "{'image': 'https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/medal_table.png', 'query': '识别这份表格的内容, 以markdown格式输出'}" ``` This command uses the `paddle_dynamic` inference engine by default. Ensure you have PaddlePaddle installed according to the PaddlePaddle installation guide. ``` -------------------------------- ### Download Example Dataset for Text Detection Source: https://www.paddleocr.ai/latest/version3.x/module_usage/text_detection.html Use this command to download the example dataset for text detection model training. Ensure you have wget installed. ```bash # 下载示例数据集 wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/ocr_det_dataset_examples.tar tar -xf ocr_det_dataset_examples.tar ``` -------------------------------- ### Quick Start with Command Line Source: https://www.paddleocr.ai/latest/version3.x/module_usage/doc_vlm.html Use this command to quickly experience the DocVLM module with a sample image and query. Ensure PaddleOCR is installed. ```bash paddleocr doc_vlm -i "{'image': 'https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/medal_table.png', 'query': '识别这份表格的内容, 以markdown格式输出'}" ``` -------------------------------- ### Run Server with PaddleX CLI (OCR Example) Source: https://www.paddleocr.ai/latest/version3.x/deployment/serving.html Example of running the serving server for a general OCR pipeline using the PaddleX CLI. This command starts the server with the 'OCR' pipeline. ```bash paddlex --serve --pipeline OCR ``` -------------------------------- ### Download Example Dataset Source: https://www.paddleocr.ai/latest/version3.x/module_usage/table_structure_recognition.html Downloads and extracts an example dataset for table structure recognition. Ensure you have wget installed. ```bash wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/table_rec_dataset_examples.tar tar -xf table_rec_dataset_examples.tar ``` -------------------------------- ### Quick Start with Command Line Source: https://www.paddleocr.ai/latest/version3.x/module_usage/seal_text_detection.html?q= Experience seal text detection with a single command line instruction. This example uses a provided URL for the input image. ```APIDOC ## Quick Start Use one command to quickly experience seal text detection: ```bash paddleocr seal_text_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/seal_text_det.png ``` **Note:** This command defaults to using the `paddle_static` inference engine. Ensure you have PaddlePaddle installed according to the framework's installation guide. ``` -------------------------------- ### Install Training Dependencies Source: https://www.paddleocr.ai/latest/version3.x/installation.html Install the remaining training dependencies by running the pip install command with the requirements.txt file. ```bash python -m pip install -r requirements.txt ``` -------------------------------- ### Start GenAI Server with PaddleOCR CLI (vLLM) Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html Starts the PaddleOCR GenAI server using the PaddleOCR CLI, specifying vLLM as the backend. This command is used after installing dependencies via `paddleocr install_genai_server_deps`. ```bash paddleocr genai_server --model_name PaddleOCR-VL-1.5-0.9B --backend vllm --port 8118 ``` -------------------------------- ### Server Startup Information Source: https://www.paddleocr.ai/latest/version3.x/deployment/serving.html Example output indicating that the Uvicorn server has started successfully and is listening on a specific port. This message confirms the server is running and ready to accept requests. ```text INFO: Started server process [63108] INFO: Waiting for application startup. INFO: Application startup complete. INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit) ``` -------------------------------- ### Command-line Quick Start Source: https://www.paddleocr.ai/latest/version3.x/module_usage/seal_text_detection.html Quickly experience seal text detection using a single command-line instruction. This example uses a remote image URL. ```APIDOC ## Command-line Quick Start Use a single command to quickly experience seal text detection: ``` paddleocr seal_text_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/seal_text_det.png ``` This example defaults to the `paddle_static` inference engine. Ensure PaddlePaddle is installed according to the framework installation guide. ``` -------------------------------- ### Quick Start with Command Line Source: https://www.paddleocr.ai/latest/version3.x/module_usage/seal_text_detection.html?q= Use this command for a quick, one-line experience of seal text detection. Ensure PaddleOCR is installed. ```bash paddleocr seal_text_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/seal_text_det.png ``` -------------------------------- ### Execute Packaging Script Source: https://www.paddleocr.ai/latest/version3.x/deployment/packaging.html Examples of how to run the packaging script. Use `--file` to specify your main script and `--nvidia` to include NVIDIA dependencies. ```bash python package.py --file main.py # 将NVIDIA的CUDA、cuDNN相关依赖库打包至可执行文件的同级目录中。 python package.py --file main.py --nvidia ``` -------------------------------- ### Install PaddlePaddle for GPU and CPU Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html?q= Commands to install PaddlePaddle framework for NVIDIA GPUs (CUDA 12.6 example) or x64 CPUs. Ensure only one version (CPU or GPU) is installed. ```bash # 英伟达 GPU(以 CUDA 12.6 为例) python -m pip install paddlepaddle-gpu==3.2.1 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/ # x64 CPU python -m pip install paddlepaddle==3.2.1 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/ ``` -------------------------------- ### Install PaddlePaddle for GPU and CPU Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html Install PaddlePaddle inference engine. Choose either the GPU or CPU version, as they cannot be installed simultaneously. Examples provided for NVIDIA GPU with CUDA 12.6 and x64 CPU. ```bash # NVIDIA GPU (example with CUDA 12.6) python -m pip install paddlepaddle-gpu==3.2.1 -i https://www.paddlepaddle.org.cn/packages/stable/cu126/ # x64 CPU python -m pip install paddlepaddle==3.2.1 -i https://www.paddlepaddle.org.cn/packages/stable/cpu/ ``` -------------------------------- ### Check CUDA Version and Install PaddlePaddle Source: https://www.paddleocr.ai/latest/FAQ.html Verify your CUDA version using `nvidia-smi` and install the corresponding PaddlePaddle GPU version. This is crucial for GPU environment setup. ```bash nvidia-smi ``` ```bash pip install paddlepaddle-gpu==3.0.0 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/avx/stable.html ``` -------------------------------- ### Download Example Dataset Source: https://www.paddleocr.ai/latest/version3.x/module_usage/text_recognition.html Use this command to download the example dataset for text recognition. ```bash wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/ocr_rec_dataset_examples.tar tar -xf ocr_rec_dataset_examples.tar ``` -------------------------------- ### Run Server with PaddleX CLI (Basic) Source: https://www.paddleocr.ai/latest/version3.x/deployment/serving.html Start the serving server using the PaddleX CLI. Specify the pipeline name or configuration file path. Other command-line options can be used to adjust settings like model path, batch size, and deployment device. ```bash paddlex --serve --pipeline {PaddleX 产线注册名或产线配置文件路径} [{其他命令行选项}] ``` -------------------------------- ### Quick Start Table Classification Source: https://www.paddleocr.ai/latest/version3.x/module_usage/table_classification.html Use this command to quickly experience the table classification module. It requires PaddleOCR to be installed. ```bash paddleocr table_classification -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg ``` -------------------------------- ### Install Serving Plugin with PaddleX CLI Source: https://www.paddleocr.ai/latest/version3.x/deployment/serving.html Install the PaddleX serving deployment plugin using the PaddleX CLI. This is a prerequisite for basic serving deployment. ```bash paddlex --install serving ``` -------------------------------- ### Go SDK Example Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/doc_preprocessor.html?q= Example code in Go demonstrating how to read an image file, encode it to base64, construct the API request payload, send the request to the document preprocessing service, and process the response. ```Go package main import ( "bytes" "encoding/base64" "encoding/json" "fmt" "io/ioutil" "net/http" "os" ) const API_URL = "http://localhost:8080/document-preprocessing" // Replace with your actual API endpoint func main() { filePath := "./demo.jpg" fileBytes, err := ioutil.ReadFile(filePath) if err != nil { fmt.Printf("Error reading file: %v\n", err) return } fileData := base64.StdEncoding.EncodeToString(fileBytes) payload := map[string]interface{}{ "file": fileData, "fileType": 1, } payloadBytes, err := json.Marshal(payload) if err != nil { fmt.Printf("Error marshaling payload: %v\n", err) return } client := &http.Client{} req, err := http.NewRequest("POST", API_URL, bytes.NewBuffer(payloadBytes)) if err != nil { fmt.Printf("Error creating request: %v\n", err) return } req.Header.Set("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %v\n", err) return } defer res.Body.Close() if res.StatusCode != http.StatusOK { fmt.Printf("Unexpected status code: %d\n", res.StatusCode) return } body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Printf("Error reading response body: %v\n", err) return } type DocPreprocessingResult struct { PrunedResult map[string]interface{} `json:"prunedResult"` OutputImage string `json:"outputImage"` DocPreprocessingImage *string `json:"docPreprocessingImage"` InputImage *string `json:"inputImage"` } type Response struct { Result struct { DocPreprocessingResults []DocPreprocessingResult `json:"docPreprocessingResults"` DataInfo interface{} `json:"dataInfo"` } `json:"result"` } var respData Response if err := json.Unmarshal(body, &respData); err != nil { fmt.Printf("Error unmarshaling response: %v\n", err) return } for i, res := range respData.Result.DocPreprocessingResults { fmt.Printf("Result %d - prunedResult: %+v\n", i, res.PrunedResult) imgBytes, err := base64.StdEncoding.DecodeString(res.OutputImage) if err != nil { fmt.Printf("Error decoding outputImage at index %d: %v\n", i, err) continue } filename := fmt.Sprintf("out_%d.png", i) if err := os.WriteFile(filename, imgBytes, 0644); err != nil { fmt.Printf("Error saving image %s: %v\n", filename, err) continue } fmt.Printf("Saved output image to %s\n", filename) } } ``` -------------------------------- ### Python Service Call Example Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PP-StructureV3.html?q= This Python snippet demonstrates how to call the PaddleOCR service for layout parsing. Ensure you have the 'requests' library installed. ```python import requests import json # Replace with your actual service URL url = "http://127.0.0.1:8080/predict/paddleocr" # Image file path or base64 encoded string # For local files, you can use: # with open("image.jpg", "rb") as f: # image_data = f.read() # image_base64 = base64.b64encode(image_data).decode("utf-8") # Example using a URL image_url = "https://raw.githubusercontent.com/PaddlePaddle/PaddleOCR/release/2.7/doc/doc_en/pics/quick_start/chinese_ocr_en_img1.jpg" params = { "file": image_url, "fileType": 1, # 1 for image, 0 for PDF "use_angle_cls": True, # Example of other parameters "det_model_dir": "./inference/ch_PP-OCRv3_det_infer", "rec_model_dir": "./inference/ch_PP-OCRv3_rec_infer", "cls_model_dir": "./inference/ch_ppocr_mobile_v2.0_cls_infer" } headers = {"Content-Type": "application/json"} response = requests.post(url=url, data=json.dumps(params), headers=headers) if response.status_code == 200: print(response.json()) else: print(f"Error: {response.status_code}") print(response.text) ``` -------------------------------- ### Quick Start Table Cells Detection Source: https://www.paddleocr.ai/latest/version3.x/module_usage/table_cells_detection.html?q= Use this command to quickly experience the table cells detection functionality. Ensure PaddleOCR is installed. ```bash paddleocr table_cells_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg ``` -------------------------------- ### Download Example Dataset Source: https://www.paddleocr.ai/latest/version3.x/module_usage/text_recognition.html?q= Use wget to download the example dataset for text recognition. After downloading, extract the tar archive. ```bash # 下载示例数据集 wget https://paddle-model-ecology.bj.bcebos.com/paddlex/data/ocr_rec_dataset_examples.tar tar -xf ocr_rec_dataset_examples.tar ``` -------------------------------- ### Quick Start Layout Detection Source: https://www.paddleocr.ai/latest/version3.x/module_usage/layout_detection.html Use this command to quickly experience layout detection with a default model and engine. Ensure PaddleOCR is installed. ```bash paddleocr layout_detection -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/layout.jpg ``` -------------------------------- ### Install ADB on Linux Source: https://www.paddleocr.ai/latest/version3.x/deployment/on_device_deployment.html Install ADB and necessary tools like wget on Linux systems using apt. ```bash sudo apt update sudo apt install -y wget adb ``` -------------------------------- ### Quick Start with Command Line Source: https://www.paddleocr.ai/latest/version3.x/module_usage/chart_parsing.html This snippet shows how to quickly experience the chart parsing functionality using a single command line instruction with the default paddle_dynamic engine. ```APIDOC ## Quick Start with Command Line Use a single command to quickly experience chart parsing: ```bash paddleocr chart_parsing -i "{'image': 'https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/chart_parsing_02.png'}" ``` This example uses the `paddle_dynamic` inference engine by default. Ensure you have PaddlePaddle installed according to the framework installation guide. ``` -------------------------------- ### Run PPStructureV3 with Specific Input Pattern and Batching Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/instructions/parallel_inference.html Configure the PPStructureV3 pipeline to process specific file types (e.g., '.jpg') from the input directory. This example also sets multiple instances per device and a batch size for efficient processing across specified GPUs. ```bash python infer_mp.py \ --pipeline PPStructureV3 \ --input_dir input_images/ \ --device 'gpu:0,2' \ --output_dir output \ --instances_per_device 2 \ --batch_size 4 \ --input_glob_pattern '*.jpg' ``` -------------------------------- ### Node.js Service Call Example Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PP-StructureV3.html?q= This Node.js snippet demonstrates how to call the PaddleOCR service for layout parsing using the 'axios' library. Ensure 'axios' is installed. ```javascript const axios = require('axios'); const fs = require('fs'); const url = 'http://127.0.0.1:8080/predict/paddleocr'; // Function to read and base64 encode an image file function getImageBase64(filePath) { const image = fs.readFileSync(filePath); return Buffer.from(image).toString('base64'); } // Example using a local file const imagePath = './test.jpg'; const imageBase64 = getImageBase64(imagePath); const params = { file: imageBase64, fileType: 1, // 1 for image, 0 for PDF use_angle_cls: true, det_model_dir: "./inference/ch_PP-OCRv3_det_infer", rec_model_dir: "./inference/ch_PP-OCRv3_rec_infer", cls_model_dir: "./inference/ch_ppocr_mobile_v2.0_cls_infer" }; const headers = { 'Content-Type': 'application/json' }; axios.post(url, params, { headers: headers }) .then(response => { console.log(response.data); }) .catch(error => { console.error(`Error: ${error.response.status}`); console.error(error.response.data); }); ``` -------------------------------- ### Server Configuration: FastDeploy Parameters Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL.html?q= Example server-side performance tuning parameters for FastDeploy on an NVIDIA RTX 3060. ```yaml gpu-memory-utilization: 0.7 max-concurrency: 2048 ``` -------------------------------- ### Basic Service Deployment API Reference (Go) Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/doc_preprocessor.html?q= This Go code demonstrates how to send a POST request to a document preprocessing API. It includes reading a local file, encoding it to base64, constructing a JSON payload, sending the request, and processing the JSON response. Ensure the API_URL is correctly set and handle potential errors during file operations, network requests, and JSON parsing. ```go filePath := "./demo.jpg" fileBytes, err := ioutil.ReadFile(filePath) if err != nil { fmt.Printf("Error reading file: %v\n", err) return } fileData := base64.StdEncoding.EncodeToString(fileBytes) payload := map[string]interface{}{ "file": fileData, "fileType": 1, } payloadBytes, err := json.Marshal(payload) if err != nil { fmt.Printf("Error marshaling payload: %v\n", err) return } client := &http.Client{} req, err := http.NewRequest("POST", API_URL, bytes.NewBuffer(payloadBytes)) if err != nil { fmt.Printf("Error creating request: %v\n", err) return } req.Header.Set("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %v\n", err) return } deffer res.Body.Close() if res.StatusCode != http.StatusOK { fmt.Printf("Unexpected status code: %d\n", res.StatusCode) return } body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Printf("Error reading response body: %v\n", err) return } type DocPreprocessingResult struct { PrunedResult map[string]interface{} `json:"prunedResult"` OutputImage string `json:"outputImage"` DocPreprocessingImage *string `json:"docPreprocessingImage"` InputImage *string `json:"inputImage"` } type Response struct { Result struct { DocPreprocessingResults []DocPreprocessingResult `json:"docPreprocessingResults"` DataInfo interface{} `json:"dataInfo"` } `json:"result"` } var respData Response if err := json.Unmarshal(body, &respData); err != nil { fmt.Printf("Error unmarshaling response: %v\n", err) return } for i, res := range respData.Result.DocPreprocessingResults { fmt.Printf("Result %d - prunedResult: %+v\n", i, res.PrunedResult) imgBytes, err := base64.StdEncoding.DecodeString(res.OutputImage) if err != nil { fmt.Printf("Error decoding outputImage at index %d: %v\n", i, err) continue } filename := fmt.Sprintf("out_%d.png", i) if err := os.WriteFile(filename, imgBytes, 0644); err != nil { fmt.Printf("Error saving image %s: %v\n", filename, err) continue } fmt.Printf("Saved output image to %s\n", filename) } } ``` -------------------------------- ### Quick Start Table Structure Recognition Source: https://www.paddleocr.ai/latest/version3.x/module_usage/table_structure_recognition.html Use this command to quickly test the table structure recognition functionality with a sample image URL. Ensure PaddleOCR is installed. ```bash paddleocr table_structure_recognition -i https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg ``` -------------------------------- ### Setup Virtual Environment for VLM Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/PaddleOCR-VL-NVIDIA-Blackwell.html Creates and activates a Python virtual environment for installing VLM dependencies like vLLM and SGLang. This helps prevent package conflicts. ```bash # 如果当前存在已激活的虚拟环境,先通过 `deactivate` 取消激活 # 创建虚拟环境 python -m venv .venv_vlm # 激活环境 source .venv_vlm/bin/activate ``` -------------------------------- ### Go SDK Example Source: https://www.paddleocr.ai/latest/version3.x/pipeline_usage/formula_recognition.html?q= Example code demonstrating how to use the formula recognition API from a Go application. ```Go package main import ( "bytes" "encoding/base64" "encoding/json" "fmt" "io/ioutil" "net/http" "os" ) func main() { API_URL := "http://localhost:8080/formula-recognition" filePath := "./demo.jpg" fileBytes, err := ioutil.ReadFile(filePath) if err != nil { fmt.Printf("Error reading file: %v\n", err) return } fileData := base64.StdEncoding.EncodeToString(fileBytes) payload := map[string]interface{}{ "file": fileData, "fileType": 1, } payloadBytes, err := json.Marshal(payload) if err != nil { fmt.Printf("Error marshaling payload: %v\n", err) return } client := &http.Client{} req, err := http.NewRequest("POST", API_URL, bytes.NewBuffer(payloadBytes)) if err != nil { fmt.Printf("Error creating request: %v\n", err) return } req.Header.Set("Content-Type", "application/json") res, err := client.Do(req) if err != nil { fmt.Printf("Error sending request: %v\n", err) return } defer res.Body.Close() if res.StatusCode != http.StatusOK { fmt.Printf("Unexpected status code: %d\n", res.StatusCode) return } body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Printf("Error reading response body: %v\n", err) return } type FormulaRecResult struct { PrunedResult map[string]interface{} `json:"prunedResult"` OutputImages map[string]string `json:"outputImages"` InputImage *string `json:"inputImage"` } type Response struct { Result struct { FormulaRecResults []FormulaRecResult `json:"formulaRecResults"` DataInfo interface{} `json:"dataInfo"` } `json:"result"` } var respData Response if err := json.Unmarshal(body, &respData); err != nil { fmt.Printf("Error unmarshaling response: %v\n", err) return } for i, res := range respData.Result.FormulaRecResults { fmt.Printf("Result %d - prunedResult: %+v\n", i, res.PrunedResult) for imgName, imgData := range res.OutputImages { imgBytes, err := base64.StdEncoding.DecodeString(imgData) if err != nil { fmt.Printf("Error decoding image %s_%d: %v\n", imgName, i, err) continue } filename := fmt.Sprintf("%s_%d.jpg", imgName, i) if err := os.WriteFile(filename, imgBytes, 0644); err != nil { fmt.Printf("Error saving image %s: %v\n", filename, err) continue } fmt.Printf("Saved image to %s\n", filename) } } } ```