# dai_benchmark

Python API: `modelconverter.platforms.dai_benchmark`

The DepthAI benchmark pipeline of the RVC2 and RVC4 benchmarks.

Benchmark nodes on the device feed one input to the model in a loop and report the throughput. The latency of one inference comes
from the device logs.

## Functions

| Name | Description |
| --- | --- |
| [`run_dai_benchmark`](https://docs.luxonis.com/software-v3/ai-inference/conversion/rvc-conversion/offline/modelconverter/modelconverter-api-reference/platforms/dai_benchmark.md#dai_benchmark-Functions-run_dai_benchmark) | Run the model on the device in a loop and measure its speed. |

### function `run_dai_benchmark`

```python
def run_dai_benchmark(
    device: dai.Device,
    input_data: dai.NNData,
    configure_network: Callable[[dai.node.NeuralNetwork], None],
    *,
    latency_pattern: re.Pattern[str],
    log_level: dai.LogLevel,
    input_fps: float,
    num_threads: int,
    num_messages: int,
    benchmark_time: int,
    repetitions: int,
) -> Result
```

Run the model on the device in a loop and measure its speed.

Args

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `device` | `dai.Device` | Device to run the pipeline on. | required |
| `input_data` | `dai.NNData` | Input that is sent to the model on every inference. | required |
| `configure_network` | `Callable[[dai.node.NeuralNetwork], None]` | Loads the model into the network node. | required |
| `latency_pattern` | `re.Pattern[str]` | Pattern of the latency in the device logs, with a `latency_ms` group. | required |
| `log_level` | `dai.LogLevel` | Log level at which the device reports the latency. The logs reach the callback only; stdout gets warnings. | required |
| `input_fps` | `float` | Rate of the inputs, `-1` for no limit. | required |
| `num_threads` | `int` | Number of inference threads of the network. | required |
| `num_messages` | `int` | Number of messages in each throughput report. | required |
| `benchmark_time` | `int` | Duration of the run in seconds. A value that is not positive runs `repetitions` reports instead. | required |
| `repetitions` | `int` | Number of reports to collect in a run that `benchmark_time` does not limit. | required |

Returns

| Type | Description |
| --- | --- |
| `Result` | The mean `fps` and the mean `latency` in milliseconds, or `"N/A"` when the logs hold no latency. |

Raises

| Type | Description |
| --- | --- |
| `TypeError` | If the report queue returns a message that is not a `dai.BenchmarkReport`. |
