This repo is a word for word (with slight enhancements) translation of ONNX C API example
- Download ONNX library
export ONNXRUNTIME_VERSION=1.17.3
curl https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}.tgz -Lso onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}.tgz
tar -xvf onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION}.tgz && \
mv onnxruntime-linux-x64-gpu-${ONNXRUNTIME_VERSION} /thirdparty/onnxruntime- Get ONNX-Odin bindings
export ONNXRUNTIME_VERSION=1.17.3
curl https://raw.githubusercontent.com/yevhen-k/onnx-odin-bindings/ONNX-${ONNXRUNTIME_VERSION}_OdinLinux-0.0.1/onnxbinding.odin -Lso onnxbinding.odin- Edit onnxbinding.odin if necessary to adjust package name or foreign import of
libonnxruntime.so
// ...
package onnx_bindings
// ...
when ODIN_OS == .Linux do foreign import onnx "/thirdparty/onnxruntime/lib/libonnxruntime.so"
// ...- Get SqueezeNet model (using squeezenet version 1.3)
curl https://github.com/onnx/models/raw/main/validated/vision/classification/squeezenet/model/squeezenet1.0-8.onnx -Lso squeezenet1.0-8.onnx- Build and run
With the use of rpath:
cd ..
odin build onnx-odin-squeezenet-inference-demo -extra-linker-flags:"-Wl,-rpath=/thirdparty/onnxruntime/lib/" -out:onnx-odin-squeezenet-inference-demo/odin_onnx_example
cd onnx-odin-squeezenet-inference-demo && ./odin_onnx_exampleOr with the use of LD_LIBRARY_PATH:
cd ..
odin build onnx-odin-squeezenet-inference-demo -out:onnx-odin-squeezenet-inference-demo/odin_onnx_example
cd onnx-odin-squeezenet-inference-demo && LD_LIBRARY_PATH=/thirdparty/onnxruntime/lib/ ./odin_onnx_example- Model squeezenet.onnx: https://github.com/onnx/models/tree/main/validated/vision/classification/squeezenet
- ONNX C API example: https://github.com/microsoft/onnxruntime/blob/v1.4.0/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/C_Api_Sample.cpp
- ONNX Odin bindings: https://github.com/yevhen-k/onnx-odin-bindings