# regression

Python API: `depthai_nodes.node.parsers.regression`

## Classes

| Name | Description |
| --- | --- |
| [`RegressionParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/regression.md#regression-Classes-RegressionParser) | Parser class for parsing the output of a model with regression output (e.g. Age- Gender). |

### class `RegressionParser`

```python
class RegressionParser(BaseParser)
```

Parser class for parsing the output of a model with regression output (e.g. Age- Gender).

> **Note**
> Emits `dai.beta.Predictions` messages. Message containing the prediction(s).

Attributes

| Name | Description |
| --- | --- |
| `output_layer_name` | Name of the output layer relevant to the parser. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/regression.md#regression-Classes-RegressionParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/regression.md#regression-Classes-RegressionParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/regression.md#regression-Classes-RegressionParser-compute) | Compute parser results from extracted tensors without sending messages. |
| [`emit`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/regression.md#regression-Classes-RegressionParser-emit) | Create a `dai.beta.Predictions` message and send it on `out`. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/regression.md#regression-Classes-RegressionParser-extract) | Select and dequantize the model tensors needed for parsing. |
| [`run`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/regression.md#regression-Classes-RegressionParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setOutputLayerName`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/regression.md#regression-Classes-RegressionParser-setOutputLayerName) | Sets the name of the output layer. |

#### method `__init__`

```python
def __init__(output_layer_name: str = '')
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_name` | `str` | Name of the output layer relevant to the parser. | `''` |

#### method `build`

```python
def build(head_config: dict[str, Any]) -> RegressionParser
```

Configures the parser.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `head_config` | `dict[str, Any]` | The head configuration for the parser. | required |

Returns

| Type | Description |
| --- | --- |
| `RegressionParser` | The parser object with the head configuration set. |

#### static method `compute`

```python
def compute(predictions: np.ndarray) -> list[float]
```

Compute parser results from extracted tensors without sending messages.

> **Note**
> Uses [depthai_nodes.node.parsers.utils.regression.compute_regression_predictions](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/regression.md#regression-Functions-compute_regression_predictions); see that helper for tensor layout and validation details.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `predictions` | `np.ndarray` | Model prediction tensor. | required |

Returns

| Type | Description |
| --- | --- |
| `list[float]` | A Python list obtained after squeezing singleton dimensions. Scalar predictions become a one-item list; remaining non-singleton dimensions produce nested lists. |

#### method `emit`

```python
def emit(output: dai.NNData, predictions: list[float])
```

Create a `dai.beta.Predictions` message and send it on `out`.

Copies source timestamps and sequence number, and carries the source image transformation when present.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |
| `predictions` | `list[float]` | Regression values returned by `compute()`. | required |

#### method `extract`

```python
def extract(output: dai.NNData) -> np.ndarray
```

Select and dequantize the model tensors needed for parsing.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output` | `dai.NNData` | Neural network output carrying tensors and source timestamps, sequence number, and optional image transformation. | required |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Dequantized regression tensor. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If no output name is configured and the message does not contain exactly one layer, or configured class requirements are not met. |

#### method `run`

```python
def run()
```

Read queued network outputs, parse them, and emit results while running.

The pipeline invokes this processing loop. It exits when the input queue closes or the node stops.

#### method `setOutputLayerName`

```python
def setOutputLayerName(output_layer_name: str)
```

Sets the name of the output layer.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_name` | `str` | Name of the output layer relevant to the parser. | required |
