o
odinpkg.dev
packages / app / onnx-odin-squeezenet-inference-demo

onnx-odin-squeezenet-inference-demo

bdb0dc1app

Inference of SqueezeNet.onnx model on CUDA with Odin

MIT · updated 2 years ago

ONNX Odin SqueezeNet Inference Demo

This repo is a word for word (with slight enhancements) translation of ONNX C API example

  1. 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
  1. 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
  1. 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"
// ...
  1. 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
  1. 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_example

Or 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

References