# task_utils

Python API: `luxonis_ml.data.utils.task_utils`

## Functions

| Name | Description |
| --- | --- |
|
[`get_task_name`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/utils/task_utils.md)
| Return the task name from a task string. |
|
[`get_task_type`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/utils/task_utils.md)
| Return the task type from a task string. |
|
[`split_task`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/utils/task_utils.md)
| Split a task into task name and task type. |
|
[`task_is_metadata`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/utils/task_utils.md)
| Check whether a task is a metadata task. |
|
[`task_type_iterator`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/data/utils/task_utils.md)
| Iterate over labels of a specific task type. |

### function `get_task_name`

```python
def get_task_name(task: str) -> str
```

Return the task name from a task string.

> **Examples**
> ```pycon
>>> get_task_name("detector/boundingbox")
'detector'
>>> get_task_name("classification")
'classification'
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `task` | `str` | Task string. | required |

Returns

| Type | Description |
| --- | --- |
| `str` | Task name. |

### function `get_task_type`

```python
def get_task_type(task: str) -> str
```

Return the task type from a task string.

> **Example**
> ```pycon
>>> get_task_type("task_name/type")
'type'
>>> get_task_type("metadata/name")
'metadata/name'
>>> get_task_type("task_name/metadata/name")
'metadata/name'
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `task` | `str` | Task string, such as `"task_name/type"`. | required |

Returns

| Type | Description |
| --- | --- |
| `str` | Task type. Metadata tasks are returned as `"metadata/type"`. |

### function `split_task`

```python
def split_task(task: str) -> tuple[str, str]
```

Split a task into task name and task type.

> **Examples**
> ```pycon
>>> split_task("detector/boundingbox")
('detector', 'boundingbox')
>>> split_task("classification")
('', 'classification')
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `task` | `str` | Task to split. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[str, str]` | Task name and task type. |

### function `task_is_metadata`

```python
def task_is_metadata(task: str) -> bool
```

Check whether a task is a metadata task.

> **Examples**
> ```pycon
>>> task_is_metadata("metadata/weather")
True
>>> task_is_metadata("camera/metadata/weather")
True
>>> task_is_metadata("camera/boundingbox")
False
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `task` | `str` | Task to check. | required |

Returns

| Type | Description |
| --- | --- |
| `bool` | Whether the task is a metadata task. |

### function `task_type_iterator`

```python
def task_type_iterator(
    labels: Labels,
    task_type: TaskType,
) -> Iterator[tuple[str, np.ndarray]]
```

Iterate over labels of a specific task type.

> **Examples**
> ```pycon
>>> labels = {
...     "detector/boundingbox": np.array([1]),
...     "pose/keypoints": np.array([2]),
... }
>>> [
...     (task, arr.tolist())
...     for task, arr in task_type_iterator(labels, "keypoints")
... ]
[('pose/keypoints', [2])]
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `labels` | `Labels` | Labels to iterate over. | required |
| `task_type` | `TaskType` | Label type to yield. | required |

Returns

| Type | Description |
| --- | --- |
| `Iterator[tuple[str, np.ndarray]]` | Iterator over matching labels. |
