# scrfd

Python API: `depthai_nodes.node.parsers.utils.scrfd`

## Functions

| Name | Description |
| --- | --- |
| [`compute_anchor_centers`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/scrfd.md#scrfd-Functions-compute_anchor_centers) | Compute the anchor centers for a given list of strides, input size, and number of anchors. |
| [`compute_scrfd_detections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/scrfd.md#scrfd-Functions-compute_scrfd_detections) | Decode SCRFD heads into normalized face detections. |
| [`decode_scrfd`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/scrfd.md#scrfd-Functions-decode_scrfd) | Decode the detection results of SCRFD. |
| [`distance2bbox`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/scrfd.md#scrfd-Functions-distance2bbox) | Decode distance prediction to bounding box. |
| [`distance2kps`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/utils/scrfd.md#scrfd-Functions-distance2kps) | Decode distance prediction to keypoints. |

### function `compute_anchor_centers`

```python
def compute_anchor_centers(
    strides: list[int],
    input_size: tuple[int, int],
    num_anchors: int,
) -> dict[int, np.ndarray]
```

Compute the anchor centers for a given list of strides, input size, and number of anchors.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `strides` | `list[int]` | List of strides. | required |
| `input_size` | `tuple[int, int]` | Input size. | required |
| `num_anchors` | `int` | Number of anchors. | required |

Returns

| Type | Description |
| --- | --- |
| `dict[int, np.ndarray]` | Dictionary of anchor centers. |

### function `compute_scrfd_detections`

```python
def compute_scrfd_detections(
    *,
    bboxes_concatenated: list[np.ndarray],
    scores_concatenated: list[np.ndarray],
    kps_concatenated: list[np.ndarray],
    feat_stride_fpn: tuple[int, ...] | list[int],
    input_size: tuple[int, int],
    num_anchors: int,
    score_threshold: float,
    nms_threshold: float,
    anchors: dict[int, np.ndarray],
    label_names: list[str] | None = None,
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]
```

Decode SCRFD heads into normalized face detections.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `bboxes_concatenated` | `list[np.ndarray]` | Box-distance tensors ordered by feature-pyramid stride. | required |
| `scores_concatenated` | `list[np.ndarray]` | Confidence tensors ordered by feature-pyramid stride. | required |
| `kps_concatenated` | `list[np.ndarray]` | Keypoint-offset tensors ordered by feature-pyramid stride. | required |
| `feat_stride_fpn` | `tuple[int, ...] | list[int]` | Feature-pyramid strides corresponding to the tensor lists. | required |
| `input_size` | `tuple[int, int]` | Model input size as `(width, height)`. | required |
| `num_anchors` | `int` | Number of anchors per feature-map location. | required |
| `score_threshold` | `float` | Minimum face confidence. | required |
| `nms_threshold` | `float` | Intersection-over-union threshold for suppression. | required |
| `anchors` | `dict[int, np.ndarray]` | Mapping from each feature stride to its precomputed anchor centers. | required |
| `label_names` | `list[str] | None` | Optional class-name lookup indexed by predicted class ID. | `None` |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, list[str] | None]` | Normalized center-XY/width/height boxes, scores, keypoints, zero-valued face class IDs, and optional mapped class names. |

### function `decode_scrfd`

```python
def decode_scrfd(
    bboxes_concatenated,
    scores_concatenated,
    kps_concatenated,
    feat_stride_fpn,
    input_size,
    num_anchors,
    score_threshold,
    nms_threshold,
    anchors,
)
```

Decode the detection results of SCRFD.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `bboxes_concatenated` | `list[np.ndarray]` | List of bounding box predictions for each scale. | required |
| `scores_concatenated` | `list[np.ndarray]` | List of confidence score predictions for each scale. | required |
| `kps_concatenated` | `list[np.ndarray]` | List of keypoint predictions for each scale. | required |
| `feat_stride_fpn` | `list[int]` | List of feature strides for each scale. | required |
| `input_size` | `tuple[int]` | Input size of the model. | required |
| `num_anchors` | `int` | Number of anchors. | required |
| `score_threshold` | `float` | Confidence score threshold. | required |
| `nms_threshold` | `float` | Non-maximum suppression threshold. | required |
| `anchors` | `dict[int, np.ndarray]` | Dictionary of anchors. | required |

Returns

 * `tuple[np.ndarray, np.ndarray, np.ndarray]`: * `Bounding boxes, confidence`: scores, and keypoints of detected objects.

### function `distance2bbox`

```python
def distance2bbox(points, distance, max_shape=None)
```

Decode distance prediction to bounding box.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `points` | `np.ndarray` | Shape (n, 2), [x, y]. | required |
| `distance` | `np.ndarray` | Distance from the given point to 4 boundaries (left, top, right, bottom). | required |
| `max_shape` | `tuple[int, int]` | Shape of the image. | `None` |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Decoded bboxes. |

### function `distance2kps`

```python
def distance2kps(points, distance, max_shape=None)
```

Decode distance prediction to keypoints.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `points` | `np.ndarray` | Shape (n, 2), [x, y]. | required |
| `distance` | `np.ndarray` | Distance from the given point to 4 boundaries (left, top, right, bottom). | required |
| `max_shape` | `tuple[int, int]` | Shape of the image. | `None` |

Returns

| Type | Description |
| --- | --- |
| `np.ndarray` | Decoded keypoints. |
