# parsing_neural_network

Python API: `depthai_nodes.node.parsing_neural_network`

## Classes

### ParsingNeuralNetwork

Build inference with native parsers for each NN Archive head.

`build()` accepts an NN Archive, model description, or Model Zoo slug. Parser outputs preserve their native message types. Use
`HostParsingNeuralNetwork` when Python parser implementations are needed.

#### Methods

##### init

```python
def __init__(*args, **kwargs):
```

Initialize the wrapper and create the internal neural-network node.

##### build

```python
def build(input: dai.Node.Output | dai.node.Camera, nnSource: dai.NNModelDescription | dai.NNArchive | str, fps: float | None = None) -> ParsingNeuralNetwork:
```

Build the neural-network node and create parser nodes for each head.

Parameters

 * `input` (`dai.Node.Output | dai.node.Camera`): Upstream output or camera feeding frames into the neural-network node.
 * `nnSource` (`dai.NNModelDescription | dai.NNArchive | str`): dai.NNModelDescription, dai.NNArchive, or HubAI model slug.
 * `fps` (`float | None`): Optional runtime FPS limit for the neural-network node.

Returns

 * `ParsingNeuralNetwork`: The configured node instance.

Raises

 * `ValueError`: If `nnSource` is not an archive, model description, or Model Zoo slug, or its parser configuration is invalid.

##### cleanup

```python
def cleanup(self):
```

Cleans up the ParsingNeuralNetwork node and removes all nodes created by ParsingNeuralNetwork from the pipeline.

Must be called before removing the node from the pipeline.

##### getNumInferenceThreads

```python
def getNumInferenceThreads(self) -> int:
```

Return the configured number of inference threads.

##### getOutput

```python
def getOutput(head: int) -> dai.Node.Output:
```

Select an individual model-head output.

Parameters

 * `head` (`int`): Zero-based head index from the archive.

Returns

 * `dai.Node.Output`: Parser output for the selected head.

Raises

 * `KeyError`: If the head is not available.

##### getParser

```python
def getParser(*args, **kwargs) -> BaseParser | dai.DeviceNode:
```

Return the parser for the requested model head.

Parameters

 * `*args`: Either a head index, a parser type, or a parser type and head index.
 * `parserType`: Optional expected parser type used for runtime type checking.
 * `index`: Model head index. Defaults to 0.
 * `**kwargs`: Optional `parserType` and `index` keyword arguments.

Returns

 * `BaseParser | dai.DeviceNode`: Parser node matching the requested head.

Raises

 * `KeyError`: If the model-head index is unavailable.
 * `TypeError`: If the parser does not match the requested parser type.

##### run

```python
def run(self):
```

Methods inherited from ThreadedHostNode.

Method runs with start of the pipeline.

##### setBackend

```python
def setBackend(setBackend: str):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `setBackend` (`str`): Backend identifier accepted by DepthAI.

##### setBackendProperties

```python
def setBackendProperties(setBackendProperties: dict[str, str]):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `setBackendProperties` (`dict[str, str]`): Backend-specific string properties.

##### setBlob

```python
def setBlob(blob: Path | dai.OpenVINO.Blob):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `blob` (`Path | dai.OpenVINO.Blob`): OpenVINO blob or path accepted by DepthAI.

##### setBlobPath

```python
def setBlobPath(path: Path):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `path` (`Path`): Local OpenVINO blob path.

##### setFromModelZoo

```python
def setFromModelZoo(description: dai.NNModelDescription, useCached: bool):
```

Load a model into the native network without rebuilding parsers.

Parameters

 * `description` (`dai.NNModelDescription`): Model Zoo description passed to DepthAI.
 * `useCached` (`bool`): Whether DepthAI may reuse a cached model.

##### setModelPath

```python
def setModelPath(modelPath: Path):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `modelPath` (`Path`): Local model path accepted by the native node.

##### setNNArchive

```python
def setNNArchive(nnArchive: dai.NNArchive, numShaves: int | None = None):
```

Set the active model archive and rebuild parser nodes.

Parameters

 * `nnArchive` (`dai.NNArchive`): Neural-network archive containing the model and parser config.
 * `numShaves` (`int | None`): Optional number of shaves allocated to the neural-network node.

##### setNumInferenceThreads

```python
def setNumInferenceThreads(numThreads: int):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `numThreads` (`int`): Requested number of parallel inference threads.

##### setNumNCEPerInferenceThread

```python
def setNumNCEPerInferenceThread(numNCEPerThread: int):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `numNCEPerThread` (`int`): Number of neural compute engines allocated per inference thread.

##### setNumPoolFrames

```python
def setNumPoolFrames(numFrames: int):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `numFrames` (`int`): Number of frames in the network output pool.

##### setNumShavesPerInferenceThread

```python
def setNumShavesPerInferenceThread(numShavesPerInferenceThread: int):
```

Forward configuration to the underlying native NeuralNetwork node.

> **Note**
> Backend and platform validation is performed by DepthAI. This forwarding method does not rebuild parser nodes.

Parameters

 * `numShavesPerInferenceThread` (`int`): Number of SHAVE cores allocated per inference thread.

#### Attributes

##### input

Return the primary neural-network input.

##### inputs

Return the neural-network input map.

##### out

Return the single parser output when the model has exactly one head.

##### outputs

Neural network output having dai.MessageGroup as a payload which contains outputs of all model heads and can be accessed as a
dictionary with str(model head index) as a key.

Can be used only when there are at least two model heads. Otherwise, out property must be used.

##### passthrough

Return the primary passthrough stream from the underlying NN node.

##### passthroughs

Return the passthrough output map from the underlying NN node.

## Attributes

### TParser
