Skip to main content

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

PyPI Python License


The Problem

Deploying a CV model to edge devices is painful. You need to:

  1. Export PyTorch โ†’ ONNX (handle dynamic axes, opsets, tracing issues)
  2. Optimize the graph (constant folding, operator fusion, dead code elimination)
  3. Quantize (FP16? INT8? Dynamic? Static with calibration?)
  4. Convert to target format (TFLite? OpenVINO? CoreML?)
  5. Benchmark (latency, throughput, memory)
  6. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py2edg-0.1.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py2edg-0.1.1-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

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

Hashes for py2edg-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ee4dd613d72c875c3938f6db96d3e691101790613bcd1428c7b785f96fc443c4
MD5 dbc6d0cd32a096e4a0d4e15a5c967d7b
BLAKE2b-256 9622eccc49d8455505cf1689f1eb1fb155992c565a01feb1ec40279227de8b49

See more details on using hashes here.

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

Hashes for py2edg-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7886358d5ea05b4c0ed5929f5eeb15b7f57d3e790745dbffedca89ce3a4caa41
MD5 a415d095fd81e7f2e3305da0df4a4860
BLAKE2b-256 61ca4d40c0902a2b1cf1bab42f4c7188ca3f7399a24e1ea0d73b770f13014d3e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page