# utils

Python API: `luxonis_ml.nn_archive.utils`

## Functions

| Name | Description |
| --- | --- |
|
[`infer_layout`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/nn_archive/utils.md)
| Infer a layout code for a tensor shape. |
|
[`is_nn_archive`](https://docs.luxonis.com/software-v3/ai-inference/model-source/training/luxonis-ml/luxonis-ml-api-reference/nn_archive/utils.md)
| Check whether a path points to a valid NN Archive. |

### function `infer_layout`

```python
def infer_layout(shape: list[int]) -> str
```

Infer a layout code for a tensor shape.

The function recognizes common image tensor layouts. For other shapes, it uses the first available letters starting at `C`.

> **Example**
> ```pycon
>>> infer_layout([1, 3, 256, 256])
'NCHW'
>>> infer_layout([256, 256, 3])
'HWC'
>>> infer_layout([1, 19, 7, 8])
'NCDE'
```

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `shape` | `list[int]` | Tensor shape to infer from. | required |

Returns

| Type | Description |
| --- | --- |
| `str` | Layout code matching the number of dimensions in `shape`. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the shape has too many dimensions for automatic layout inference. |

### function `is_nn_archive`

```python
def is_nn_archive(path: PathType) -> bool
```

Check whether a path points to a valid NN Archive.

A valid archive must be a tar file and contain a top-level `config.json` member.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `path` | `PathType` | Path to the file to check. | required |

Returns

| Type | Description |
| --- | --- |
| `bool` | `True` if the file is a valid NN Archive, otherwise `False`. |
