Ubuntu で onnxruntime をインストールしてコンパイルする

onnxruntime は、Linux、Windows、Mac、および組み込みデバイスに適した onnx 形式の機械学習モデル用の高性能推論エンジンです。

このブログでは、onnxruntime のコンパイル手順と、このプロセスで発生した問題と解決策を記録します。

1 ダウンロード

git clone --depth 1 --branch v1.12.1 --recursive https://github.com/Microsoft/onnxruntime

ダウンロード中に発生した問題とその解決策の記録

  1. 致命的: ' https://github.com/...' にアクセスできません: OpenSSL SSL_read: 接続が中止されました、エラー番号 10053

sslネットワーク認証を解除する必要がある場合、

git config --global http.sslVerify false
  1. ダウンロード速度に関係する

git clone の速度が遅すぎる場合は、次のブログを参照して修正してください。

https://www.cnblogs.com/isLinXu/p/16990977.html

それでもクローンできない場合は、次の公式 Web サイトのリンクから公式バイナリ ファイルを直接ダウンロードすることをお勧めします。

https://github.com/microsoft/onnxruntime/tags

マシンの cuda および cudnn バージョンを参照して、インストールされている onnxruntime バージョンを選択できます。対応関係は次のとおりです。

https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html

  1. エラー: RPC が失敗しました。カール 92 HTTP/2 ストリーム 5 が終了前に正常に閉じられませんでした

解決策 1 (git の http バージョンを置き換える):

git config --global http.version HTTP/1.1

解決策 2 (git バッファのサイズを増やす):

git config --global http.postBuffer 524288000
  1. 21052 ミリ秒後にgithub.comポート 443に接続できませんでした: タイムアウトしました

これは、git ポートとシステム プロキシの違いが原因で発生します。

まず、[設定] -> [ネットワークとインターネット] -> [プロキシ] を開き、現在のプロキシのアドレスとポート番号を記録します。

次に、git のアドレスとポートを変更します。

git config --global http.proxy http://[地址]:[端口]
git config --global https.proxy http://[地址]:[端口]

2 コンパイル

GPU バージョンをコンパイルする

./build.sh --skip_tests --use_cuda --config Release --build_shared_lib --parallel --cuda_home [你的cuda安装目录] --cudnn_home [你的cuda安装目录]

このうち --use_cuda は onnxruntime の GPU バージョンを使用することを意味し、--cuda_home、--cudnn_home はすべて cuda をインストールしたディレクトリ (「/usr/local/cuda-11.4」など) を指します。

onnxruntime と cuda および cudnn の対応するバージョンとの関係については、次の公式推奨事項を参照してください。

https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html

CPUのバージョンをコンパイルする

./build.sh --skip_tests --config Release --build_shared_lib

TensorRT バージョンをコンパイルする

./build.sh \
    --parallel 8 \
    --use_cuda \
    --cuda_version=11.1 \
    --cuda_home=[你的cuda安装目录] \
    --cudnn_home=[你的cuda安装目录] \
    --use_tensorrt \
    --tensorrt_home=[你的tensorrt安装目录] \
    --build_shared_lib --enable_pybind \
    --build_wheel --update --build \
    --config Release

おすすめ

転載: blog.csdn.net/qq_38964360/article/details/129755345