https://github.com/victorbadenas/SimpleOnnxInference
A simple c++ onnx application for inferencing images
https://github.com/victorbadenas/SimpleOnnxInference
convolutional-neural-networks deep-learning deep-neural-networks onnxruntime
Last synced: about 2 months ago
JSON representation
A simple c++ onnx application for inferencing images
- Host: GitHub
- URL: https://github.com/victorbadenas/SimpleOnnxInference
- Owner: victorbadenas
- License: apache-2.0
- Created: 2021-12-21T10:46:34.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-01-27T17:10:44.000Z (over 3 years ago)
- Last Synced: 2024-10-27T23:23:34.401Z (7 months ago)
- Topics: convolutional-neural-networks, deep-learning, deep-neural-networks, onnxruntime
- Language: C++
- Homepage:
- Size: 44.8 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleOnnxInference




## install requirements
For this project we need opencv and onnx. OpenCV needs to be built from source. For this project we will be using the v3.4.1 tag in their [repository](https://github.com/opencv/opencv/tree/3.4.16).
### Ubuntu
For ubuntu installation, follow or run the [installRequirements.sh](scripts/installRequirements.sh) bash script.
```bash
./scripts/installRequirements.sh
```### MacOS
For macos installation, follow or run the [installRequirementsOsx.sh](scripts/installRequirementsOsx.sh) bash script.
```bash
./scripts/installRequirementsOsx.sh
```## Loading a sample model from torchvision for imagenet classification
This repository provides a [getTorchvisionModel.py](scripts/getTorchvisionModel.py) python script to load and export a model present in the torchvision package to onnx format. For running the python script create an environment and install the requirements in [requirements.txt](requirements.txt). Then simply run the file as follows:
```bash
python3 scripts/getTorchvisionModel.py -m ${modelArch} -O 13 -o ${outFolder} -i 3 224 224
```where `-i 3 224 224` corresponds to the size of the input to the network.
## Build
To build, install the conan packages (`cxxopts`):
```bash
conan install -if build/ .
```Then configure the cmake project:
```bash
cmake -DONNXRUNTIME_ROOTDIR="~/.local/include/onnxruntime" -DOpenCV_DIR="/usr/local/share/OpenCV" -S . -B build/
```And build:
```bash
cmake --build build/
```## Run
The binary is stored in the `./build/bin/` folder. It requires the modelPath (onnx format), the imagepath (jpeg format). the label file is optional but highly encouraged as it provides the output label in human-readable format.
```bash
./build/bin/main -m ${modelPath} -i ${imagePath} -l ${labelPath} -d
```The label file must be a plain text file where each line corresponds to the label of the line index where is located. for instance, for a 3 class classification, the label file would be as follows:
```text
class1
class2
class3
```