🧪 New tutorials are being published — build from robot arms to sensors step by step
Skip to content

Edge AI Deployment Intro

For developers taking a model from "trained" to "running on edge devices". Using NVIDIA Jetson as the reference platform.

1. Why Edge Deployment?

CompareCloud InferenceEdge Inference
Latency50-500ms network round-trip<10ms on-device
PrivacyData leaves deviceData stays local
CostOngoing GPU feesOne-time hardware
OfflineUnavailable offlineFully offline

For robotics (real-time control), industrial inspection (pipeline-sensitive), and privacy-sensitive scenarios (medical/security), edge deployment is a necessity.

2. Deployment Paths

PyTorch Model
   │  torch.onnx.export

ONNX ──► TensorRT Engine ──► Inference App
   │              │
   └──► TorchScript ──► Inference App (simpler path)
PathSpeedup vs native PyTorchBest For
TorchScript~1.5-2xQuick, minimal changes
ONNX Runtime~2-4xCross-platform
TensorRT5-10xPerformance-first, Jetson/edge

3. Quick Start: PyTorch → TensorRT

3.1 Export ONNX

python
import torch

# Safe load: weights_only=True prevents deserialization attacks
model = torch.load('model.pt', map_location='cuda', weights_only=True)
model.eval()

dummy = torch.randn(1, 3, 224, 224).cuda()
torch.onnx.export(
    model, dummy, 'model.onnx',
    input_names=['input'], output_names=['output'],
    opset_version=17,
)

3.2 ONNX → TensorRT Engine

bash
trtexec --onnx=model.onnx \
        --saveEngine=model.engine \
        --fp16 \
        --workspace=2048

3.3 Python Inference

python
import tensorrt as trt
import pycuda.driver as cuda
import pycuda.autoinit

with open('model.engine', 'rb') as f:
    engine = trt.Runtime(trt.Logger()).deserialize_cuda_engine(f.read())
context = engine.create_execution_context()

4. Performance Checklist

  • [ ] Use --fp16 (half precision) instead of fp32
  • [ ] Reduce input resolution to task minimum
  • [ ] Benchmark with trtexec for actual FPS
  • [ ] batch=1 is usually best for robotics
  • [ ] Check power mode (sudo nvpmodel -m 0)

5. FAQ

Q: TensorRT errors with Unsupported layer?

A: The model has operators TensorRT doesn't support. Try: newer TensorRT, onnx-simplifier, lower opset.

Q: Does fp16 hurt accuracy?

A: Most CV models are nearly lossless; validate mAP for detection/segmentation.

Q: Out of memory (workspace)?

A: Lower workspace or input resolution; the 16GB model is more comfortable.

Q: Still slow with TensorRT?

A: Verify GPU is actually used (nvidia-smi); avoid repeated GPU↔CPU copies.


Support