ONNX simple sample: Difference between revisions
Maumontero (talk | contribs) No edit summary |
Maumontero (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
__TOC__ | __TOC__ | ||
= Introduction = | = Introduction = | ||
On this page, you are going to find the steps to install ONXX and ONXXRuntime and run a simple C/C++ | On this page, you are going to find the steps to install ONXX and ONXXRuntime and run a simple C/C++ example on Linux. This wiki page tries to describe the importance of ONNX models and how to use it. The goal is to provide you some examples. | ||
= Installing ONNX = | = Installing ONNX = | ||
Line 19: | Line 19: | ||
= Installing ONNXRuntime = | = Installing ONNXRuntime = | ||
This guide | This guide builds the baseline CPU version of ONNXRuntime form source, to build it from the source code using the following commands: | ||
<pre> | <pre> | ||
Line 50: | Line 50: | ||
</pre> | </pre> | ||
= | = Example = | ||
This guide is for using an ONNXRuntime C/C++ code on | This guide is for using an ONNXRuntime C/C++ code on Linux, for that reason only the SqueezeNet examples are build it. | ||
== Build == | == Build == | ||
First go to the path with the C/C++ code | First go to the path with the C/C++ code examples. | ||
<pre> | <pre> | ||
cd onnxruntime/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/ | cd onnxruntime/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/ | ||
Line 73: | Line 73: | ||
</pre> | </pre> | ||
Running this | Running this example you will get the following output: | ||
<pre> | <pre> |
Revision as of 16:49, 20 November 2019
Introduction
On this page, you are going to find the steps to install ONXX and ONXXRuntime and run a simple C/C++ example on Linux. This wiki page tries to describe the importance of ONNX models and how to use it. The goal is to provide you some examples.
Installing ONNX
You can then install ONNX from PyPi with the following command:
sudo pip install onnx
You can also build and install ONNX locally from source code:
git clone https://github.com/onnx/onnx.git cd onnx git submodule update --init --recursive python setup.py install
Installing ONNXRuntime
This guide builds the baseline CPU version of ONNXRuntime form source, to build it from the source code using the following commands:
git clone --recursive https://github.com/Microsoft/onnxruntime -b v1.0.0 cd onnxruntime
Before install onnxruntime you need to install CMake 3.13 or higher.
sudo -H pip3 install cmake
After install CMake run the following command for build onnxruntime:
./build.sh --config RelWithDebInfo --build_shared_lib --parallel
Finally, install it:
cd build/Linux/RelWithDebInfo sudo make install
Because this test is on Linux you need to copy the .so file to general lib path:
cp libonnxruntime.so /usr/lib/x86_64-linux-gnu/
Example
This guide is for using an ONNXRuntime C/C++ code on Linux, for that reason only the SqueezeNet examples are build it.
Build
First go to the path with the C/C++ code examples.
cd onnxruntime/csharp/test/Microsoft.ML.OnnxRuntime.EndToEndTests.Capi/
After that build the code:
g++ -o Capi_sample C_Api_Sample.cpp -I $PATHTOONNXRUNTIMESESSION (#CHOOSE THE APPROPRIATE PATH TO onnxruntime/include/onnxruntime/core/session) -lonnxruntime -std=c++14
Run
Finally just run the code:
./Capi_sample
Running this example you will get the following output:
Using Onnxruntime C API Number of inputs = 1 Input 0 : name=data_0 Input 0 : type=1 Input 0 : num_dims=4 Input 0 : dim 0=1 Input 0 : dim 1=3 Input 0 : dim 2=224 Input 0 : dim 3=224 Score for class [0] = 0.000045 Score for class [1] = 0.003846 Score for class [2] = 0.000125 Score for class [3] = 0.001180 Score for class [4] = 0.001317 Done!