我想优化我的神经网络(来自Google的Resnet101)以使用TensorRT(5.1版)进行推理。我一直在寻找如何做到这一点的博客和教程,并发现了诸如here之类的一些东西。他们都有一件共同的事情:
trt_graph = trt.create_inference_graph(
getNetwork(network_file_name),
outputs,
max_batch_size=batch_size,
max_workspace_size_bytes=workspace_size,
precision_mode=”INT8")
但是问题是我的TensorRT版本没有此功能。我得到的输出如下。
Python 3.6.6 |Anaconda custom (64-bit)
>>> import tensorrt as trt
>>> trt.__version__
5.1.2.2
>>> trt.create_inference_graph()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorrt' has no attribute 'create_inference_graph'
有人知道该功能是否在TensorRT版本5.1中被其他功能取代吗?如何运行?
答案 0 :(得分:1)
某些tensorflow安装默认已经具有tensorrt。尝试;
import tensorflow.contrib.tensorrt as trt
答案 1 :(得分:0)
如@Uziel所建议,Tensorrt应该与以下对象一起使用:
import tensorflow.contrib.tensorrt as trt
不幸的是,在我的情况下,导入导致了以下错误:
tensorflow.python.framework.errors_impl.NotFoundError: libnvinfer.so.4: cannot open shared object file: No such file or directory
我的TensorRT安装存在问题。重新安装所有内容后,它现在可以正常工作。
答案 2 :(得分:0)
这也是另一个可以导入 tensorrt 的位置
from tensorflow.python.compiler.tensorrt import trt_convert as trt