Failed to import 'tensorflow.contrib.tensorrt' in tensorflow r1.14 - tensorflow

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!

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.

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

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!

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 under contrib in TF windows distribution however linux has it (I tried 1.13.1).

Related

Colab SpaCy | PyTorch NameError: name '_C' is not defined

Trying to import spacy into Google Colab but getting an error name '_C' is not defined. Is it problem with the torch somewhere inside?
torch version: 1.13.1
spacy version: 3.5.0
I've tried to upgrade spacy and cython, but it didn't work. What should I do?
As I said I've tried solutions from here, here and here
When I'm trying to downgrade numpy I'm getting a dependency error with scipy.
I've also tried to install torch 1.9.0 as in here but it also didn't work.
And I've tried to downgrade to spacy 3.4.3 which runs perfectly on my local machine -- didn't work.
UPD: just discovered that importing torch shows same error
UPD_2: this happened when I've uploaded my own notebook. When I open a new clear notebook -- everything works just fine.

Cannot import Tensorflow

I can't import tensorflow, even after checking all dependencies. I'm getting an error message 'ModuleNotFoundError: No module named 'tensorflow'' when importing 'import tensorflow as tf' in vs code
I installed tensorflow through conda with 'conda install tensorflow'. It seems to have worked, since when I use 'pip show tensorflow', it shows up as 'version 2.10.0'. Moreover, my Python version is '3.9.15', so it should be compatible. I've been looking all over and no other installatoins have been working. Any suggestions?
Please try again by using Python version 3.10 as Python 3.9 shows some version errors in VS code.
Please check this link to install TensorFlow in VScode.

TensorFlow2 keeps installing the same version

I'm trying to run a program in my Raspberry but i can't because it needs at least TensorFlow 2.2.0, while I have TensorFlow 2.0.0 . I tried several times to install TensorFlow 2.2.0 and 2.3.0 . But after install it, it always comes that is 2.0.0 still.
Versions of TensorFlow
Somebody can tell me what happens? Thank you!!
Try to find the package in the /python3.x/site-packages and remove the tensorflow directory using rm.
Then install the needed tensorflow version following the installation instruction found here in the official documentation of tensorflow.
Also attaching the image from the comment of #pablo Gracia S.

Problem with importing tensorflow and testing NN

I'm currently working on a program to play a game similar to atari-games. I'm using keras (python 3). I finished writing the code and I want to test it, and I have few questions about the process:
first of all, I have trouble importing tesnorflow for some reason. I've installed it using pip. I've made sure to created new env. before the installation (which finished successfully), but when I try to run my program it says:
ModuleNotFoundError: No module named 'tensorflow'
I also, tried to install the package from within pycharm, but then I get this error:
Could not find a version that satisfies the requirement tensorflow (from versions: )
No matching distribution found for tensorflow
I've checked program requirements (such as pip, python, virtualenv and setuptools versions) and everything seems up to date. perhaps someone could point out what else might be the problem?
Is there any other way I can test the performance of my program?
Thank you very much for your time and attention.
Anaconda is a complete time-saver. I suggest create an enviornment using Anaconda and install the tensorflow by conda install tensorflow If you would like to use the gpu version, conda automatically installs the CUDA and cudnn for you too.

Python 3.6 Tensor Flow: Cannot import name 'nccl_ops'

I am trying to test NVIDIA's Style GAN and am encountering an error when trying to run the pretrained_example.py file.
I get an import error from the line from tensorflow.python.ops import nccl_ops
ImportError: cannot import name 'nccl_ops'
I think I installed all the prerequisites properly and am using python 3.6. It could be a mac tensorflow issue possibly because it doesn't mention OSX on the github project. Any help would be appreciated. It might be a matter of installing a different version of tensorflow or something else, I'm not sure.
I updated tensorflow and it solved this issue