# LACInfer model zoo

## Description

LACInfer model zoo provides deployment examples for current mainstream algorithms,
including the process of using Python API to quantize, compile and inference the
ONNX models on LGGPU.

## Supported models

Below is a list of supported models:

- yolov5\{n/s/m\}, yolov5s\_relu, yolov5\{n/s/m\}-seg
- yolov6\{n/s/m\}
- yolov7
- yolov8\{n/s/m\}, yolov8n-obb, yolov8n-pose, yolov8\{n/s/m\}-seg
- yolov9s
- yolov10\{n/s/m\}
- yolo11\{n/s/m\}
- yolo12s
- yolo26s
- yolox-\{s/m\}

Note: Whether other models can inference correctly and how their performance
has not been fully validated.

## Example: Inference YOLOv5 using LACInfer

### Environment Setup

```
virtualenv venv
source venv/bin/activate

pip install -r requirements.txt

export PYTHONPATH=path/to/LACInfer/lib:$PYTHONPATH
```

### Options

| Option                  | Description                                       | Default                                 |
|-------------------------|---------------------------------------------------|-----------------------------------------|
| --imgPath               | image path to be inferred                         | ../images/bus.jpg                       |
| --cocoClassPath         | coco classes path                                 | ../models/coco.names                    |
| --staticModelPath       | static onnx filepath                              | ../models/f32\_model/yolov5s\_relu.onnx |
| --objectThreshold       | class confidence                                  | 0.25                                    |
| --nmsThreshold          | nms iou thresh                                    | 0.45                                    |
| --resPath               | result path                                       | ./Result.jpg                            |
| --calibrationPath       | calibration path for quantization                 | ../images                               |
| --action                | action: infer, quant-int8 or quant-fp16           | infer                                   |
| --modelFormat           | model format: onnx, lir or lir-compiled           | onnx                                    |
| --quantOnly             | only quantize the model                           | False                                   |
| --saveLirs              | save quantized and compiled lir models            | False                                   |
| --forceInt8Output       | force int8 output when quantizing to int8         | False                                   |
| --per-channel           | use per-channel quantization for weights          | False                                   |
| --asymmetric-activation | use asymmetric activation quantization            | False                                   |
| --expect                | expected results, e.g. --expect bus,person:3      | None                                    |
| --minConfidence         | minimum confidence threshold for expected classes | 0.5                                     |
| --no-offload-copy       | Disable offload copy during compilation           | False                                   |
| --no-exhaustive-tune    | Disable exhaustive tuning during compilation      | False                                   |
| --monitorMemory         | print peak RSS for subprocess pipeline stages     | False                                   |

### Examples

```
cd yolov5/python

# compile and run an onnx model using lacinfer
python yolov5_infer_migraphx.py
python yolov5_infer_migraphx.py --imgPath ... --staticModelPath ... --action infer --modelFormat onnx

# quantize an onnx model, and then compile and run it (and save the lir models)
python yolov5_infer_migraphx.py --action quant-int8
python yolov5_infer_migraphx.py --action quant-int8 --calibrationPath ... --saveLirs

# quantize an onnx model and save it as lir format, without compiling and running
python yolov5_infer_migraphx.py --action quant-fp16 --quantOnly

# given a lir model or compiled lir model, (compiling and) running it
python yolov5_infer_migraphx.py --modelFormat lir --staticModelPath ...
python yolov5_infer_migraphx.py --modelFormat lir-compiled --staticModelPath ...

# automatic result verification — expect specific objects
python yolov5_infer_migraphx.py --expect bus,person
python yolov5_infer_migraphx.py --expect person:3,bus:1

# custom minimum confidence threshold for expected classes
python yolov5_infer_migraphx.py --expect bus,person --minConfidence 0.3

# combined: quantize int8 with result verification
python yolov5_infer_migraphx.py --action quant-int8 --expect person:2,car:1 --minConfidence 0.3
```
