# 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),
which the per-platform exporters subclass.

## Classes

### Exporter

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)
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)
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)
wraps both with the shared bookkeeping.

#### Methods

##### 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.

Parameters

 * `config` (`SingleStageConfig`): Configuration of the single stage to convert.
 * `output_dir` (`Path`): Directory the converted model and the build information are written to.

##### export

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

Convert the model with the platform's toolchain.

Returns

 * `Path`: Path of the converted model, still under its intermediate name.

##### exporter_buildinfo

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

Describe the platform-specific side of the conversion.

Returns

 * `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).

##### run

```python
def run(self) -> 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),
renames its result after the original model, drops the intermediate outputs unless they are to be kept, and writes
`buildinfo.json`.

Returns

 * `Path`: Path of the converted model in the output directory.

#### Attributes

##### config

##### inference_model_path

Return the path of the model to run inference with.

Raises

 * `ValueError`: If the export has not been run yet, so no such model exists.

##### inputs

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)
reads them to resolve a linked calibration, so every exporter must provide them.

##### intermediate_outputs_dir

##### model_name

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)
uses it to name the calibration directory of a linked stage.

##### output_dir

##### platform

The platform the subclass converts for.
