One-line edge deployment for CV models โ convert, quantize, benchmark, and ship to any device.
Project description
๐ Py2Edg
One-line edge deployment for Computer Vision models
Convert, quantize, optimize, and benchmark CV models for any edge device โ in a single function call.
Built by Mouissat Rabah Abderrahmane
The Problem
Deploying a CV model to edge devices is painful. You need to:
- Export PyTorch โ ONNX (handle dynamic axes, opsets, tracing issues)
- Optimize the graph (constant folding, operator fusion, dead code elimination)
- Quantize (FP16? INT8? Dynamic? Static with calibration?)
- Convert to target format (TFLite? OpenVINO? CoreML?)
- Benchmark (latency, throughput, memory)
- Repeat for each device...
Py2Edg does all of this in one line.
Quick Start
pip install py2edg
import py2edg as rcv
# Deploy to Raspberry Pi 4 โ converts, optimizes, quantizes, benchmarks
report = rcv.deploy("yolov8n.pt", device="rpi4")
That's it. Py2Edg automatically:
- Converts your PyTorch model to ONNX
- Optimizes the computation graph
- Quantizes to INT8 (optimal for RPi4)
- Converts to TFLite (best format for RPi4)
- Benchmarks and generates a deployment report
Core API
rcv.deploy() โ Full Pipeline
# Raspberry Pi 4
report = rcv.deploy("model.pt", device="rpi4")
# NVIDIA Jetson Nano
report = rcv.deploy("model.pt", device="jetson_nano")
# Orange Pi 5
report = rcv.deploy("model.pt", device="orange_pi")
# Custom configuration
report = rcv.deploy(
"model.pt",
device="rpi4",
quantize="int8",
input_shape=(1, 3, 320, 320),
benchmark_runs=200,
)
report.print()
rcv.convert() โ Format Conversion
# PyTorch โ ONNX
rcv.convert("model.pt", target="onnx")
# ONNX with FP16 quantization
rcv.convert("model.pt", target="onnx", quantize="fp16")
# Auto-configure for device
rcv.convert("model.pt", device="jetson_nano")
# To TFLite with INT8
rcv.convert("model.onnx", target="tflite", quantize="int8")
rcv.benchmark() โ Performance Measurement
stats = rcv.benchmark("model.onnx", input_shape=(1, 3, 640, 640))
print(f"Latency: {stats.latency_mean_ms:.1f} ms")
print(f"Throughput: {stats.throughput_fps:.0f} FPS")
print(f"P95: {stats.latency_p95_ms:.1f} ms")
rcv.compare() โ Side-by-Side Comparison
rcv.compare(
"model.onnx",
"model_fp16.onnx",
"model_int8.onnx",
input_shape=(1, 3, 640, 640),
)
# โโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโ
# โ Model โ Size(MB) โ Mean(ms) โ FPS โ vs Base โ
# โโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโค
# โ model โ 25.30 โ 18.42 โ 54.3 โ baseline โ
# โ model_fp16 โ 12.70 โ 12.15 โ 82.3 โ 1.52x โ
# โ model_int8 โ 6.80 โ 8.91 โ 112.2 โ 2.07x โ
# โโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโ
rcv.validate() โ Output Accuracy Check
result = rcv.validate(pytorch_model, "model_fp16.onnx")
print(f"Max diff: {result['max_diff']:.6f}")
print(f"Passed: {result['passed']}")
Built-in Device Profiles
| Device | Format | Quantize | Notes |
|---|---|---|---|
rpi4 |
TFLite | INT8 | Best for real-time on RPi4 |
rpi5 |
TFLite | INT8 | 2x faster than RPi4 |
jetson_nano |
ONNX | FP16 | CUDA + TensorRT |
jetson_orin |
ONNX | FP16 | Extremely powerful |
orange_pi |
ONNX | INT8 | RK3588 NPU support |
coral_tpu |
TFLite | UINT8 | Edge TPU compiler |
android_cpu |
TFLite | INT8 | XNNPACK delegate |
android_gpu |
TFLite | FP16 | GPU delegate |
ios_coreml |
CoreML | FP16 | Apple Neural Engine |
server_gpu |
ONNX | FP16 | TensorRT provider |
Custom Devices
rcv.register_device(rcv.DeviceProfile(
name="my_fpga",
display_name="Custom FPGA Board",
compute="npu",
memory_mb=256,
preferred_format="onnx",
quantize="int8",
))
Deployment Recipes
Save and share reproducible deployment configs:
recipe = rcv.DeployRecipe(
name="yolo-rpi4",
model="yolov8n.pt",
device="rpi4",
)
recipe.apply_device_defaults()
rcv.save_recipe(recipe, "deploy.yaml")
# Later, or on another machine:
recipe = rcv.load_recipe("deploy.yaml")
report = rcv.deploy(recipe=recipe)
CLI
# Full deployment
py2edg deploy model.pt --device rpi4
# Convert only
py2edg convert model.pt --target onnx --quantize fp16
# Benchmark
py2edg benchmark model.onnx --runs 200
# Inspect model
py2edg inspect model.onnx
# List devices
py2edg devices
# Create recipe
py2edg recipe create --device jetson_nano --model model.pt -o deploy.yaml
Architecture
py2edg/
โโโ api.py # High-level one-liner API (convert, deploy, benchmark, ...)
โโโ converter.py # Format conversion engine (PyTorchโONNXโTFLite/OpenVINO)
โโโ quantizer.py # Quantization (FP16, INT8 static/dynamic)
โโโ optimizer.py # Graph optimization (fusion, pruning, simplification)
โโโ benchmark.py # Speed/memory benchmarking with statistics
โโโ devices.py # Edge device profiles (RPi, Jetson, Coral, mobile, ...)
โโโ recipe.py # YAML-based deployment recipes
โโโ report.py # Deployment report generation
โโโ cli.py # Command-line interface
โโโ _imports.py # Lazy optional dependency management
Installation Options
pip install py2edg # Core (ONNX Runtime)
pip install py2edg[torch] # + PyTorch support
pip install py2edg[tflite] # + TFLite conversion
pip install py2edg[openvino] # + OpenVINO support
pip install py2edg[full] # Everything
Contributing
git clone https://github.com/Rahimdzx/py2edg.git
cd py2edg
pip install -e ".[dev]"
pytest
License
MIT License โ see LICENSE for details.
Author
Mouissat Rabah Abderrahmane
- AI & Robotics Engineer | MSc from Saint Petersburg State University
- GitHub: @Rahimdzx
Made with โค๏ธ ๐ฉ๐ฟ
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py2edg-0.1.1.tar.gz.
File metadata
- Download URL: py2edg-0.1.1.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee4dd613d72c875c3938f6db96d3e691101790613bcd1428c7b785f96fc443c4
|
|
| MD5 |
dbc6d0cd32a096e4a0d4e15a5c967d7b
|
|
| BLAKE2b-256 |
9622eccc49d8455505cf1689f1eb1fb155992c565a01feb1ec40279227de8b49
|
File details
Details for the file py2edg-0.1.1-py3-none-any.whl.
File metadata
- Download URL: py2edg-0.1.1-py3-none-any.whl
- Upload date:
- Size: 32.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7886358d5ea05b4c0ed5929f5eeb15b7f57d3e790745dbffedca89ce3a4caa41
|
|
| MD5 |
a415d095fd81e7f2e3305da0df4a4860
|
|
| BLAKE2b-256 |
61ca4d40c0902a2b1cf1bab42f4c7188ca3f7399a24e1ea0d73b770f13014d3e
|