# base_analyze

Python API: `modelconverter.platforms.base_analyze`

Base class of the per-platform model analyzers.

An analyzer inspects a converted model layer by layer on a connected device: it compares the output of every layer against the
ONNX model the conversion started from, and measures the cycles each layer takes. Only the RVC4 package implements it. The
analyzer runs on the host and calls the SNPE tools there, so `snpe-dlc-info` and `snpe-diagview` must be on the host `PATH`.

## Classes

### Analyzer

Base class for the layer-wise analysis of a DLC model.

Reads the names and shapes of the model's inputs and outputs, and the data types of its inputs, from `snpe-dlc-info`, and checks
the directories holding the images the analysis is run on.

#### Methods

##### init

```python
def __init__(dlc_model_path: str, image_dirs: dict[str, str]):
```

Initialize the analyzer and read the model's layer shapes.

Parameters

 * `dlc_model_path` (`str`): Path to the DLC model to analyze.
 * `image_dirs` (`dict[str, str]`): Directory of input images per model input, keyed by input name. All of them must hold the same
   number of files. A single directory keyed by any name is matched to the only input of a single-input model.

Raises

 * `ValueError`: If the directories do not all hold the same number of files, if there are no directories, or if an input name
   matches none of the model's inputs.

##### analyze_layer_cycles

```python
def analyze_layer_cycles(self):
```

Measure the cycles each layer of the model takes.

##### analyze_layer_outputs

```python
def analyze_layer_outputs(onnx_model_path: Path):
```

Compare the layer outputs against the original ONNX model.

Parameters

 * `onnx_model_path` (`Path`): Path to the ONNX model the analyzed model was converted from.
