Export Script
The basic export script is located incourse/vision_class/export/export_model.py:1:
Model Export Process
The export process follows these steps:- Load PyTorch Model: Load the trained
.ptmodel file - Configure Export: Specify target format and parameters
- Run Export: Ultralytics handles format conversion
- Verify Output: Test exported model with sample inference
Export Command
Using the Ultralytics API:Supported Export Formats
The course materials include examples for three optimized formats:ONNX Format
Location:course/vision_class/export/models/onnx/
yolo11s.onnx(38 MB)
- Cross-platform compatibility
- Hardware acceleration support
- Standard inference engines (ONNX Runtime)
- Cloud deployment
- Server inference
- Cross-platform applications
NCNN Format
Location:course/vision_class/export/models/ncnn/
model.ncnn.param(23 KB) - Architecture definitionmodel.ncnn.bin(38 MB) - Model weightsmetadata.yaml- Model metadata
- Optimized for ARM processors
- No external dependencies
- Efficient CPU inference
- Mobile devices (Android/iOS)
- Embedded systems
- Edge computing (Raspberry Pi, Jetson)
MNN Format
Location:course/vision_class/export/models/mnn/
yolo11s.mnn(38 MB)
- Alibaba’s lightweight framework
- Mobile-optimized inference
- Low power consumption
- Mobile applications
- IoT devices
- Resource-constrained environments
NCNN Model Details
The production system uses NCNN format. The metadata file (course/vision_class/export/models/ncnn/metadata.yaml:1) contains:
NCNN Inference Example
The course includes an NCNN inference test (course/vision_class/export/models/ncnn/model_ncnn.py:5):
Optimization for Edge Devices
Exported models are optimized for edge deployment through:Model Quantization
NCNN and MNN support quantization for:- Reduced model size (4x smaller with INT8)
- Faster inference (2-4x speedup)
- Lower power consumption
Hardware Acceleration
- NCNN: Vulkan GPU acceleration, ARM NEON optimization
- MNN: Metal (iOS), OpenCL, Vulkan support
- ONNX: CUDA, TensorRT, DirectML acceleration
Memory Optimization
Edge-optimized formats provide:- In-place operations to reduce memory
- Operator fusion for efficiency
- Optimized memory allocation
Export Best Practices
1. Test Inference
Always verify exported model accuracy:2. Choose Appropriate Format
| Deployment | Recommended Format |
|---|---|
| Raspberry Pi | NCNN |
| Android/iOS | NCNN or MNN |
| Cloud/Server | ONNX |
| Jetson Nano | ONNX (TensorRT) |
| Web Browser | ONNX (ONNX.js) |
3. Consider Trade-offs
- ONNX: Best compatibility, larger size
- NCNN: Best for ARM CPUs, requires compilation
- MNN: Good mobile performance, smaller ecosystem
Integration with System
The robotic arm system loads the NCNN model inmodel_loader.py:10: