开放神经网络交换(ONNX)工具
开放神经网络交换(ONNX)是一个开放的生态系统,它使人工智能开发人员能够在项目发展过程中选择正确的工具。ONNX为人工智能模型提供了一种开源格式,包括深度学习和传统ML,它定义了一个可扩展的计算图模型,以及内置运算符和标准数据类型的定义。目前我们关注的是推断(评分)所需的能力。
ONNX受到广泛支持,可以在许多框架、工具和硬件中找到。实现不同框架之间的互操作性和简化从研究到生产的路径有助于提高人工智能社区的创新速度。
参考链接:https://github.com/onnx/onnx
Use ONNX
Learn about the ONNX spec
Programming utilities for working with ONNX Graphs
ONNX_ML=1 for onnx-ml):USE_MSVC_STATIC_RUNTIME (should be 1 or 0, not ON or OFF)ONNX_USE_PROTOBUF_SHARED_LIBS, Protobuf_USE_STATIC_LIBSONNX_USE_PROTOBUF_SHARED_LIBS is ON then Protobuf_USE_STATIC_LIBS must be OFF and USE_MSVC_STATIC_RUNTIME must be 0.ONNX_USE_PROTOBUF_SHARED_LIBS is OFF then
Protobuf_USE_STATIC_LIBS must be ON and USE_MSVC_STATIC_RUNTIME can be 1 or 0.import onnx command
does not work from the source checkout directory; in this case you‘ll see ModuleNotFoundError: No module named
‘onnx.onnx_cpp2py_export‘. Change into another directory to fix
this error./lib with /lib64.DEBUG=1. For debug versions of the dependencies,
you need to open the CMakeLists
file and append a letter d at the end
of the package name lines. For example, NAMES
protobuf-lite would become NAMES
protobuf-lited.·conda install -c conda-forge onnx
·# Use conda-forge protobuf, as default doesn‘t come with protoc
·conda install -c conda-forge protobuf numpy
·pip install onnx
·git clone https://github.com/onnx/onnx.git
·cd onnx
·git submodule update --init --recursive
·python setup.py install
·sudo apt-get install protobuf-compiler libprotoc-dev
·pip install onnx
·git clone https://github.com/protocolbuffers/protobuf.git
·cd protobuf
·git checkout 3.9.x
·cd cmake
·# Explicitly set -Dprotobuf_MSVC_STATIC_RUNTIME=OFF to make sure protobuf does not statically link to runtime library
·cmake -G "Visual Studio 15 2017 Win64" -Dprotobuf_MSVC_STATIC_RUNTIME=OFF -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_EXAMPLES=OFF -DCMAKE_INSTALL_PREFIX=<protobuf_install_dir>
·msbuild protobuf.sln /m /p:Configuration=Release
·msbuild INSTALL.vcxproj /p:Configuration=Release
·# Get ONNX
·git clone https://github.com/onnx/onnx.git
·cd onnx
·git submodule update --init --recursive
·
·# Set environment variables to find protobuf and turn off static linking of ONNX to runtime library.
·# Even better option is to add it to user\system PATH so this step can be performed only once.
·# For more details check https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2017
·set PATH=<protobuf_install_dir>\bin;%PATH%
·set USE_MSVC_STATIC_RUNTIME=0
·
·# Optional: Set environment variable `ONNX_ML=1` for onnx-ml
·
·# Build ONNX
·python setup.py install
·# Use conda-forge protobuf
·conda install -c conda-forge numpy libprotobuf=3.11.3 protobuf
·
·# Get ONNX
·git clone https://github.com/onnx/onnx.git
·cd onnx
·git submodule update --init --recursive
·
·# Set environment variable for ONNX to use protobuf shared lib
·set USE_MSVC_STATIC_RUNTIME=0
·set CMAKE_ARGS="-DONNX_USE_PROTOBUF_SHARED_LIBS=ON -DProtobuf_USE_STATIC_LIBS=OFF -DONNX_USE_LITE_PROTO=ON"
·
·# Build ONNX
·# Optional: Set environment variable `ONNX_ML=1` for onnx-ml
·
·python setup.py install
·pip install cython protobuf numpy
·sudo apt-get install libprotobuf-dev protobuf-compiler
·pip install onnx
·python -c "import onnx"
·pip install pytest nbval
·pytest
原文:https://www.cnblogs.com/wujianming-110117/p/14088450.html