Python 3.6 Tensor Flow: Cannot import name 'nccl_ops' - tensorflow

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

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.

ModuleNotFoundError : import tensorflow.compat.v1 as tf

import tensorflow.compat.v1 as tf
Error displayed in vscode
output in jupyter
Despite trying all the possible options, I am not able to fix this error.
I am trying to learn machine learning to create a simple sign language detection system. In my VSCode, the above image is displayed.
You need to follow the instructions mentioned in this link to install the tensorflow then open the VS code in the same virtual environment.
Please check these similar issues for your reference.

Unable to import Keras(from TensorFlow 2.0) in PyCharm 2019.2

I have just installed the stable version of TensorFlow 2.0 (released on October 1st 2019) in PyCharm.
The problem is that the keras package is unavailable.
The actual error is :
"cannot import name 'keras' from tensorflow"
I have installed via pip install tensorflow==2.0.0 the CPU version, and then uninstalled the CPU version and installed the GPU version , via pip install tensorflow-gpu==2.0.0.
Neither of the above worked versions of TensorFlow were working properly(could not import keras or other packages via from tensorflow.package_X import Y).
If I revert TensorFlow to version 2.0.0.b1, keras is available as a package (PyCharm recognises it) and everything runs smoothly.
Is there a way to solve this problem? Am I making a mistake in the installation process?
UPDATE --- Importing from the Python Console works and allows the imports without any error.
For PyCharm Users
For those who use PyCharm. Install future (EAP) release 2019.3 EAP build 193.3793.14 from here. With that, you will be able to use autocomplete for the current stable release of TensorFlow (i.e. 2.0). I have tried it and it works :).
For other IDEs
For users with other IDEs, this will be resolved only after the stable version is released, which is anyways the case now. But this might take some more time for a fix. See the comment here. I assume it will be wise to wait and keep using version 2.0.0.b1. On the other hand avoid imports from tensorflow_core if you do not want to refactor your code in the future.
Note: for autocomplete to work use import statement as below
import tensorflow.keras as tk
# this does not work for autocomplete
# from tensorflow import keras as tk
The autocomplete works for TensorFlow 2.0.0 on CPU version, but the autocomplete does not work for the GPU version.
SOLVED --- See the answers to this problem below.
SOLUTION 1 (best solution)
Is the accepted answer provided above. It works on EAP version, I tested it on several machines with Windows.
SOLUTION 2
Although PyCharm does not recognise the modules, running the .py file works. I still do not know if this is a problem of TensorFlow or PyCharm, but this is the solution that I have found, many people have run into this problem.
SOLUTION 3
Import the modules from tensorflow_core instead of tensorflow
Example: from tensorflow_core.python.keras.preprocessing.image import ImageDataGenerator
However, as mentioned by #Nagabhushan S N in the comment below and above in the accepted answer:
On the other hand avoid imports from tensorflow_core if you do not
want to refactor your code in the future.

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

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