Search code examples
pythontensorflowtensorrt

TensorRT 5.1 has no attribute create_inference_graph


I want to optimize my neural network (Resnet101 from Google) for inference with TensorRT (ver. 5.1). I've been looking for blogs and tutorials how to do it and found some stuff like here and a few other. All of them have one common thing:

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")

But the problem is that my version of TensorRT does not have such function. I get an output as below.

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'

Does anyone know if that function was replaced with other in version 5.1 of TensorRT? How to run it?


Solution

  • As @Uziel suggested Tensorrt should be used with:

    import tensorflow.contrib.tensorrt as trt

    Unfortunately in my case that import caused a following error:

    tensorflow.python.framework.errors_impl.NotFoundError: libnvinfer.so.4: cannot open shared object file: No such file or directory

    There was a problem with my installation of TensorRT. After reinstalling everything it works now.