docs/en/integrations/ncnn.md
Deploying computer vision models on devices with limited computational power, such as mobile or embedded systems, requires careful format selection. Using an optimized format ensures that even resource-constrained devices can handle advanced computer vision tasks efficiently.
Exporting to NCNN format allows you to optimize your Ultralytics YOLO26 models for lightweight device-based applications. This guide covers how to convert your models to NCNN format for improved performance on mobile and embedded devices.
The NCNN framework, developed by Tencent, is a high-performance neural network inference computing framework optimized specifically for mobile platforms, including mobile phones, embedded devices, and IoT devices. NCNN is compatible with a wide range of platforms, including Linux, Android, iOS, and macOS.
NCNN is known for its fast processing speed on mobile CPUs and enables rapid deployment of deep learning models to mobile platforms, making it an excellent choice for building AI-powered applications.
NCNN models provide several key features that enable on-device machine learning, helping developers deploy models on mobile, embedded, and edge devices:
Efficient and High-Performance: NCNN models are lightweight and optimized for mobile and embedded devices like Raspberry Pi with limited resources, while maintaining high accuracy on computer vision tasks.
Quantization: NCNN supports quantization, a technique that reduces the precision of model weights and activations to improve performance and reduce memory footprint.
Compatibility: NCNN models are compatible with popular deep learning frameworks including TensorFlow, Caffe, and ONNX, allowing developers to leverage existing models and workflows.
Ease of Use: NCNN provides user-friendly tools for converting models between formats, ensuring smooth interoperability across different development environments.
Vulkan GPU Acceleration: NCNN supports Vulkan for GPU-accelerated inference across multiple vendors including AMD, Intel, and other non-NVIDIA GPUs, enabling high-performance deployment on a wider range of hardware.
NCNN models are compatible with a variety of deployment platforms:
Mobile Deployment: Optimized for Android and iOS, enabling seamless integration into mobile applications for efficient on-device inference.
Embedded Systems and IoT Devices: Ideal for resource-constrained devices like Raspberry Pi and NVIDIA Jetson. If standard inference on a Raspberry Pi with the Ultralytics Guide is insufficient, NCNN can provide significant performance improvements.
Desktop and Server Deployment: Supports deployment across Linux, Windows, and macOS for development, training, and evaluation workflows.
NCNN supports GPU acceleration through Vulkan, enabling high-performance inference on a wide range of GPUs including AMD, Intel, and other non-NVIDIA graphics cards. This is particularly useful for:
device="vulkan:0", device="vulkan:1", etc.To use Vulkan acceleration, specify the Vulkan device when running inference:
!!! example "Vulkan Inference"
=== "Python"
```python
from ultralytics import YOLO
# Load the exported NCNN model
ncnn_model = YOLO("./yolo26n_ncnn_model")
# Run inference with Vulkan GPU acceleration (first Vulkan device)
results = ncnn_model("https://ultralytics.com/images/bus.jpg", device="vulkan:0")
# Use second Vulkan device in multi-GPU systems
results = ncnn_model("https://ultralytics.com/images/bus.jpg", device="vulkan:1")
```
=== "CLI"
```bash
# Run inference with Vulkan GPU acceleration
yolo predict model='./yolo26n_ncnn_model' source='https://ultralytics.com/images/bus.jpg' device=vulkan:0
```
!!! tip "Vulkan Requirements"
Ensure you have Vulkan drivers installed for your GPU. Most modern GPU drivers include Vulkan support by default. You can verify Vulkan availability using tools like `vulkaninfo` on Linux or the Vulkan SDK on Windows.
You can expand model compatibility and deployment flexibility by converting YOLO26 models to NCNN format.
To install the required packages, run:
!!! tip "Installation"
=== "CLI"
```bash
# Install the required package for YOLO26
pip install ultralytics
```
For detailed instructions and best practices, see the Ultralytics Installation guide. If you encounter any difficulties, consult our Common Issues guide for solutions.
All Ultralytics YOLO26 models are designed to support export out of the box, making it easy to integrate them into your preferred deployment workflow. You can view the full list of supported export formats and configuration options to choose the best setup for your application.
!!! example "Usage"
=== "Python"
```python
from ultralytics import YOLO
# Load the YOLO26 model
model = YOLO("yolo26n.pt")
# Export the model to NCNN format
model.export(format="ncnn") # creates '/yolo26n_ncnn_model'
# Load the exported NCNN model
ncnn_model = YOLO("./yolo26n_ncnn_model")
# Run inference
results = ncnn_model("https://ultralytics.com/images/bus.jpg")
```
=== "CLI"
```bash
# Export a YOLO26n PyTorch model to NCNN format
yolo export model=yolo26n.pt format=ncnn # creates '/yolo26n_ncnn_model'
# Run inference with the exported model
yolo predict model='./yolo26n_ncnn_model' source='https://ultralytics.com/images/bus.jpg'
```
| Argument | Type | Default | Description |
|---|---|---|---|
format | str | 'ncnn' | Target format for the exported model, defining compatibility with various deployment environments. |
imgsz | int or tuple | 640 | Desired image size for the model input. Can be an integer for square images or a tuple (height, width) for specific dimensions. |
half | bool | False | Enables FP16 (half-precision) quantization, reducing model size and potentially speeding up inference on supported hardware. |
batch | int | 1 | Specifies export model batch inference size or the max number of images the exported model will process concurrently in predict mode. |
device | str | None | Specifies the device for exporting: GPU (device=0), CPU (device=cpu), MPS for Apple silicon (device=mps). |
For more details about the export process, visit the Ultralytics documentation page on exporting.
After exporting your Ultralytics YOLO26 models to NCNN format, you can deploy them using the YOLO("yolo26n_ncnn_model/") method as shown in the usage example above. For platform-specific deployment instructions, see the following resources:
Android: Build and integrate NCNN models for object detection in Android applications.
macOS: Deploy NCNN models on macOS systems.
Linux: Deploy NCNN models on Linux devices including Raspberry Pi and similar embedded systems.
Windows x64: Deploy NCNN models on Windows x64 using Visual Studio.
This guide covered exporting Ultralytics YOLO26 models to NCNN format for improved efficiency and speed on resource-constrained devices.
For additional details, refer to the official NCNN documentation. For other export options, visit our integration guide page.
To export your Ultralytics YOLO26 model to NCNN format:
Python: Use the export method from the YOLO class.
from ultralytics import YOLO
# Load the YOLO26 model
model = YOLO("yolo26n.pt")
# Export to NCNN format
model.export(format="ncnn") # creates '/yolo26n_ncnn_model'
CLI: Use the yolo export command.
yolo export model=yolo26n.pt format=ncnn # creates '/yolo26n_ncnn_model'
For detailed export options, see the Export documentation.
Exporting your Ultralytics YOLO26 models to NCNN offers several benefits:
For more details, see the Why Export to NCNN? section.
NCNN, developed by Tencent, is specifically optimized for mobile platforms. Key reasons to use NCNN include:
For more information, see the Key Features of NCNN Models section.
NCNN is versatile and supports various platforms:
For improved performance on Raspberry Pi, consider using NCNN format as detailed in our Raspberry Pi Guide.
To deploy your YOLO26 models on Android:
For detailed instructions, see Deploying Exported YOLO26 NCNN Models.
For more advanced guides and use cases, visit the Ultralytics deployment guide.
NCNN supports Vulkan for GPU acceleration on AMD, Intel, and other non-NVIDIA GPUs. To use Vulkan:
from ultralytics import YOLO
# Load NCNN model and run with Vulkan GPU
model = YOLO("yolo26n_ncnn_model")
results = model("image.jpg", device="vulkan:0") # Use first Vulkan device
For multi-GPU systems, specify the device index (e.g., vulkan:1 for the second GPU). Ensure Vulkan drivers are installed for your GPU. See the Vulkan GPU Acceleration section for more details.