Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,11 @@ python scripts/gradio_demo.py \
> [!TIP]
> Live inference is provided as an independent script so that you can load this script into any deployment devices without having to install all the (large) dependencies in this repo. The script only requires `onnxruntime`, `cv2` and `numpy` to run.

There are two live inference scripts:

1. `live_inference.py` - Run live inference on a video, image or webcam using ONNXRuntime. This script requires a pre-exported ONNX model.
2. `live_inference_pretrained.py` - Automatically download the pretrained model, convert to ONNX, and run inference in one go.

Run live inference on a video, image or webcam using ONNXRuntime. This runs on CPU by default.
If you would like to use the CUDA backend, install the `onnxruntime-gpu` package and uninstall the `onnxruntime` package.

Expand Down Expand Up @@ -378,6 +383,18 @@ Webcam video width at 320x240 pixels (240p):
https://github.com/user-attachments/assets/f4afff9c-3e6d-4965-ab86-0d4de7ce1a44


To run live inference with pretrained model on webcam, use the following command
```bash
python scripts/live_inference_pretrained.py --webcam
```
This downloads the pretrained model, converts it to ONNX, and runs inference on the webcam. All other arguments are optional but they are similar to the `live_inference.py` script.

The output is as follows


https://github.com/user-attachments/assets/5aca6044-db81-4988-937e-2447a7cbe06e




For video inference, specify the path to the video file as the input. Output video will be saved as `onnx_result.mp4` in the current directory.
Expand All @@ -393,7 +410,12 @@ python scripts/live_inference.py
```
https://github.com/user-attachments/assets/6bc1dc6a-a223-4220-954d-2dab5c75b4a8

The following is an inference using the pre-trained model `deim_hgnetv2_x` trained on COCO. See how I exported the pre-trained model to onnx in this notebook [here](nbs/export.ipynb).

The following is an inference using the pre-trained model `deim_hgnetv2_x` trained on COCO.

```bash
python scripts/live_inference_pretrained.py --model deim_hgnetv2_x --video video.mp4
```

https://github.com/user-attachments/assets/77070ea4-8407-4648-ade3-01cacd77b51b

Expand Down Expand Up @@ -473,6 +495,11 @@ pixi run -e cuda live-inference --onnx model.onnx --webcam --provider cuda --cla
pixi run -e cpu live-inference --onnx model.onnx --input video.mp4 --class-names classes.txt --inference-size 320
```

Live inference with pretrained model on webcam
```bash
pixi run -e cuda live-inference-pretrained --webcam
```

Launch Gradio app
```bash
pixi run gradio-demo --model "best_prep.onnx" --classes "classes.txt" --examples "Rock Paper Scissors SXSW.v14i.coco/test"
Expand Down
387 changes: 310 additions & 77 deletions nbs/pretrained-model-inference.ipynb

Large diffs are not rendered by default.

276 changes: 1 addition & 275 deletions pixi.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies = [
"calflops>=0.3.2,<0.4",
"transformers>=4.49.0,<5",
"opencv-python>=4.11.0.86,<5",
"gdown>=5.2.0,<6",
"loguru>=0.7.3,<0.8",
"matplotlib",
"onnx>=1.17.0,<2",
Expand Down Expand Up @@ -66,6 +65,7 @@ default = { features = ["cpu"] }
[tool.pixi.tasks]
quickstart = "python scripts/quickstart.py"
live-inference = "python scripts/live_inference.py"
live-inference-pretrained = "python scripts/live_inference_pretrained.py"
train-model = "python scripts/train.py"
gradio-demo = "python scripts/gradio_demo.py"
export = "python scripts/export.py"
Loading