# rf_detr

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

## Classes

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

### class `RFDETRParser`

```python
class RFDETRParser(BaseParser)
```

Parser class for parsing the output of the RF-DETR object detection model.

RF-DETR from Roboflow is a detection transformer model that outputs bounding boxes and class probabilities. The model can
optionally output instance segmentation masks.

> **Note**
> Emits `dai.ImgDetections` messages. dai.ImgDetections message containing bounding boxes, labels, confidence scores, and optionally instance segmentation masks.

References:

RF-DETR: [https://github.com/roboflow/rf-detr](https://github.com/roboflow/rf-detr)

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `conf_threshold` |  | Confidence score threshold for detected objects. |
| `input_shape` | `tuple[int, int] | None` |  |
| `label_names` |  | List of label names for detected objects. |
| `mask_conf` |  | Confidence threshold for binarizing instance segmentation masks. |
| `max_det` |  | Maximum number of detections to keep. |
| `output_layer_names` | `list[str]` | Names of the output layers (boxes, logits, and optionally masks). |

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`input`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-input) | `dai.Node.Input` | Input port accepting `dai.NNData`. |
| [`out`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-out) | `dai.Node.Output` | Output port carrying parsed messages. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-__init__) | Initializes the parser node. |
| [`build`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-build) | Configures the parser based on the head configuration. |
| [`compute`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-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/rf_detr.md#rf_detr-Classes-RFDETRParser-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/rf_detr.md#rf_detr-Classes-RFDETRParser-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/rf_detr.md#rf_detr-Classes-RFDETRParser-run) | Read queued network outputs, parse them, and emit results while running. |
| [`setConfidenceThreshold`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-setConfidenceThreshold) | Sets the confidence score threshold for detected objects. |
| [`setLabelNames`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-setLabelNames) | Sets the label names for detected objects. |
| [`setMaskConfidence`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-setMaskConfidence) | Sets the mask confidence threshold. |
| [`setMaxDetections`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-setMaxDetections) | Sets the maximum number of detections to keep. |
| [`setOutputLayerNames`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/node/parsers/rf_detr.md#rf_detr-Classes-RFDETRParser-setOutputLayerNames) | Sets the output layer names for the parser. |

#### property `input`

```python
input: dai.Node.Input
```

Input port accepting `dai.NNData`.

#### property `out`

```python
out: dai.Node.Output
```

Output port carrying parsed messages.

#### method `__init__`

```python
def __init__(
    conf_threshold: float = 0.5,
    max_det: int = 300,
    label_names: list[str] | None = None,
    mask_conf: float = 0.5,
)
```

Initializes the parser node.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `conf_threshold` | `float` | Confidence score threshold for detected objects. | `0.5` |
| `max_det` | `int` | Maximum number of detections to keep. | `300` |
| `label_names` | `list[str] | None` | List of label names for detected objects. | `None` |
| `mask_conf` | `float` | Mask confidence threshold for instance segmentation masks. | `0.5` |

#### method `build`

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

Configures the parser based on the head configuration.

Args

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

Returns

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

#### method `compute`

```python
def compute(
    boxes_tensor: np.ndarray,
    logits_tensor: np.ndarray,
    *,
    conf_threshold: float,
    max_det: int,
    label_names: list[str] | None,
    mask_conf: float,
    input_shape: tuple[int, int] | None,
    masks_tensor: np.ndarray | None = None,
) -> tuple[np.ndarray, np.ndarray, np.ndarray, list[str] | None, np.ndarray | None]
```

Compute parser results from extracted tensors without sending messages.

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

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `boxes_tensor` | `np.ndarray` | Batched normalized center-XY/width/height predictions. | required |
| `logits_tensor` | `np.ndarray` | Class logits of shape `(1, queries, classes)`. | required |
| `conf_threshold` | `float` | Minimum detection confidence used to filter candidates. | required |
| `max_det` | `int` | Maximum number of detection candidates to retain or consider during suppression. | required |
| `label_names` | `list[str] | None` | Optional class-name lookup indexed by predicted class ID. | required |
| `mask_conf` | `float` | Probability threshold used to binarize mask logits. | required |
| `input_shape` | `tuple[int, int] | None` | Model input image shape as `(height, width)`. | required |
| `masks_tensor` | `np.ndarray | None` | Optional per-query mask logits, ordered like the box predictions. | `None` |

Returns

| Type | Description |
| --- | --- |
| `tuple[np.ndarray, np.ndarray, np.ndarray, list[str] | None, np.ndarray | None]` | Boxes in normalized center-XY/width/height format, scores, integer class IDs, optional class names, and an optional HW uint8 instance mask. Mask values index returned detections; 255 is background. Segmentation retains at most 255 instances, and higher-confidence masks win overlaps. |

#### method `emit`

```python
def emit(
    output: dai.NNData,
    boxes: np.ndarray,
    scores: np.ndarray,
    labels: np.ndarray,
    label_names_list: list[str] | None,
    final_mask: np.ndarray | 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 |
| `boxes` | `np.ndarray` | Normalized center-XY/width/height boxes returned by `compute()`. | required |
| `scores` | `np.ndarray` | Confidence scores corresponding to the computed payload. | required |
| `labels` | `np.ndarray` | Integer class IDs corresponding to the boxes. | required |
| `label_names_list` | `list[str] | None` | Optional class names corresponding to the detections. | required |
| `final_mask` | `np.ndarray | None` | Optional instance mask whose IDs index the returned detections; 255 is background. | required |

#### method `extract`

```python
def extract(output: dai.NNData) -> tuple[np.ndarray, np.ndarray, np.ndarray | None]
```

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[np.ndarray, np.ndarray, np.ndarray | None]` | Float32 box, class-logit, and optional mask tensors in configured layer order. Without a mask layer, the third value is `None`. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the selected outputs do not contain two or three layers. |

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

```python
def setConfidenceThreshold(threshold: float)
```

Sets the confidence score threshold for detected objects.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `threshold` | `float` | Confidence score threshold for detected objects. | required |

#### method `setLabelNames`

```python
def setLabelNames(label_names: list[str])
```

Sets the label names for detected objects.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `label_names` | `list[str]` | List of label names for detected objects. | required |

#### method `setMaskConfidence`

```python
def setMaskConfidence(mask_conf: float)
```

Sets the mask confidence threshold.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `mask_conf` | `float` | The mask confidence threshold. | required |

#### method `setMaxDetections`

```python
def setMaxDetections(max_det: int)
```

Sets the maximum number of detections to keep.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `max_det` | `int` | Maximum number of detections to keep. | required |

#### method `setOutputLayerNames`

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

Sets the output layer names for the parser.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `output_layer_names` | `list[str]` | List of output layer names. | required |
