https://github.com/myatmyintzuthin/libtorch-inference
https://github.com/myatmyintzuthin/libtorch-inference
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/myatmyintzuthin/libtorch-inference
- Owner: myatmyintzuthin
- License: apache-2.0
- Created: 2023-02-07T04:37:01.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-27T10:15:42.000Z (9 months ago)
- Last Synced: 2025-02-03T21:34:38.978Z (5 months ago)
- Language: C++
- Size: 202 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# torchlib-inference



This repo consists of C++ libtorch inference implementation for pytorch classification model.
### Install Dependencies
1. Download libtorch distribution from [official website](https://pytorch.org/get-started/locally/). libtorch version used in this repo [link](https://download.pytorch.org/libtorch/cpu/libtorch-cxx11-abi-shared-with-deps-2.0.0%2Bcpu.zip).
2. Unzip the downloaded file and store `libtorch` folder in `external_packages` folder. If `external_packages` folder doesn't exit, create one.
3. Install OpenCV: follow the installation instructions in this [guide](https://github.com/myatmyintzuthin/extract-table/blob/C%2B%2B/Installation_Guide.md).### Run inference
- Before running inference, the pytorch model should be converted to script model. Reference, [trace_model.py](https://github.com/myatmyintzuthin/jpfood-classification-pytorch/blob/master/trace_model.py).
- Build cmake:
```
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=/path/to/libtorch ..
cmake --build . --config Release
```
- run inference, inside `build` folder:
```
./libtorch --model_path ../script_model/resnet_food_script.pt --image_path ../test-images/sushi.jpg
```### Results
```
Finish model loading ...
Finish image processing ...
---------------------------------------
Predicted class = Sushi | confidence = 0.999214
```