Overview
TheNet class is the core of OpenCV’s DNN module. It represents a neural network loaded from various frameworks and provides methods for inference.
Loading Models
readNet (Auto-detect)
Framework-Specific Loaders
ONNX
TensorFlow
Caffe
Darknet (YOLO)
Backend and Target
setPreferableBackend
DNN_BACKEND_DEFAULT: Default OpenCV implementationDNN_BACKEND_OPENCV: Pure OpenCV implementationDNN_BACKEND_CUDA: NVIDIA CUDADNN_BACKEND_INFERENCE_ENGINE: Intel OpenVINODNN_BACKEND_VKCOM: Vulkan
setPreferableTarget
DNN_TARGET_CPU: CPUDNN_TARGET_OPENCL: OpenCL (GPU)DNN_TARGET_OPENCL_FP16: OpenCL with FP16DNN_TARGET_CUDA: CUDADNN_TARGET_CUDA_FP16: CUDA with FP16DNN_TARGET_MYRIAD: Intel MyriadDNN_TARGET_FPGA: FPGA
Backend/Target Compatibility
Setting Inputs
setInput
blob: 4D blob (NCHW format)name: Input layer name (optional if single input)scalefactor: Multiplicative scaling factormean: Mean values to subtract
Forward Pass
forward (Single Output)
forward (Multiple Outputs)
forwardAsync (Asynchronous)
Network Information
empty
getLayerNames
getLayerId
getLayer
getUnconnectedOutLayersNames
Network Modification
setInputsNames
setInputShape
getParam
setParam
Performance Analysis
getPerfProfile
getFLOPS
getMemoryConsumption
Network Optimization
enableFusion
enableWinograd
Debugging
dump
dumpToFile
dumpToPbtxt
Complete Example
See Also
- DNN Module - DNN module overview
- DNN Layers - Layer types
- DNN Inference - Inference utilities
