# config

Python API: `modelconverter.utils.config`

Configuration models describing a conversion.

A conversion is described by a YAML file (see `configs/defaults.yaml`) that is parsed into the pydantic models defined here. The
top-level
[Config](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-Config)
holds one
[SingleStageConfig](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-SingleStageConfig)
per stage, each describing the input model, its inputs and outputs, the calibration data and the platform-specific options
([HailoConfig](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-HailoConfig),
[RVC2Config](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RVC2Config),
[RVC3Config](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RVC3Config)
and
[RVC4Config](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RVC4Config)).

Values that the user did not provide are filled in from the metadata of the input model itself, so that the exporter running
inside the per-backend Docker image receives a fully resolved description of the model.

## Classes

| Name | Description |
| --- | --- |
| [`BaseCalibrationConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-BaseCalibrationConfig) | Resize policy shared by image, random and linked calibration. |
| [`BlobBaseConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-BlobBaseConfig) | Options shared by the OpenVINO-based platforms. |
| [`Config`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-Config) | Top-level configuration of a conversion. |
| [`EncodingConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-EncodingConfig) | Color encoding conversion requested for an input. |
| [`HailoConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-HailoConfig) | Options of the Hailo conversion. |
| [`ImageCalibrationConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ImageCalibrationConfig) | Calibration data read from a directory of files. |
| [`InputConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig) | Description of a single input of the model. |
| [`LinkCalibrationConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-LinkCalibrationConfig) | Calibration data produced by another stage of the conversion. |
| [`ONNXOptimizationsConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ONNXOptimizationsConfig) | Switches of the individual ONNX graph optimizations. |
| [`OutputConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-OutputConfig) | Description of a single output of the model. |
| [`PlatformConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-PlatformConfig) | Base class for the platform-specific sections of a stage. |
| [`QuantizationOverrides`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-QuantizationOverrides) | Raw RVC4 quantization overrides to pass to SNPE. |
| [`RandomCalibrationConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RandomCalibrationConfig) | Calibration data generated from a normal distribution. |
| [`RVC2Config`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RVC2Config) | Options of the RVC2 conversion. |
| [`RVC3Config`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RVC3Config) | Options of the RVC3 conversion. |
| [`RVC4Config`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RVC4Config) | Options of the RVC4 conversion. |
| [`SingleStageConfig`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-SingleStageConfig) | Description of a single stage of the conversion. |

### class `BaseCalibrationConfig`

```python
class BaseCalibrationConfig(BaseModelExtraForbid)
```

Resize policy shared by image, random and linked calibration.

`resize_method` defaults to `RESIZE` at runtime. An omitted policy remains omitted during serialization so it cannot override
archive metadata or become an explicit deployment requirement on reload.

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`has_resize_method`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-BaseCalibrationConfig-has_resize_method) | `bool` | Whether a resize policy was configured or inherited from an archive. |

Methods

| Name | Description |
| --- | --- |
| [`to_image_calibration`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-BaseCalibrationConfig-to_image_calibration) | Retain resize policy when generated calibration becomes files. |

#### property `has_resize_method`

```python
has_resize_method: bool
```

Whether a resize policy was configured or inherited from an archive.

#### method `to_image_calibration`

```python
def to_image_calibration(path: Path) -> ImageCalibrationConfig
```

Retain resize policy when generated calibration becomes files.

### class `BlobBaseConfig`

```python
class BlobBaseConfig(PlatformConfig)
```

Options shared by the OpenVINO-based platforms.

Base class for the RVC2 and RVC3 configurations, which both convert the model through OpenVINO into a blob.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `compile_tool_args` | `list[str]` | Additional arguments passed to the OpenVINO `compile_tool`. They take precedence over the default ones. |
| `compress_to_fp16` | `bool` | Whether to compress FP32 weights and biases of the original model to FP16. All intermediate data is kept in the original precision. |
| `mo_args` | `list[str]` | Additional arguments passed to the OpenVINO model optimizer. They take precedence over the default ones. |

### class `Config`

```python
class Config(LuxonisConfig)
```

Top-level configuration of a conversion.

A single-stage configuration is accepted as well: the stage fields can be given at the top level and are wrapped into a single
stage during validation, so the shorthand

```yaml
input_model: models/yolov6n.onnx
encoding:
  from: RGB
  to: BGR
calibration:
  path: models/coco128
```

is equivalent to the same fields nested under a single entry of `stages`. See `configs/defaults.yaml` for every field with its
default.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `name` | `str` | Package name for NN Archive files and default output directories in both output modes. Defaults to the archive basename, model stem for flat configs, or joined explicit stage keys. Also names the implicit stage in flat configs; explicit stage keys and model files stay unchanged. |
| `rich_logging` | `bool` | Whether to use rich formatting for the log messages. |
| `stages` | `dict[str, SingleStageConfig]` | Configurations of the individual stages, keyed by stage name. |

Methods

| Name | Description |
| --- | --- |
| [`get_stage_config`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-Config-get_stage_config) | Return the configuration of the given stage. |
| [`merge_overrides`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-Config-merge_overrides) | Merge overrides into raw config data, in place. |

#### method `get_stage_config`

```python
def get_stage_config(stage: str | None) -> SingleStageConfig
```

Return the configuration of the given stage.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `stage` | `str | None` | Name of the stage. Can be `None` only if the configuration has a single stage. | required |

Returns

| Type | Description |
| --- | --- |
| `SingleStageConfig` | The configuration of the requested stage. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If no stage name is given and the configuration has more than one stage. |
| `KeyError` | If no stage of the given name exists. |

#### class method `merge_overrides`

```python
def merge_overrides(data: Params, overrides: Params)
```

Merge overrides into raw config data, in place.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `data` | `Params` | Raw config data to update. | required |
| `overrides` | `Params` | Overrides keyed by dotted paths, such as `"stages.main.inputs"`. | required |

### class `EncodingConfig`

```python
class EncodingConfig(BaseModelExtraForbid)
```

Color encoding conversion requested for an input.

The `from` field, named `from_` in Python, is the encoding the original model expects. The `to` field is the encoding the
converted model is fed with at runtime. If the two differ, a channel reversal is prepended to the input, so that the converted
model takes `to` data while the original graph still receives `from` data.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `from_` | `Encoding` |  |

### class `HailoConfig`

```python
class HailoConfig(PlatformConfig)
```

Options of the Hailo conversion.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `alls` | `list[str]` | Additional lines of the Hailo model script (`alls`) passed to the model optimizer. |
| `batch_size` | `int` | Batch size used for the calibration. |
| `compression_level` | `Literal[0, 1, 2, 3, 4, 5]` | Compression level, between `0` and `5`. |
| `disable_compilation` | `bool` | Whether to stop after the quantization, without compiling the model. |
| `force_onnx_names` | `bool` | Whether to force the ONNX names on the produced `.har` and `.hef` models. |
| `hw_arch` | `Literal['hailo8', 'hailo8l', 'hailo8r', 'hailo10h', 'hailo15h', 'hailo15m']` | Hailo hardware architecture to compile for. |
| `optimization_level` | `Literal[-100, 0, 1, 2, 3, 4]` | Optimization level, between `0` and `4`, or `-100` to disable all optimizations. |

### class `ImageCalibrationConfig`

```python
class ImageCalibrationConfig(BaseCalibrationConfig)
```

Calibration data read from a directory of files.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `max_images` | `int` | Number of files to use from the calibration data. A negative value means all of them. |
| `path` | `Path` | Path to the calibration data. Can be a local directory, a remote URL, or an LDF dataset identifier in the `<dataset_name>:<split>` form; it is downloaded during validation and stored as a local path. |
| `resize_method` |  | How to resize images for calibration and inference. Explicit values also define the output archive's resize mode. |

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`generated_from_link`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ImageCalibrationConfig-generated_from_link) | `bool` | Whether this file source was materialized from a stage link. |
| [`generated_from_random`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ImageCalibrationConfig-generated_from_random) | `bool` | Whether this file source was materialized from random calibration. |
| [`generated_layout`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ImageCalibrationConfig-generated_layout) | `str` | Layout used when generated tensor calibration was materialized. |

Methods

| Name | Description |
| --- | --- |
| [`is_user_tensor`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ImageCalibrationConfig-is_user_tensor) | Whether a tensor file uses the backend-ready calibration contract. |
| [`mark_generated_from_link`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ImageCalibrationConfig-mark_generated_from_link) | Mark the files as written from linked inference results. |
| [`mark_generated_from_random`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ImageCalibrationConfig-mark_generated_from_random) | Mark the files as written from random calibration data. |

#### property `generated_from_link`

```python
generated_from_link: bool
```

Whether this file source was materialized from a stage link.

#### property `generated_from_random`

```python
generated_from_random: bool
```

Whether this file source was materialized from random calibration.

#### property `generated_layout`

```python
generated_layout: str
```

Layout used when generated tensor calibration was materialized.

#### method `is_user_tensor`

```python
def is_user_tensor(path: Path) -> bool
```

Whether a tensor file uses the backend-ready calibration contract.

#### method `mark_generated_from_link`

```python
def mark_generated_from_link(layout: str)
```

Mark the files as written from linked inference results.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `layout` | `str` | Layout of the generated tensors. | required |

#### method `mark_generated_from_random`

```python
def mark_generated_from_random(layout: str)
```

Mark the files as written from random calibration data.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `layout` | `str` | Layout of the generated tensors. | required |

### class `InputConfig`

```python
class InputConfig(OutputConfig)
```

Description of a single input of the model.

Extends
[OutputConfig](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-OutputConfig)
with the pre-processing and calibration settings of the input. Each conversion applies `mean_values` and `scale_values` in its own
way: the RVC4 exporter bakes them into the ONNX graph, RVC2 and RVC3 hand them to the OpenVINO model optimizer, and Hailo puts
them in the model script.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `calibration` | `ImageCalibrationConfig | RandomCalibrationConfig | LinkCalibrationConfig` | Source of the calibration data for this input. |
| `encoding` | `EncodingConfig` | Color encoding conversion for this input. |
| `frozen_value` | `list[int | float] | None` | List of constant values the input is frozen to. Used only by the OpenVINO-based conversions (RVC2 and RVC3), which pass it on to the model optimizer. |
| `mean_values` | `Annotated[list[float], Field(min_length=1)] | None` | Per-channel values subtracted from the input, with the same options as `scale_values`. |
| `scale_values` | `Annotated[list[float], Field(min_length=1)] | None` | Per-channel values the input is divided by, after `mean_values` has been subtracted. Can be given as a single number, a list, or the name of a preset such as `"imagenet"`. |

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`calibration_preprocessing`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-calibration_preprocessing) | `CalibrationPreprocessing | None` | Preprocessing moved out of the model but retained for calibration. |
| [`channel_count`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-channel_count) | `int | None` | The positive channel count when `C` is trustworthy. |
| [`encoding_mismatch`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-encoding_mismatch) | `bool` | Whether the `from` and `to` encodings differ. |
| [`is_color_input`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-is_color_input) | `bool` | Whether the input is fed with color image data. |
| [`is_raw_input`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-is_raw_input) | `bool` | Whether the input is fed with non-image data. |

Methods

| Name | Description |
| --- | --- |
| [`calibration_preprocessing.setter`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-calibration_preprocessing.setter) |  |
| [`requires_input_preprocessing`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-requires_input_preprocessing) | Check whether preprocessing is requested for this input. |
| [`validate_input_contract`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-validate_input_contract) | Validate encoding and preprocessing against a known channel axis. |
| [`validate_preprocessing`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-InputConfig-validate_preprocessing) | Validate requested preprocessing and return the channel count. |

#### property `calibration_preprocessing`

```python
calibration_preprocessing: CalibrationPreprocessing | None
```

Preprocessing moved out of the model but retained for calibration.

#### property `channel_count`

```python
channel_count: int | None
```

The positive channel count when `C` is trustworthy.

#### property `encoding_mismatch`

```python
encoding_mismatch: bool
```

Whether the `from` and `to` encodings differ.

#### property `is_color_input`

```python
is_color_input: bool
```

Whether the input is fed with color image data.

#### property `is_raw_input`

```python
is_raw_input: bool
```

Whether the input is fed with non-image data.

#### method `calibration_preprocessing.setter`

```python
def calibration_preprocessing.setter(value: CalibrationPreprocessing | None)
```

#### method `requires_input_preprocessing`

```python
def requires_input_preprocessing(*, reverse_only: bool = False) -> bool
```

Check whether preprocessing is requested for this input.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `reverse_only` | `bool` | If `True`, only the channel reversal is taken into account and the mean and scale values are ignored. | `False` |

Returns

| Type | Description |
| --- | --- |
| `bool` | `True` if the encodings differ or -- unless `reverse_only` is set -- if any non-neutral mean or scale values are set. |

#### method `validate_input_contract`

```python
def validate_input_contract(*, validate_values: bool = True)
```

Validate encoding and preprocessing against a known channel axis.

#### method `validate_preprocessing`

```python
def validate_preprocessing(*, reverse_only: bool = False) -> int
```

Validate requested preprocessing and return the channel count.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `reverse_only` | `bool` | Validate only a requested encoding conversion. | `False` |

Returns

| Type | Description |
| --- | --- |
| `int` | The resolved number of input channels. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the input contract is insufficient or inconsistent. |

### class `LinkCalibrationConfig`

```python
class LinkCalibrationConfig(BaseCalibrationConfig)
```

Calibration data produced by another stage of the conversion.

Used for multi-stage models, where the calibration data of one stage is obtained by running inference with a previously converted
stage.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `layout` | `str | None` | Layout of arrays returned by `script`. When omitted, the arrays use the backend-ready calibration tensor contract. |
| `output` | `str | None` | Name of the output of `stage` to use as the calibration data. |
| `resize_method` |  | Image resize policy, also retained for inference and output archive metadata. Prepared tensors are not resized. |
| `script` | `str | None` | Python script post-processing the outputs of `stage`. Either the source code itself or a path to a `.py` file, whose contents are read during validation. Either `output` or `script` must be provided. |
| `stage` | `str` | Name of the stage to take the calibration data from. |

### class `ONNXOptimizationsConfig`

```python
class ONNXOptimizationsConfig(BaseModelExtraForbid)
```

Switches of the individual ONNX graph optimizations.

The optimizations are applied to the ONNX model before it is handed over to the platform-specific conversion. All of them are
enabled by default.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `fuse_add_mul_to_bn` | `bool` | Whether to fuse `Add`/`Sub` and `Mul` nodes following a `Conv` node into a `BatchNormalization` node. |
| `fuse_comb_add_mul_to_conv` | `bool` | Whether to fuse combinations of `Add` and `Mul` nodes preceding a `Conv` node into the `Conv` node. |
| `fuse_single_add_mul_to_conv` | `bool` | Whether to fuse a single `Add` or `Mul` node preceding a `Conv` node into the `Conv` node. |
| `fuse_split_concat_to_conv` | `bool` | Whether to fuse `Split` and `Concat` nodes preceding a `Conv` node into the `Conv` node. |
| `substitute_div_with_mul` | `bool` | Whether to replace a `Div` node whose second operand is a float constant with a `Mul` node and a reciprocal copy of that constant. |
| `substitute_sub_with_add` | `bool` | Whether to replace a `Sub` node whose second operand is a constant with an `Add` node and a negated copy of that constant. |

Methods

| Name | Description |
| --- | --- |
| [`all_disabled`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ONNXOptimizationsConfig-all_disabled) | Check whether every optimization is switched off. |

#### method `all_disabled`

```python
def all_disabled() -> bool
```

Check whether every optimization is switched off.

### class `OutputConfig`

```python
class OutputConfig(BaseModelExtraForbid)
```

Description of a single output of the model.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `data_type` | `DataType` | Data type of the output. |
| `layout` | `str | None` | Lettercode representation of the layout, e.g. `"NCHW"`. Requires `shape` to be provided; a default layout is guessed from the shape if only `shape` is given. |
| `name` | `str` | Name of the output tensor or node. |
| `shape` | `list[int] | None` | Shape of the output. Inferred from the model if not provided. |

Methods

| Name | Description |
| --- | --- |
| [`validate_layout`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-OutputConfig-validate_layout) | Check that the layout and the shape have the same length. |

#### method `validate_layout`

```python
def validate_layout() -> Self
```

Check that the layout and the shape have the same length.

Returns

| Type | Description |
| --- | --- |
| `Self` | The validated model. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the length of the layout does not match the length of the shape. |

### class `PlatformConfig`

```python
class PlatformConfig(BaseModelExtraForbid)
```

Base class for the platform-specific sections of a stage.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `disable_calibration` | `bool` | Whether to skip calibration, and with it the quantization of the model. |

### class `QuantizationOverrides`

```python
class QuantizationOverrides(BaseModelExtraForbid)
```

Raw RVC4 quantization overrides to pass to SNPE.

The payload is kept either as the user-provided mapping or as the path to the user-provided file. It is intentionally not coerced
through `Encodings` unless the caller already provided an `Encodings` object.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `payload` | `dict[str, Any] | None` |  |
| `source_path` | `Path | None` |  |

Methods

| Name | Description |
| --- | --- |
| [`from_path`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-QuantizationOverrides-from_path) | Build overrides from a JSON file path. |
| [`from_payload`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-QuantizationOverrides-from_payload) | Build overrides from an inline JSON payload. |
| [`load_payload`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-QuantizationOverrides-load_payload) | Return the JSON payload without mutating the stored source. |
| [`serialize`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-QuantizationOverrides-serialize) | Serialize like the user-facing `rvc4.encodings` value. |

#### class method `from_path`

```python
def from_path(path: Path) -> QuantizationOverrides
```

Build overrides from a JSON file path.

#### class method `from_payload`

```python
def from_payload(payload: dict[str, Any]) -> QuantizationOverrides
```

Build overrides from an inline JSON payload.

#### method `load_payload`

```python
def load_payload() -> dict[str, Any]
```

Return the JSON payload without mutating the stored source.

#### method `serialize`

```python
def serialize() -> dict[str, Any] | str
```

Serialize like the user-facing `rvc4.encodings` value.

### class `RandomCalibrationConfig`

```python
class RandomCalibrationConfig(BaseCalibrationConfig)
```

Calibration data generated from a normal distribution.

Used when no calibration data is provided. The generated values are drawn from a normal distribution and clipped to the allowed
range.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `data_type` | `DataType` | Data type the generated samples are cast to. |
| `max_images` | `int` | Number of samples to generate. |
| `max_value` | `float` | Upper bound the generated values are clipped to. |
| `mean` | `float` | Mean of the normal distribution. |
| `min_value` | `float` | Lower bound the generated values are clipped to. |
| `resize_method` |  | Image resize policy retained for inference and output archive metadata. Random samples already have input size. |
| `std` | `float` | Standard deviation of the normal distribution. |

### class `RVC2Config`

```python
class RVC2Config(BlobBaseConfig)
```

Options of the RVC2 conversion.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `n_workers` | `PositiveInt | None` | Number of workers used for the parallel superblob compilation. Overrides the automatically determined number. |
| `number_of_shaves` | `int` | Number of SHAVE cores the blob is compiled for. Forced to `8` when `superblob` is enabled. |
| `superblob` | `bool` | Whether to produce a `.superblob` file instead of a regular `.blob`. |

### class `RVC3Config`

```python
class RVC3Config(BlobBaseConfig)
```

Options of the RVC3 conversion.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `pot_target_device` | `PotDevice` | Target device of the OpenVINO post-training optimization tool. |

### class `RVC4Config`

```python
class RVC4Config(PlatformConfig)
```

Options of the RVC4 conversion.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `disable_calibration` | `bool` |  |
| `encodings` | `QuantizationOverrides | Encodings | None` | Raw quantization overrides passed to SNPE. ModelConverter only inspects names when strict validation is enabled and only rewrites exposed IO entries when IO normalization is enabled. |
| `htp_socs` | `list[Literal['sm8350', 'sm8450', 'sm8550', 'sm8650', 'qcs6490', 'qcs8550']]` | Platforms to pre-compute the DLC graph for. |
| `keep_raw_images` | `bool` | Whether to keep the raw calibration images in the intermediate outputs. They can get very large. |
| `normalize_io_encodings` | `bool` | Whether to replace exposed input/output activation encodings with the default 8-bit integer encoding. |
| `optimization_level` | `Literal[1, 2, 3]` | Optimization level of the DLC graph preparation. Higher levels take longer but yield a faster graph. |
| `quantization_mode` | `QuantizationMode` | Pre-defined quantization mode. All modes except `CUSTOM` override the user-provided SNPE arguments. |
| `snpe_dlc_graph_prepare_args` | `list[str]` | Additional arguments passed to SNPE `snpe-dlc-graph-prepare`. |
| `snpe_dlc_quant_args` | `list[str]` | Additional arguments passed to SNPE `snpe-dlc-quant`. |
| `snpe_onnx_to_dlc_args` | `list[str]` | Additional arguments passed to SNPE `snpe-onnx-to-dlc`. They take precedence over the default ones. |
| `strict_quantization_overrides` | `bool` | Whether to validate configured quantization override names against their activation/parameter groups in the effective ONNX model. |
| `use_per_channel_quantization` | `bool` | Whether to use per-axis-element quantization for the weights and biases of the supported layer types. |
| `use_per_row_quantization` | `bool` | Whether to use row-wise quantization of the `MatMul` and `FullyConnected` operations. |

Methods

| Name | Description |
| --- | --- |
| [`validate_encodings`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RVC4Config-validate_encodings) | Preserve the quantization encodings from the config. |
| [`validate_quantization_overrides`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-RVC4Config-validate_quantization_overrides) | Normalize raw quantization override arguments into `encodings`. |

#### static method `validate_encodings`

```python
def validate_encodings(
    value: ParamValue | QuantizationOverrides | Encodings,
) -> QuantizationOverrides | Encodings | None
```

Preserve the quantization encodings from the config.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `value` | `ParamValue | QuantizationOverrides | Encodings` | Either `None`, a JSON string, a path to a JSON file, or an already parsed mapping. | required |

Returns

| Type | Description |
| --- | --- |
| `QuantizationOverrides | Encodings | None` | The raw encodings source, or `None` if no value was given. |

#### method `validate_quantization_overrides`

```python
def validate_quantization_overrides() -> Self
```

Normalize raw quantization override arguments into `encodings`.

Both `--quantization_overrides PATH` and `--quantization_overrides=PATH` forms are removed from `snpe_onnx_to_dlc_args` and the
referenced JSON file is stored as the raw `encodings` source.

Returns

| Type | Description |
| --- | --- |
| `Self` | The validated model. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If a raw override path is missing, more than one raw override is provided, or a raw override is combined with `encodings`. |

### class `SingleStageConfig`

```python
class SingleStageConfig(BaseModelExtraForbid)
```

Description of a single stage of the conversion.

Holds everything needed to convert one model: the model itself, its inputs and outputs, and the options of every supported
platform. Most of the fields are filled in from the metadata of the input model when they are not given explicitly.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `hailo` | `HailoConfig` | Options of the Hailo conversion. |
| `input_bin` | `Path | None` | Path to the `.bin` file of an OpenVINO IR model. Derived from `input_model` for IR models. |
| `input_file_type` | `InputFileType` | Type of the input model, derived from the suffix of `input_model`. |
| `input_model` | `Path` | Path to the model to convert. Downloaded to the local models directory during validation. |
| `inputs` | `list[InputConfig]` | Descriptions of the model inputs. |
| `intermediate_outputs_remote_url` | `str | None` | Remote URL to upload the intermediate outputs to. |
| `keep_intermediate_outputs` | `bool` | Whether to keep the files created during the conversion. |
| `onnx_optimizations` | `ONNXOptimizationsConfig` | Switches of the ONNX graph optimizations. |
| `onnx_simplification` | `Literal['onnxsim', 'onnxslim', False]` | ONNX simplification method to use, or `False` to disable the simplification. |
| `output_remote_url` | `str | None` | Remote URL to upload the converted model to. |
| `outputs` | `list[OutputConfig]` | Descriptions of the model outputs. |
| `put_file_plugin` | `str | None` | Name of the registered plugin used for the uploads. |
| `rvc2` | `RVC2Config` | Options of the RVC2 conversion. |
| `rvc3` | `RVC3Config` | Options of the RVC3 conversion. |
| `rvc4` | `RVC4Config` | Options of the RVC4 conversion. |

Methods

| Name | Description |
| --- | --- |
| [`get_platform_config`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-SingleStageConfig-get_platform_config) | Return the platform configuration for the given platform. |
| [`validate_disable_onnx_optimizations`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-SingleStageConfig-validate_disable_onnx_optimizations) | Translate the deprecated `disable_onnx_optimizations`. |
| [`validate_onnx_optimizations`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-SingleStageConfig-validate_onnx_optimizations) | Expand the shorthand values of `onnx_optimizations`. |
| [`validate_onnx_simplification`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-SingleStageConfig-validate_onnx_simplification) | Translate the deprecated `disable_onnx_simplification`. |

#### method `get_platform_config`

```python
def get_platform_config(platform: Platform) -> PlatformConfig
```

Return the platform configuration for the given platform.

#### class method `validate_disable_onnx_optimizations`

```python
def validate_disable_onnx_optimizations(data: Params) -> Params
```

Translate the deprecated `disable_onnx_optimizations`.

> **Deprecated**
> Deprecated since version 0.5.6:Use `onnx_optimizations: false` instead.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `data` | `Params` | Raw stage configuration. | required |

Returns

| Type | Description |
| --- | --- |
| `Params` | The configuration with all ONNX optimizations disabled if the deprecated option was enabled. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If `disable_onnx_optimizations` is enabled and `onnx_optimizations` is specified as well. |

#### class method `validate_onnx_optimizations`

```python
def validate_onnx_optimizations(data: Params) -> Params
```

Expand the shorthand values of `onnx_optimizations`.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `data` | `Params` | Raw stage configuration. | required |

Returns

| Type | Description |
| --- | --- |
| `Params` | The configuration with `onnx_optimizations` replaced by an [ONNXOptimizationsConfig](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Classes-ONNXOptimizationsConfig) with all optimizations either enabled or disabled, if a shorthand value was used. |

#### class method `validate_onnx_simplification`

```python
def validate_onnx_simplification(data: Params) -> Params
```

Translate the deprecated `disable_onnx_simplification`.

> **Deprecated**
> Deprecated since version 0.5.6:Use `onnx_simplification: false` instead.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `data` | `Params` | Raw stage configuration. | required |

Returns

| Type | Description |
| --- | --- |
| `Params` | The configuration with `onnx_simplification` set to `False` if the deprecated option was enabled. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If `disable_onnx_simplification` is enabled and `onnx_simplification` is specified as well. |

## Functions

| Name | Description |
| --- | --- |
| [`broadcast_preprocessing_values`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Functions-broadcast_preprocessing_values) | Expand a scalar preprocessing value to the resolved channel count. |
| [`generate_renamed_onnx`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Functions-generate_renamed_onnx) | Save a copy of an ONNX model with renamed node connections. |

### function `broadcast_preprocessing_values`

```python
def broadcast_preprocessing_values(
    values: list[float],
    channels: int | None,
) -> list[float]
```

Expand a scalar preprocessing value to the resolved channel count.

### function `generate_renamed_onnx`

```python
def generate_renamed_onnx(
    onnx_path: PathType,
    rename_dict: dict[str, str],
    output_path: PathType,
)
```

Save a copy of an ONNX model with renamed node connections.

Every node input and output whose name appears in `rename_dict` is replaced by the new name. The model is saved with external data
if the original model used it.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `onnx_path` | `PathType` | Path to the ONNX model to rename. | required |
| `rename_dict` | `dict[str, str]` | Mapping from the old tensor names to the new ones. | required |
| `output_path` | `PathType` | Path to save the renamed model to. | required |

## Module Attributes

| Name | Type | Description |
| --- | --- | --- |
| [`NAMED_VALUES`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Module-Attributes-NAMED_VALUES) | `dict[str, dict]` |  |
| [`TRUSTWORTHY_INFERRED_CHANNEL_LAYOUTS`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/utils/config.md#config-Module-Attributes-TRUSTWORTHY_INFERRED_CHANNEL_LAYOUTS) |  |  |

### constant `NAMED_VALUES`

```python
NAMED_VALUES: dict[str, dict] = {
    'imagenet': {'mean': [123.675, 116.28, 103.53], 'scale': [58.395, 57.12, 57.375]},
}
```

### constant `TRUSTWORTHY_INFERRED_CHANNEL_LAYOUTS`

```python
TRUSTWORTHY_INFERRED_CHANNEL_LAYOUTS = frozenset({'CHW', 'HWC', 'NCHW', 'NHWC'})
```
