Overview
Theretto-cli provides a command-line interface for running OCR inference on images using PaddleOCR models.
Installation
Usage
Command Structure
retto-cli/src/main.rs:20
Options
Model Paths
Path to the text detection model (ONNX format)
Path to the text classification/angle model (ONNX format)
Path to the text recognition model (ONNX format)
Path to the character dictionary file for recognition
Input
Path to a directory containing images or a single image fileSupports recursive directory traversal to process all image files
Device Configuration
Execution device for inferenceOptions:
cpu- Use CPU execution (always available)cuda- Use NVIDIA CUDA GPU (requiresbackend-ort-cudafeature)directml- Use DirectML on Windows (requiresbackend-ort-directmlfeature)
Device ID when using GPU acceleration (CUDA or DirectML)Only applicable when
--device is set to cuda or directmlModel Source
Download models from Hugging Face Hub instead of using local filesRequires:
hf-hub feature flagWhen enabled, downloads PaddleOCR v4 models from the default repository (pk5ls20/PaddleModel)Examples
Basic Usage (CPU)
Process images using CPU with Hugging Face Hub models:Using Local Models
Process with locally stored model files:GPU Acceleration (CUDA)
Run inference on NVIDIA GPU device 0:GPU Acceleration (DirectML)
Run inference using DirectML on Windows:Single Image
Process a single image file:Custom Dictionary
Use a custom character dictionary:Output
The CLI processes all images and outputs performance metrics:Log Levels
Set the log level using theRUST_LOG environment variable:
Implementation Details
Directory Walking
The CLI useswalkdir to recursively traverse directories:
retto-cli/src/main.rs:72
Session Configuration
The CLI creates a session with the specified configuration:retto-cli/src/main.rs:67
Performance Measurement
Processing time is measured and averaged across all images:retto-cli/src/main.rs:79
Features
The CLI supports different features that can be enabled during compilation:Error Handling
Common errors and solutions:Model Not Found
Model Not Found
Error:
ModelNotFoundErrorSolution: Ensure model files exist at the specified paths, or enable --use-hf-hub to download them automatically.Failed to Read Image
Failed to Read Image
Error:
Failed to read image fileSolution: Check that the image path is correct and the file is readable. Supported formats depend on the image crate.CUDA/DirectML Not Available
CUDA/DirectML Not Available
Error: Feature not enabledSolution: Rebuild with the appropriate feature flag:
--features backend-ort-cuda or --features backend-ort-directml.