Overview
The DNN (Deep Neural Networks) module provides:- Loading models from popular frameworks (TensorFlow, PyTorch, ONNX, Caffe, Darknet)
- Forward inference (no training)
- Multiple backend support (CPU, OpenCL, CUDA)
- Pre-trained model zoo
The DNN module is for inference only. For training, use frameworks like TensorFlow or PyTorch.
Quick Start
Net Class
Loading Models
Setting Backend and Target
Inference
Blob Preparation
blobFromImage
blobFromImages (Batch)
Blob Format
Blobs use NCHW format:- N: Batch size
- C: Channels
- H: Height
- W: Width
Common Tasks
Image Classification
Object Detection (YOLO)
Semantic Segmentation
Model Zoo
OpenCV provides pre-trained models:Performance Optimization
Backend Selection
Input Size
Batch Processing
Best Practices
Use ONNX Format
ONNX provides best compatibility across frameworks
Enable GPU
Use CUDA backend for 5-10x speedup on NVIDIA GPUs
Optimize Input Size
Smaller inputs trade accuracy for speed
Batch When Possible
Batch processing improves GPU utilization
Troubleshooting
Model Loading Issues
Check Backend Support
Enable Diagnostic Mode
See Also
- DNN Network API - Detailed Net class reference
- DNN Layers - Layer types and custom layers
- DNN Inference - Advanced inference techniques
- Object Detection Module - Classic detection methods
