# typing

Python API: `luxonis_ml.typing`

Common type aliases and utility functions for type checking.

## Classes

| Name | Description |
| --- | --- |
|
[`BaseModelExtraForbid`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
| Base model with extra fields forbidden. |
|
[`ConfigItem`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
| Configuration schema for dynamic object instantiation. Typically used to instantiate objects stored in registries. |
|
[`LoaderOutput`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
| Images, labels, and record metadata returned by dataset loaders. |
|
[`TrackedAugmentations`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
| Augmentation provenance generated by a loader. |

### class `BaseModelExtraForbid`

```python
class BaseModelExtraForbid(BaseModel)
```

Base model with extra fields forbidden.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `model_config` | `ConfigDict` | Pydantic model configuration with `extra` set to `"forbid"`. |

### class `ConfigItem`

```python
class ConfigItem(BaseModelExtraForbid)
```

Configuration schema for dynamic object instantiation. Typically used to instantiate objects stored in registries.

A dictionary with a name and a dictionary of parameters.

> **Example**
> ```pycon
>>> ConfigItem(name="Resize", params={"height": 256}).name
'Resize'
>>> ConfigItem(name="Normalize").params
{}
```

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `name` | `str` | Name of the object this configuration applies to. |
| `params` | `Params` | Additional parameters for instantiating the object. |

### class `LoaderOutput`

```python
class LoaderOutput(
    tuple[np.ndarray | dict[str, 'np.ndarray'], Labels] if TYPE_CHECKING else object,
)
```

Images, labels, and record metadata returned by dataset loaders.

Prefer attribute access for new code. The object also supports the legacy two-value tuple protocol so existing code can continue to unpack `image_or_images, labels = loader[0]`.

> **Example**
> ```python
sample = loader[0]

images = sample.images
labels = sample.labels
metadata = sample.metadata
```

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `images` | `dict[str, np.ndarray]` | Image arrays keyed by source name. Single-source datasets use the conventional `"image"`
key. |
| `labels` | `dict[str, np.ndarray]` | Label arrays keyed by `"task_name/task_type"`. |
| `metadata` | `Params` | Record-level metadata from
[DatasetRecord.sample_metadata](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/ldf/annotation.md),
plus any automatic loader metadata such as `"filenames"` when enabled. Augmented outputs also include an `"augmentations"` mapping
from configured paths to the runtime parameters that were selected. |

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`image`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
| `np.ndarray` | Returns the first image in the images dictionary. |

#### property `image`

```python
image: np.ndarray
```

Returns the first image in the images dictionary.

### class `TrackedAugmentations`

```python
class TrackedAugmentations(dict)
```

Augmentation provenance generated by a loader.

A plain mapping, subclassed only to stay distinguishable from a record's own `"augmentations"` metadata.

## Functions

| Name | Description |
| --- | --- |
|
[`all_not_none`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
| Check whether all values in a collection are not `None`. |
|
[`any_not_none`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
| Check whether at least one value in a collection is not `None`. |
|
[`check_type`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md)
| Check whether a value has the expected type. |

### function `all_not_none`

```python
def all_not_none(values: Iterable[Any]) -> bool
```

Check whether all values in a collection are not `None`.

> **Examples**
> ```pycon
>>> all_not_none([1, "x", 0])
True
>>> all_not_none([1, None, 0])
False
>>> all_not_none([])
True
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `values` | `Iterable[Any]` | Iterable of values to check. | required |

Returns

| Type | Description |
| --- | --- |
| `bool` | `True` if all values are not `None`, otherwise `False`. |

### function `any_not_none`

```python
def any_not_none(values: Iterable[Any]) -> bool
```

Check whether at least one value in a collection is not `None`.

> **Examples**
> ```pycon
>>> any_not_none([None, "x"])
True
>>> any_not_none([None, None])
False
>>> any_not_none([])
False
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `values` | `Iterable[Any]` | Iterable of values to check. | required |

Returns

| Type | Description |
| --- | --- |
| `bool` | `True` if at least one value is not `None`, otherwise `False`. |

### function `check_type`

```python
def check_type(value: Any, typ: type[T]) -> TypeGuard[T]
```

Check whether a value has the expected type.

> **Note**
> This function acts as a [type guard](https://typing.python.org/en/latest/spec/narrowing.html#typeguard), allowing type checkers to narrow the type of a variable when the function returns `True`.

> **Examples**
> ```pycon
>>> check_type("oak", str)
True
>>> check_type("oak", int)
False
>>> check_type([1, 2, 3], list)
True
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `value` | `Any` | Value to check. | required |
| `typ` | `type[T]` | Type to check against. | required |

Returns

| Type | Description |
| --- | --- |
| `TypeGuard[T]` | `True` if `value` conforms to `typ`, otherwise `False`. |

## Module Attributes

| Name | Type | Description |
| --- | --- | --- |
| [`Color`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | Color type alias. |
| [`HSV`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` |  |
| [`Kwargs`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | A keyword dictionary of arbitrary parameters. |
| [`Labels`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | Dictionary mapping task names to the annotations as C{np.ndarray} |
| [`LoaderMultiOutput`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | C{LoaderMultiOutput} is a tuple containing a dictionary mapping image names to C{np.ndarray} and a dictionary of task group names and their annotations as L{Labels}. |
| [`LoaderSingleOutput`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | C{LoaderSingleOutput} is a tuple containing a single image as a C{np.ndarray} and a dictionary of task group names and their annotations as L{Labels}. |
| [`Params`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | A keyword dictionary of additional parameters. |
| [`ParamValue`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` |  |
| [`PathType`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | A string or a [pathlib.Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path) object. |
| [`PosixPathType`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | A string or a [pathlib.PurePosixPath](https://docs.python.org/3/library/pathlib.html#pathlib.PurePosixPath) object. |
| [`PrimitiveType`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` | Primitive types in Python. |
| [`RGB`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` |  |
| [`T`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) |  |  |
| [`TaskType`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/typing.md) | `TypeAlias` |  |

### type alias `Color`

```python
Color: TypeAlias = str | int | RGB
```

Color type alias.

Can be either a string (e.g. "red", "#FF5512"), a tuple of RGB values, or a single value (in which case it is interpreted as a grayscale value).

### type alias `HSV`

```python
HSV: TypeAlias = tuple[float, float, float]
```

### type alias `Kwargs`

```python
Kwargs: TypeAlias = dict[str, Any]
```

A keyword dictionary of arbitrary parameters.

### type alias `Labels`

```python
Labels: TypeAlias = dict[str, np.ndarray]
```

Dictionary mapping task names to the annotations as C{np.ndarray}

### type alias `LoaderMultiOutput`

```python
LoaderMultiOutput: TypeAlias = tuple[dict[str, np.ndarray], Labels]
```

C{LoaderMultiOutput} is a tuple containing a dictionary mapping image names to C{np.ndarray} and a dictionary of task group names and their annotations as L{Labels}.

### type alias `LoaderSingleOutput`

```python
LoaderSingleOutput: TypeAlias = tuple[np.ndarray, Labels]
```

C{LoaderSingleOutput} is a tuple containing a single image as a C{np.ndarray} and a dictionary of task group names and their annotations as L{Labels}.

### type alias `Params`

```python
Params: TypeAlias = dict[str, ParamValue]
```

A keyword dictionary of additional parameters.

Usually loaded from a YAML file.

### type alias `ParamValue`

```python
ParamValue: TypeAlias = Mapping[str, ParamValue] | Sequence[ParamValue] | PrimitiveType
```

### type alias `PathType`

```python
PathType: TypeAlias = str | Path
```

A string or a [pathlib.Path](https://docs.python.org/3/library/pathlib.html#pathlib.Path) object.

### type alias `PosixPathType`

```python
PosixPathType: TypeAlias = str | PurePosixPath
```

A string or a [pathlib.PurePosixPath](https://docs.python.org/3/library/pathlib.html#pathlib.PurePosixPath) object.

### type alias `PrimitiveType`

```python
PrimitiveType: TypeAlias = str | int | float | bool | None
```

Primitive types in Python.

### type alias `RGB`

```python
RGB: TypeAlias = tuple[int, int, int]
```

### type variable `T`

```python
T = TypeVar('T')
```

### type alias `TaskType`

```python
TaskType: TypeAlias = Literal[
    'classification',
    'boundingbox',
    'segmentation',
    'instance_segmentation',
    'keypoints',
    'array',
]
```
