# regression

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

## Classes

### RegressionParser

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).

#### Methods

##### init

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

Initializes the parser node.

Parameters

 * `output_layer_name` (`str`): Name of the output layer relevant to the parser.

##### build

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

Configures the parser.

Parameters

 * `head_config` (`dict[str, Any]`): The head configuration for the parser.

Returns

 * `RegressionParser`: The parser object with the head configuration set.

##### 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); see that helper for tensor layout and validation details.

Parameters

 * `predictions` (`np.ndarray`): Model prediction tensor.

Returns

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

##### 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.

Parameters

 * `output` (`dai.NNData`): Neural network output carrying tensors and source timestamps, sequence number, and optional image
   transformation.
 * `predictions` (`list[float]`): Regression values returned by `compute()`.

##### extract

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

Select and dequantize the model tensors needed for parsing.

Parameters

 * `output` (`dai.NNData`): Neural network output carrying tensors and source timestamps, sequence number, and optional image
   transformation.

Returns

 * `np.ndarray`: Dequantized regression tensor.

Raises

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

##### run

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

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.

##### setOutputLayerName

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

Sets the name of the output layer.

Parameters

 * `output_layer_name` (`str`): Name of the output layer relevant to the parser.

#### Attributes

##### output_layer_name

Name of the output layer relevant to the parser.
