Edge AI Best Practices
Production guidance for model selection, performance profiling, power management, OTA updates, and building reliable edge AI systems.
Model Selection for Edge
| Constraint | Recommended Architecture | Typical Size |
|---|---|---|
| <100 KB (MCU) | Tiny CNN, MicroNets | 20-100 KB |
| 1-5 MB (Mobile) | MobileNet-v2/v3, EfficientNet-Lite | 2-4 MB (INT8) |
| 5-20 MB (Jetson/Pi) | YOLOv8-small, ResNet-18 | 5-15 MB |
| >20 MB (Jetson Orin) | YOLOv8-medium, EfficientNet-B4 | 20-50 MB |
Performance Profiling
Always profile your model on the target hardware before deployment:
- Latency: Measure end-to-end inference time including preprocessing. Profile on-device, not on your development machine.
- Throughput: For video/streaming, measure frames per second (FPS). Target at least 15 FPS for real-time applications.
- Memory: Monitor peak RAM usage during inference. Edge devices have limited memory; exceeding it causes crashes.
- Power consumption: Measure Watts during inference. Critical for battery-powered and always-on devices.
- Thermal throttling: Sustained inference can cause overheating. Profile over 30+ minutes to catch thermal throttling.
import time import numpy as np import tflite_runtime.interpreter as tflite interpreter = tflite.Interpreter(model_path="model.tflite") interpreter.allocate_tensors() input_details = interpreter.get_input_details() input_shape = input_details[0]['shape'] # Warm-up runs for _ in range(10): interpreter.set_tensor(input_details[0]['index'], np.random.randn(*input_shape).astype(np.float32)) interpreter.invoke() # Benchmark times = [] for _ in range(100): start = time.perf_counter() interpreter.set_tensor(input_details[0]['index'], np.random.randn(*input_shape).astype(np.float32)) interpreter.invoke() times.append(time.perf_counter() - start) print(f"Mean: {np.mean(times)*1000:.1f}ms") print(f"P95: {np.percentile(times, 95)*1000:.1f}ms") print(f"FPS: {1/np.mean(times):.1f}")
Power Management
- Duty cycling: Run inference only when needed. Use motion detection or audio triggers to wake the system.
- Dynamic model switching: Use a lightweight model for always-on detection and switch to a heavier model for detailed analysis.
- Hardware sleep modes: Put accelerators and sensors to sleep between inference cycles.
- Batch processing: If real-time is not needed, accumulate data and process in batches to amortize startup costs.
Over-the-Air (OTA) Updates
Version your models
Track model versions alongside firmware versions. Use semantic versioning (v1.2.3).
A/B testing
Deploy new models to a small percentage of devices first. Monitor performance before full rollout.
Rollback capability
Always keep the previous model version on-device. If the new model underperforms, automatically revert.
Delta updates
Send only the changed weights, not the entire model. This reduces bandwidth and update time.
Testing Edge AI Systems
- On-device accuracy: Verify that quantized model accuracy matches your expectations. INT8 quantization can affect edge cases.
- Environmental testing: Test under varying lighting, temperatures, and vibration conditions that the device will encounter in production.
- Stress testing: Run continuous inference for hours to detect memory leaks, thermal throttling, and stability issues.
- Fallback behavior: Define what happens when inference fails, the model is corrupted, or confidence is too low.
Frequently Asked Questions
If you train with TensorFlow/Keras, use TFLite. If you train with PyTorch, use ONNX Runtime or export to TFLite via ONNX. For microcontrollers, TFLite Micro is the only practical option. For cross-platform deployment, ONNX provides the most flexibility.
Small LLMs (1-3B parameters) can run on devices with 4+ GB RAM using quantization (4-bit). llama.cpp and MLC-LLM enable this on phones and Raspberry Pi. Expect 5-15 tokens/second. For larger models, cloud inference is still necessary.
Edge Impulse is a platform for developing TinyML models. It provides a web-based workflow for data collection, model training, and deployment to microcontrollers. It is the easiest way to get started with TinyML without deep ML expertise.
Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX