# calibration_data

Python API: `modelconverter.utils.calibration_data`

Collection of the images used to calibrate a quantized model.

Quantizing a model for RVC3, RVC4 or Hailo needs a set of representative images. This module turns whatever the config points at
-- a local directory, a remote file, archive or directory, or a view of a Luxonis Data Format dataset -- into a local directory of
images the exporters can read.

## Functions

| Name | Description |
| --- | --- |
| [`download_calibration_data`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/calibration_data.md#calibration_data-Functions-download_calibration_data) | Resolve a calibration data specification to a local directory. |
| [`load_from_ldf`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/calibration_data.md#calibration_data-Functions-load_from_ldf) | Write the images of an LDF dataset view out as calibration data. |
| [`read_img_dir`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/calibration_data.md#calibration_data-Functions-read_img_dir) | Return the calibration images found in a directory. |

### function `download_calibration_data`

```python
def download_calibration_data(string: str, max_images: int = -1) -> Path
```

Resolve a calibration data specification to a local directory.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `string` | `str` | What to calibrate with. Either a remote URL, which is downloaded and, if it is a `.zip`, extracted; a path to a local directory; or an LDF dataset specification of the form `<dataset_name>:<split>` or `<dataset_name>:<split>:<loader_plugin>`. | required |
| `max_images` | `int` | Maximum number of files to download from a remote directory. A negative value means no limit. | `-1` |

Returns

| Type | Description |
| --- | --- |
| `Path` | Path to the local directory holding the calibration images. |

Raises

| Type | Description |
| --- | --- |
| `ModelconverterException` | If the local path exists but is not a directory, or if the string is neither an existing path nor a well-formed LDF specification. |

### function `load_from_ldf`

```python
def load_from_ldf(
    dataset_name: str,
    view: str,
    loader_plugin: str | None = None,
) -> Path
```

Write the images of an LDF dataset view out as calibration data.

The images are saved as PNG files into a per-dataset subdirectory of the calibration data directory.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `dataset_name` | `str` | Name of the `LuxonisDataset` to load. With `loader_plugin` given, it only names the directory the images are written to. | required |
| `view` | `str` | Name of the dataset view (split) to load. | required |
| `loader_plugin` | `str | None` | Name of a loader registered in the `loaders` registry to use instead of `LuxonisLoader`. | `None` |

Returns

| Type | Description |
| --- | --- |
| `Path` | Path to the directory the images were written to. |

Raises

| Type | Description |
| --- | --- |
| `NotImplementedError` | If the dataset has more than one input. |

### function `read_img_dir`

```python
def read_img_dir(path: Path, max_images: int) -> list[Path]
```

Return the calibration images found in a directory.

Exits the process if the directory contains no images.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `path` | `Path` | Directory to read the images from. | required |
| `max_images` | `int` | Maximum number of images to use. A negative value means all of them. | required |

Returns

| Type | Description |
| --- | --- |
| `list[Path]` | Paths of the images to calibrate with. |
