# task_utils

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

## 函数

### get_task_name

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

从任务字符串中返回任务名称。

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

参数

 * `task` (`str`): 任务字符串。

返回

 * `str`: 任务名称。

### get_task_type

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

从任务字符串中返回任务类型。

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

参数

 * `task` (`str`): 任务字符串，例如 `"task_name/type"`。

返回

 * `str`: 任务类型。元数据任务返回为 `"metadata/type"`。

### split_task

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

将任务拆分为任务名称和任务类型。

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

参数

 * `task` (`str`): 要拆分的任务。

返回

 * `tuple[str, str]`: 任务名称和任务类型。

### task_is_metadata

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

检查任务是否为元数据任务。

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

参数

 * `task` (`str`): 要检查的任务。

返回

 * `bool`: 任务是否为元数据任务。

### task_type_iterator

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

迭代特定任务类型的标签。

> **示例**
> ```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])]
```

参数

 * `labels` (`Labels`): 要迭代的标签。
 * `task_type` (`TaskType`): 要生成的标签类型。

返回

 * `Iterator[tuple[str, np.ndarray]]`: 匹配标签的迭代器。
