.. _l-cpp-export-nnef-example: Standalone C++ example: export an ONNX model to NNEF ==================================================== This page documents ``examples/export_nnef`` (`view on GitHub `_), a self-contained CMake project that demonstrates how to export an ONNX :cpp:class:`ModelProto` to the `Khronos NNEF v1.0 `_ representation from C++. The NNEF exporter is **not** part of the *onnx-light* package itself: the example ships its own implementation under ``examples/export_nnef/nnef/`` (``tensor_io.{h,cc}`` for the NNEF 128-byte-header binary tensor reader / writer, and ``exporter.{h,cc}`` for the ONNX → NNEF graph translator with builtin op converters for ``Conv``, ``BatchNormalization``, ``MaxPool``/``AveragePool``, the elementwise math/logical/comparison ops, ``Gemm``, ``MatMul``, ``Reshape``, ``Flatten``, ``Transpose``, ``Concat``, ``Identity`` and ``Clip``). Only the proto layer of *onnx-light* (``onnx_light::lib_onnx_proto``) is linked, to load and walk the ONNX ``ModelProto``. Step 1 – Install the C++ library --------------------------------- From the *onnx-light* repository root, build and install the static library and its public headers. The Python extension is not required: .. code-block:: bash cmake -S . -B build-install \ -DCMAKE_BUILD_TYPE=Release \ -DONNX_LIGHT_BUILD_PYTHON=OFF \ -DCMAKE_INSTALL_PREFIX=/usr/local cmake --build build-install cmake --install build-install Step 2 – Build the example --------------------------- Point ``CMAKE_PREFIX_PATH`` at the install prefix chosen above: .. code-block:: bash cmake -S examples/export_nnef -B build-export-nnef \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_PREFIX_PATH=/usr/local cmake --build build-export-nnef Step 3 – Run the example ------------------------- .. code-block:: bash ./build-export-nnef/export_nnef path/to/model.onnx path/to/out_nnef The output directory is created if needed and is populated with a ``graph.nnef`` text file plus one ``