# scrfd

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

## Classes

### SCRFDParser

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.

#### Methods

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

Parameters

 * `output_layer_names` (`list[str]`): Names of the output layers relevant to the parser.
 * `conf_threshold` (`float`): Confidence score threshold for detected faces.
 * `iou_threshold` (`float`): Non-maximum suppression threshold.
 * `max_det` (`int`): Maximum number of detections to keep.
 * `input_size` (`tuple[int, int]`): Input size of the model.
 * `feat_stride_fpn` (`tuple`): List of the feature strides.
 * `num_anchors` (`int`): Number of anchors.

##### build

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

Configures the parser.

Parameters

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

Returns

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

##### compute

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

Decode SCRFD arrays without sending a message.

Parameters

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

Returns

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

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

Parameters

 * `output` (`dai.NNData`): Neural network output carrying tensors and source timestamps, sequence number, and optional image
   transformation.
 * `bboxes` (`np.ndarray`): Normalized center-XY/width/height boxes returned by `compute()`.
 * `scores` (`np.ndarray`): Confidence scores corresponding to the computed payload.
 * `keypoints` (`np.ndarray`): Normalized keypoint coordinates returned by `compute()`.
 * `labels` (`np.ndarray`): Integer class IDs corresponding to the boxes.
 * `label_names` (`list[str] | None`): Optional class names corresponding to the detections.

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

Parameters

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

Returns

 * `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

 * `ValueError`: If a configured stride has no score, box, or keypoint layer.

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

##### setFeatStrideFPN

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

Sets the feature stride of the FPN.

Parameters

 * `feat_stride_fpn` (`list[int]`): Feature stride of the FPN.

##### setInputSize

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

Sets the input size of the model.

Parameters

 * `input_size` (`tuple[int, int]`): Input size of the model.

##### setNumAnchors

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

Sets the number of anchors.

Parameters

 * `num_anchors` (`int`): Number of anchors.

##### setOutputLayerNames

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

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

Parameters

 * `output_layer_names` (`list[str]`): The name of the output layer(s) to be used.

#### Attributes

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

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