目录
1. conda_py37.yaml文件
2. 命令行安装
3. 效果
4. 代码测试环境
配置环境cuda10.2,onnx1.8.0,onnxruntime-gpu=1.6.0
其他版本对应关系:
CUDA - onnxruntimeInstructions to execute ONNX Runtime applications with CUDAhttps://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html
name: test_onnx
channels:
- Esri
- conda-forge
- defaults
dependencies:
- _pytorch_select=1.2.0=gpu
- blas=1.0=mkl
- ca-certificates=2021.5.25=haa95532_1
- certifi=2021.5.30=py37haa95532_0
- cffi=1.14.5=py37hd8e9650_0
- cudatoolkit=10.2.89=h74a9793_1
- intel-openmp=2019.4=245
- libblas=3.8.0=14_mkl
- libcblas=3.8.0=14_mkl
- liblapack=3.8.0=14_mkl
- libmklml=2019.0.5=haa95532_0
- libprotobuf=3.14.0=h7755175_0
- mkl=2019.4=245
- mkl-service=2.3.0=py37hfa6e2cd_0
- ninja=1.10.2=h5362a0b_0
- numpy=1.20.3=py37hcbcd69c_1
- onnx=1.8.0=py37hb2e8ee1_1
- openssl=1.1.1k=h2bbff1b_0
- pip=21.1.2=pyhd8ed1ab_0
- protobuf=3.14.0=py37hf2a7229_1
- pycparser=2.20=pyh9f0ad1d_2
- python=3.7.10=0
- python_abi=3.7=1_cp37m
- setuptools=49.6.0=py37h03978a9_3
- six=1.15.0=py_0
- sqlite=3.35.5=h8ffe710_0
- tbb=2021.2.0=h2d74725_0
- typing-extensions=3.10.0.0=hd8ed1ab_0
- typing_extensions=3.10.0.0=pyha770c72_0
- vc=14.1=h869be7e_1
- vs2015_runtime=14.16.27012=hf0eaf9b_0
- wheel=0.36.2=pyhd3deb0d_0
- wincertstore=0.2=py37h03978a9_1006
- zlib=1.2.11=h62dcd97_1010
- pip:
- altgraph==0.17
- flatbuffers==2.0
- future==0.18.2
- importlib-metadata==4.5.0
- onnxruntime-gpu==1.6.0
- opencv-contrib-python==4.5.2.52
- opencv-python==4.5.2.52
- pefile==2021.5.24
- pyinstaller==4.3
- pyinstaller-hooks-contrib==2021.1
- pylibdmtx==0.1.9
- pywin32-ctypes==0.2.0
- zipp==3.4.1
prefix: D:\ProgramData\Anaconda3\envs\test_onnx
# 安装
conda env create -f conda_py37.yaml
# 激活环境
conda activate test_onnx
# 确认环境
conda list
下载onnx权重进行测试
alexnet.onnx权重-互联网文档类资源-CSDN下载生成该权重代码:importtorchimporttorchvision#useTr更多下载资源、学习资料请访问CSDN下载频道.https://download.csdn.net/download/jizhidexiaoming/80233035
import time
import onnx
import numpy as np
import onnxruntime as ort
# load onnx model
model = onnx.load_model('alexnet.onnx')
onnx.checker.check_model(model=model)
onnx.helper.printable_graph(graph=model.graph)
# onnx_runtime val
# sess_options = ort.SessionOptions()
# sess_options.graph_optimization_level = ort.GraphOptimizationLevel.ORT_DISABLE_ALL
# sess_options.optimized_model_filepath = "optimized_mnist_original.onnx"
# session = ort.InferenceSession("mnist_original.onnx", sess_options)
ort_session = ort.InferenceSession("alexnet.onnx")
while 1:
start = time.time()
outputs = ort_session.run(None, {'inputs': np.random.randn(10, 3, 224, 224).astype(np.float32)}) # inputs is same to orig
print(time.time() - start)