# hrnet

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

## Classes

| Name | Description |
| --- | --- |
| [`HRNetParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/hrnet.md#hrnet-Classes-HRNetParser) | Parser class for parsing the output of the HRNet pose estimation model. The code is inspired by [https://github.com/ibaiGorordo/ONNX-HRNET-Human-Pose-Estimation](https://github.com/ibaiGorordo/ONNX-HRNET-Human-Pose-Estimation). |

### class `HRNetParser`

```python
class HRNetParser(KeypointParser)
```

Parser class for parsing the output of the HRNet pose estimation model. The code is inspired by
[https://github.com/ibaiGorordo/ONNX-HRNET-Human-Pose-Estimation](https://github.com/ibaiGorordo/ONNX-HRNET-Human-Pose-Estimation).

> **Note**
> Emits `dai.beta.Keypoints` messages. Output containing detected body keypoints.

Attributes

| Name | Description |
| --- | --- |
| `edges` | Pairs of keypoint indexes defining skeleton edges. For example, `[(0, 1), (1, 2)]` connects keypoint 0 to 1 and 1 to 2. |
| `label_names` | Label names for the keypoints. |
| `output_layer_name` | Name of the output layer relevant to the parser. |
| `score_threshold` | Confidence score threshold for detected keypoints. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/hrnet.md#hrnet-Classes-HRNetParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/hrnet.md#hrnet-Classes-HRNetParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/hrnet.md#hrnet-Classes-HRNetParser-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/hrnet.md#hrnet-Classes-HRNetParser-emit) | Create a `dai.beta.Keypoints` message and send it on `out`. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/hrnet.md#hrnet-Classes-HRNetParser-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/hrnet.md#hrnet-Classes-HRNetParser-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/hrnet.md#hrnet-Classes-HRNetParser-setOutputLayerName) | Sets the name of the output layer. |

#### method `__init__`

```python
def __init__(
    output_layer_name: str = '',
    score_threshold: float = 0.5,
    label_names: list[str] | None = None,
    edges: list[tuple[int, int]] | None = None,
)
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_name` | `str` | Name of the output layer relevant to the parser. | `''` |
| `score_threshold` | `float` | Confidence score threshold for detected keypoints. | `0.5` |
| `label_names` | `list[str] | None` | Label names for the keypoints. | `None` |
| `edges` | `list[tuple[int, int]] | None` | Pairs of keypoint indexes defining skeleton edges. For example, `[(0, 1), (1, 2)]` connects keypoint 0 to 1 and 1 to 2. | `None` |

#### method `build`

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

Configures the parser.

Args

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

Returns

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

#### static method `compute`

```python
def compute(heatmaps: np.ndarray) -> tuple[np.ndarray, np.ndarray]
```

Compute parser results from extracted tensors without sending messages.

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

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `heatmaps` | `np.ndarray` | Heatmaps of shape `(1, keypoints, height, width)` or `(keypoints, height, width)`. The first axis is removed when its size is 1. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray]` | A pair of normalized `(N, 2)` XY coordinates and `(N,)` peak scores clipped to [0, 1]. |

#### method `emit`

```python
def emit(output: dai.NNData, keypoints: np.ndarray, scores: np.ndarray)
```

Create a `dai.beta.Keypoints` 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 |
| `keypoints` | `np.ndarray` | Normalized keypoint coordinates returned by `compute()`. | required |
| `scores` | `np.ndarray` | Confidence scores corresponding to the computed payload. | 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 heatmaps requested in NCHW storage order. |

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` | The name of the output layer. | required |
