# classification

Python API: `depthai_nodes.message.creators.classification`

## Functions

| Name | Description |
| --- | --- |
| [`create_classification_message`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/creators/classification.md#classification-Functions-create_classification_message) | Create a classification message sorted by descending score. |
| [`create_classification_sequence_message`](https://docs.luxonis.com/software-v3/ai-inference/inference/depthai-nodes/depthai-nodes-api-reference/message/creators/classification.md#classification-Functions-create_classification_sequence_message) | Create a classification sequence from per-position class probabilities. |

### function `create_classification_message`

```python
def create_classification_message(
    classes: list[str],
    scores: np.ndarray | list,
) -> dai.beta.Classifications
```

Create a classification message sorted by descending score.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `classes` | `list[str]` | Non-empty list of class names. | required |
| `scores` | `np.ndarray | list` | Floating-point probabilities corresponding to `classes`. Values must be between 0 and 1 and sum to 1 within an absolute tolerance of 0.1. A list or array that can be flattened to one probability per class is accepted. | required |

Returns

| Type | Description |
| --- | --- |
| `dai.beta.Classifications` | Native classification message containing sorted class names and scores. Classes with equal scores retain their input order. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If classes or scores are empty, have unsupported types, differ in length, or scores are not valid floating-point probabilities. |

### function `create_classification_sequence_message`

```python
def create_classification_sequence_message(
    classes: list[str],
    scores: np.ndarray | list,
    ignored_indexes: list[int] | None = None,
    remove_duplicates: bool = False,
    concatenate_classes: bool = False,
) -> dai.beta.Classifications
```

Create a classification sequence from per-position class probabilities.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `classes` | `list[str]` | Class names, indexed by the columns of `scores`. | required |
| `scores` | `np.ndarray | list` | Array or nested list of shape `(sequence_length, n_classes)`. Each row must contain probabilities between 0 and 1 that sum to 1 within an absolute tolerance of 0.01. | required |
| `ignored_indexes` | `list[int] | None` | Class indexes to omit, such as a padding or background class. | `None` |
| `remove_duplicates` | `bool` | Remove adjacent repeated winning classes before filtering ignored indexes. | `False` |
| `concatenate_classes` | `bool` | If all selected class names have at most one character, join them into words separated by spaces and average the scores within each word. | `False` |

Returns

| Type | Description |
| --- | --- |
| `dai.beta.Classifications` | Native classification message with selected class names and scores in sequence order. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If classes are not a list, scores have incompatible dimensions or invalid probabilities, or ignored indexes are not a list of valid integer class indexes. |
