# base_exporter

Python API: `modelconverter.platforms.base_exporter`

Platform-agnostic scaffolding for the model exporters.

Converting a model means handing it to a vendor toolchain that only exists inside that platform's Docker image, so what the
exporters share is everything around that call: staging the input model in the output directory, optionally simplifying the ONNX,
producing calibration data for the inputs that ask for random ones, and recording what was run. That part lives in
[Exporter](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter),
which the per-platform exporters subclass.

## Classes

| Name | Description |
| --- | --- |
| [`Exporter`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter) | Base class of the single-stage, per-platform model exporters. |

### class `Exporter`

```python
class Exporter(ABC)
```

Base class of the single-stage, per-platform model exporters.

Subclasses implement
[export](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-export)
to run their platform's toolchain and
[exporter_buildinfo](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-exporter_buildinfo)
to describe what they ran;
[run](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-run)
wraps both with the shared bookkeeping.

Attributes

| Name | Type | Description |
| --- | --- | --- |
| `config` |  |  |
| `intermediate_outputs_dir` |  |  |
| `output_dir` |  |  |
| `platform` | `Platform` | The platform the subclass converts for. |

Properties

| Name | Type | Description |
| --- | --- | --- |
| [`inference_model_path`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-inference_model_path) | `Path` | The path of the model to run inference with. |
| [`inputs`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-inputs) | `dict[str, InputConfig]` | The configured inputs, keyed by input name. |
| [`model_name`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-model_name) | `str` | The sanitized name of the input model, without a suffix. |

Methods

| Name | Description |
| --- | --- |
| [`__init__`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-__init__) | Stage the input model and the calibration data. |
| [`export`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-export) | Convert the model with the platform's toolchain. |
| [`exporter_buildinfo`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-exporter_buildinfo) | Describe the platform-specific side of the conversion. |
| [`read_calibration_file`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-read_calibration_file) | Load managed calibration data for quantization or linked inference. |
| [`run`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-run) | Convert the model and finish the output directory. |

#### property `inference_model_path`

```python
inference_model_path: Path
```

The path of the model to run inference with.

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the export has not been run yet, so no such model exists. |

#### property `inputs`

```python
inputs: dict[str, InputConfig]
```

The configured inputs, keyed by input name.

[MultiStageExporter](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/multistage_exporter.md#multistage_exporter-Classes-MultiStageExporter)
reads them to resolve a linked calibration, so every exporter must provide them.

#### property `model_name`

```python
model_name: str
```

The sanitized name of the input model, without a suffix.

[MultiStageExporter](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/multistage_exporter.md#multistage_exporter-Classes-MultiStageExporter)
uses it to name the calibration directory of a linked stage.

#### method `__init__`

```python
def __init__(config: SingleStageConfig, output_dir: Path)
```

Stage the input model and the calibration data.

The model, along with any ONNX external data belonging to it, is copied into the output directory and the intermediate outputs
directory, and simplified when the configuration asks for it. Unless the platform is RVC2 or calibration is disabled, inputs
configured for random calibration also get their data generated here, so that the export itself only ever sees image calibration.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `config` | `SingleStageConfig` | Configuration of the single stage to convert. | required |
| `output_dir` | `Path` | Directory the converted model and the build information are written to. | required |

#### method `export`

```python
def export() -> Path
```

Convert the model with the platform's toolchain.

Returns

| Type | Description |
| --- | --- |
| `Path` | Path of the converted model, still under its intermediate name. |

#### method `exporter_buildinfo`

```python
def exporter_buildinfo() -> Params
```

Describe the platform-specific side of the conversion.

Returns

| Type | Description |
| --- | --- |
| `Params` | Whatever the platform records about the tools it used, merged into `buildinfo.json` by [run](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-run). |

#### static method `read_calibration_file`

```python
def read_calibration_file(
    inp: InputConfig,
    calib: ImageCalibrationConfig,
    path: Path,
) -> tuple[npt.NDArray[np.generic], str]
```

Load managed calibration data for quantization or linked inference.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `inp` | `InputConfig` | Input whose runtime values the file contains. | required |
| `calib` | `ImageCalibrationConfig` | Calibration source, including its generated tensor layout. | required |
| `path` | `Path` | Image or managed tensor file to load. | required |

Returns

| Type | Description |
| --- | --- |
| `tuple[npt.NDArray[np.generic], str]` | The array with externalized preprocessing applied, and its layout. |

Raises

| Type | Description |
| --- | --- |
| `ValueError` | If the input has no shape or the file is an opaque user tensor that must retain its backend-ready contract. |
| `ModelconverterException` | If a generated tensor's rank does not match its recorded layout. |

#### method `run`

```python
def run() -> Path
```

Convert the model and finish the output directory.

Runs
[export](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/base_exporter.md#base_exporter-Classes-Exporter-export),
renames its result after the original model, drops the intermediate outputs unless they are to be kept, and writes
`buildinfo.json`.

Returns

| Type | Description |
| --- | --- |
| `Path` | Path of the converted model in the output directory. |
