# DetectionNetwork

DetectionNetwork node extends the
[NeuralNetwork](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/neural_network.md) by also performing
on-camera parsing (decoding) step, which parses the NN output (byte array) into bounding boxes, labels, and confidence values,
which are formatted into
[ImgDetections](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/img_detections.md) message.

Detection Network currently supports YOLO and SSD NN output formats, and replaces YoloDetectionNetwork and
MobileNetDetectionNetwork from DepthAI API v2.

## How to place it

#### Python

```python
pipeline = dai.Pipeline()
detection = pipeline.create(dai.node.DetectionNetwork)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto detection = pipeline.create<dai::node::DetectionNetwork>();
```

## Inputs and Outputs

outNetwork outputs raw/unparsed NN output (byte array) from the NN, which could be used for custom parsing on the host.

## Usage

#### Python

```python
pipeline = dai.Pipeline()
camera = pipeline.create(dai.node.Camera).build()
detection = pipeline.create(dai.node.DetectionNetwork).build(camera, dai.NNModelDescription("yolov6-nano"))
detection.setConfidenceThreshold(0.5)
detection.input.setBlocking(False)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto camera = pipeline.create<dai::node::Camera>()->build();
auto detection = pipeline.create<dai::node::DetectionNetwork>()->build(camera, dai::NNModelDescription("yolov6-nano"));
detection->setConfidenceThreshold(0.5f);
detection->input.setBlocking(false);
```

## Examples of functionality

 * [Detection network](https://docs.luxonis.com/software-v3/depthai/examples/detection_network/detection_network.md) - Run a
   YOLOv6n object detection model and display results (bounding boxes) on a video stream.
 * [Detection network remap](https://docs.luxonis.com/software-v3/depthai/examples/detection_network/detection_network_remap.md) -
   Run a YOLOv6 object detection model and map the bounding boxes onto a depth frame.
 * [Detection network replay](https://docs.luxonis.com/software-v3/depthai/examples/detection_network/detection_network_replay.md)
   - Run a YOLOv6 object detection model on a replayed video stream, visualize detections in our custom-built visualizer.

## Reference

### dai::node::DetectionNetwork

Kind: class

DetectionNetwork , base for different network specializations.

#### NeuralNetwork::Model Model

Kind: enum

#### Subnode < NeuralNetwork > neuralNetwork

Kind: variable

#### Subnode < DetectionParser > detectionParser

Kind: variable

#### Output & out

Kind: variable

Outputs ImgDetections message that carries parsed detection results. Overrides NeuralNetwork 'out' with ImgDetections output
message type.

#### Output & outNetwork

Kind: variable

Outputs unparsed inference results.

#### Input & input

Kind: variable

Input message with data to be inferred upon Default queue is blocking with size 5

#### Output & passthrough

Kind: variable

Passthrough message on which the inference was performed. Suitable for when input queue is set to non-blocking behavior.

#### DetectionNetwork(const std::shared_ptr< Device > & device)

Kind: function

#### std::shared_ptr< DetectionNetwork > build(Node::Output & input, const NNArchive & nnArchive)

Kind: function

Build DetectionNetwork node. Connect output to this node's input. Also call setNNArchive() with provided NNArchive .

parameters: output: Output to link; nnArchive: Neural network archive return: Shared pointer to DetectionNetwork node

#### std::shared_ptr< DetectionNetwork > build(const std::shared_ptr< Camera > & input, const Model & model, std::optional< float
> fps, std::optional< dai::ImgResizeMode > resizeMode)

Kind: function

Build DetectionNetwork node. Connect Camera output to this node's input and configure the inference model.

parameters: input: Camera node; model: Neural network model description, NNArchive or HubAI model id string; fps: Desired frames
per second; resizeMode: Resize mode for input frames return: Shared pointer to DetectionNetwork node

#### std::shared_ptr< DetectionNetwork > build(const std::shared_ptr< Camera > & input, const Model & model, const
ImgFrameCapability & capability)

Kind: function

Build DetectionNetwork node. Connect Camera output to this node's input and configure the inference model.

parameters: input: Camera node; model: Neural network model description, NNArchive or HubAI model id string; capability: Camera
capabilities return: Shared pointer to DetectionNetwork node

#### std::shared_ptr< DetectionNetwork > build(const std::shared_ptr< ReplayVideo > & input, const Model & model, std::optional<
float > fps)

Kind: function

#### void setNNArchive(const NNArchive & nnArchive)

Kind: function

Set NNArchive for this Node . If the archive's type is SUPERBLOB, use default number of shaves.

parameters: nnArchive: NNArchive to set

#### void setNNArchive(const NNArchive & nnArchive, int numShaves)

Kind: function

Set NNArchive for this Node , throws if the archive's type is not SUPERBLOB.

parameters: nnArchive: NNArchive to set; numShaves: Number of shaves to use

#### void setFromModelZoo(NNModelDescription description, bool useCached)

Kind: function

Download model from zoo and set it for this Node .

parameters: description: Model description to download; useCached: Use cached model if available

#### void setFromModelZoo(NNModelDescription description, int numShaves, bool useCached)

Kind: function

Download model from zoo and set it for this node.

parameters: description: Model description to download; numShaves: Number of shaves to use; useCached: Use cached model if
available

#### void setBlobPath(const std::filesystem::path & path)

Kind: function

Load network blob into assets and use once pipeline is started. parameters: Error: if file doesn't exist or isn't a valid network
blob. parameters: path: Path to network blob

#### void setBlob(OpenVINO::Blob blob)

Kind: function

Load network blob into assets and use once pipeline is started. parameters: blob: Network blob

#### void setBlob(const std::filesystem::path & path)

Kind: function

Same functionality as the setBlobPath() . Load network blob into assets and use once pipeline is started. parameters: Error: if
file doesn't exist or isn't a valid network blob. parameters: path: Path to network blob

#### void setModelPath(const std::filesystem::path & modelPath)

Kind: function

Load network model into assets. parameters: modelPath: Path to the model file.

#### void setNumPoolFrames(int numFrames)

Kind: function

Specifies how many frames will be available in the pool parameters: numFrames: How many frames will pool have

#### void setNumInferenceThreads(int numThreads)

Kind: function

How many threads should the node use to run the network. parameters: numThreads: Number of threads to dedicate to this node

#### void setNumNCEPerInferenceThread(int numNCEPerThread)

Kind: function

How many Neural Compute Engines should a single thread use for inference parameters: numNCEPerThread: Number of NCE per thread

#### void setNumShavesPerInferenceThread(int numShavesPerThread)

Kind: function

How many Shaves should a single thread use for inference parameters: numShavesPerThread: Number of shaves per thread

#### void setBackend(std::string backend)

Kind: function

Specifies backend to use parameters: backend: String specifying backend to use

#### void setBackendProperties(std::map< std::string, std::string > properties)

Kind: function

Set backend properties parameters: backendProperties: backend properties map

#### int getNumInferenceThreads()

Kind: function

How many inference threads will be used to run the network return: Number of threads, 0, 1 or 2. Zero means AUTO

#### void setConfidenceThreshold(float thresh)

Kind: function

Specifies confidence threshold at which to filter the rest of the detections. parameters: thresh: Detection confidence must be
greater than specified threshold to be added to the list

#### float getConfidenceThreshold()

Kind: function

Retrieves threshold at which to filter the rest of the detections. return: Detection confidence

#### std::vector< std::pair< Input &, std::shared_ptr< Capability > > > getRequiredInputs()

Kind: function

#### std::optional< std::vector< std::string > > getClasses()

Kind: function

#### void buildInternal()

Kind: function

Function called from within the

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
