# scrfd

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

## Classes

| Name | Description |
| --- | --- |
| [`SCRFDParser`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser) | Parser class for parsing the output of the SCRFD face detection model. |

### class `SCRFDParser`

```python
class SCRFDParser(DetectionParser)
```

Parser class for parsing the output of the SCRFD face detection model.

> **Note**
> Emits `dai.ImgDetections` messages. dai.ImgDetections message containing bounding boxes, labels, and confidence scores of detected faces.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `conf_threshold` |  | Confidence score threshold for detected faces. |
| `feat_stride_fpn` |  | Tuple of the feature strides. |
| `input_size` |  | Input size of the model. |
| `iou_threshold` |  | Non-maximum suppression threshold. |
| `label_names` | `list[str]` |  |
| `max_det` |  | Maximum number of detections to keep. |
| `num_anchors` |  | Number of anchors. |
| `output_layer_name` |  | Names of the output layers relevant to the parser. |
| `output_layer_names` |  |  |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-build) | Configures the parser. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-compute) | Decode SCRFD arrays without sending a message. |
| [`emit`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-emit) | Create a `dai.ImgDetections` message and send it on `out`. |
| [`extract`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-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/scrfd.md#scrfd-Classes-SCRFDParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setFeatStrideFPN`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-setFeatStrideFPN) | Sets the feature stride of the FPN. |
| [`setInputSize`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-setInputSize) | Sets the input size of the model. |
| [`setNumAnchors`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-setNumAnchors) | Sets the number of anchors. |
| [`setOutputLayerNames`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/scrfd.md#scrfd-Classes-SCRFDParser-setOutputLayerNames) | Sets the output layer name(s) for the parser. |

#### method `__init__`

```python
def __init__(
    output_layer_names: list[str] = None,
    conf_threshold: float = 0.5,
    iou_threshold: float = 0.5,
    max_det: int = 100,
    input_size: tuple[int, int] = (640, 640),
    feat_stride_fpn: tuple = (8, 16, 32),
    num_anchors: int = 2,
)
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_names` | `list[str]` | Names of the output layers relevant to the parser. | `None` |
| `conf_threshold` | `float` | Confidence score threshold for detected faces. | `0.5` |
| `iou_threshold` | `float` | Non-maximum suppression threshold. | `0.5` |
| `max_det` | `int` | Maximum number of detections to keep. | `100` |
| `input_size` | `tuple[int, int]` | Input size of the model. | `(640, 640)` |
| `feat_stride_fpn` | `tuple` | List of the feature strides. | `(8, 16, 32)` |
| `num_anchors` | `int` | Number of anchors. | `2` |

#### method `build`

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

Configures the parser.

Args

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

Returns

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

#### static method `compute`

```python
def compute(**kwargs)
```

Decode SCRFD arrays without sending a message.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `**kwargs` |  | Keyword arguments accepted by [depthai_nodes.node.parsers.utils.scrfd.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). |  |

Returns

| Type | Description |
| --- | --- |
|  | Normalized center-XY/width/height boxes, scores, keypoints, zero-valued face class IDs, and optional mapped class names. |

#### method `emit`

```python
def emit(
    output: dai.NNData,
    bboxes: np.ndarray,
    scores: np.ndarray,
    keypoints: np.ndarray,
    labels: np.ndarray,
    label_names: list[str] | None,
)
```

Create a `dai.ImgDetections` 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 |
| `bboxes` | `np.ndarray` | Normalized center-XY/width/height boxes returned by `compute()`. | required |
| `scores` | `np.ndarray` | Confidence scores corresponding to the computed payload. | required |
| `keypoints` | `np.ndarray` | Normalized keypoint coordinates returned by `compute()`. | required |
| `labels` | `np.ndarray` | Integer class IDs corresponding to the boxes. | required |
| `label_names` | `list[str] | None` | Optional class names corresponding to the detections. | required |

#### method `extract`

```python
def extract(
    output: dai.NNData,
) -> tuple[list[np.ndarray], list[np.ndarray], list[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 |
| --- | --- |
| `tuple[list[np.ndarray], list[np.ndarray], list[np.ndarray]]` | Lists of box, score, and keypoint tensors in configured stride order, shaped `(N, 4)`, `(N,)`, and `(N, 10)` per stride. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If a configured stride has no score, box, or keypoint layer. |

#### 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 `setFeatStrideFPN`

```python
def setFeatStrideFPN(feat_stride_fpn: list[int])
```

Sets the feature stride of the FPN.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `feat_stride_fpn` | `list[int]` | Feature stride of the FPN. | required |

#### method `setInputSize`

```python
def setInputSize(input_size: tuple[int, int])
```

Sets the input size of the model.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `input_size` | `tuple[int, int]` | Input size of the model. | required |

#### method `setNumAnchors`

```python
def setNumAnchors(num_anchors: int)
```

Sets the number of anchors.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `num_anchors` | `int` | Number of anchors. | required |

#### method `setOutputLayerNames`

```python
def setOutputLayerNames(output_layer_names: list[str])
```

Sets the output layer name(s) for the parser.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_names` | `list[str]` | The name of the output layer(s) to be used. | required |
