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 โค๏ธ in Algeria ๐Ÿ‡ฉ๐Ÿ‡ฟ

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.0.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.0-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file py2edg-0.1.0.tar.gz.

File metadata

  • Download URL: py2edg-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 bf7feb305f711eb12eb8ce2d197f7639d40939d9e37a96e95f6ff37041b52f2a
MD5 92e260f3dcb22146b8cbfd772dc0e38a
BLAKE2b-256 06a9dc1d791e2619cabf3c4a65b7c8a81f55458ff6230b3f5edefc6cea1a37e4

See more details on using hashes here.

File details

Details for the file py2edg-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py2edg-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ba5f00cfca67f6e18fcb49ffd61a7b77c648a6d61484711a957da5924d9d6ea
MD5 81b855037410a4c139e9bdf1b517de7a
BLAKE2b-256 420085b1d48d20d8f9e3ab72a89cb30f50fc36a8911a5b36ca6e8f519141d051

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