问题
I have installed the Tensorflow r1.14
and want to use TF-TRT
. However, the following error occurs:
"ModuleNotFoundError: No module named 'tensorflow.contrib.tensorrt'"
when running the sample code. The same error occurs with Tensorflow r1.13
. So my question is do I need to install the tensorflow.contrib.tensorrt
library separately? If yes, how?
Additionally, I can run the sample code of the TensorRT
, e.g. sampleINT8
, successfully. Click here to see my successful sample code run.
This leads me to believe that TensorRT
is installed properly. However, the TF-TRT
still doesn't work.
Any help would be greatly appreciated!
回答1:
In TF 1.14, TF-TRT was moved to the core from contrib.
You need to import it like this:
from tensorflow.python.compiler.tensorrt import trt_convert as trt
https://github.com/tensorflow/tensorrt/blob/master/tftrt/examples/image-classification/image_classification.py#L22
回答2:
In order to be able to import tensorflow.contrib.tensorrt
you need to have tensorflow-gpu
version >= 1.7 installed on your system. Maybe you could try installing the tensorflow-gpu
library with a:
pip install tensorflow-gpu
Check out the Windows section of the GPU documentation as well. Also, I would try updating your tensorflow
version with a:
pip install --upgrade tensorflow
to ensure you're up to date there as well. Check out this section of the TensorFlow documentation for additional support.
Hopefully that helps!
回答3:
2 possibilities
- Have you installed tensorflow-gpu instead of tensorflow?
- From your screenshot it looks like you're using Windows. I had the same problem. There seems no
tensorrt
module undercontrib
in TF windows distribution however linux has it (I tried 1.13.1).
回答4:
In TF 1.14, TF-TRT was moved to the core from contrib.
You need to import it like this: from tensorflow.python.compiler.tensorrt import > trt_convert as trt
https://github.com/tensorflow/tensorrt/blob/master/tftrt/examples/image-classification/image_classification.py#L22
This is the correct answer for Linux.
However, if you're using Windows: the TensorRT Python API (and therefore TF-TRT) is not supported for Windows at the moment, so the TensorFlow python packages aren't built with TensorRT.
来源:https://stackoverflow.com/questions/55523680/failed-to-import-tensorflow-contrib-tensorrt-in-tensorflow-r1-14