Run Tensorflow 2.0 code on Tensorflow 1.x - tensorflow

I have a code that was running on colab with Tensorflow 2.0 and now I am trying to run it on a GPU with Tensorflow 1.14 and facing several errors. Is there an easy way to upgrade to tensorflow 2.0 or is it better to modify the code and make it working on the current version?

If your code is working on colab with TF 2.0, then you can uninstall TF-GPU 1.14 and install latest version of TF 2.4.
# Uninstall tensorflow
pip uninstall tensorflow-gpu == 1.14
# Requires the latest pip
pip install --upgrade pip
# Current stable release for CPU and GPU
pip install tensorflow (which install latest version of TF 2.4)
To know more details you can refer here

Related

GPU not captured by TensorFlow

I installed tensorflow using pip install tensorflow within Anaconda virtual environment on Windows.
I tried to test whether GPU is enabled, and type
import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
and got
Num GPUs Available: 0
My system does have CUDA and CUDNN enabled, as I do not have a problem installing PyTorch GPU version. How do I enable GPU for TensorFlow?
At first, uninstall tensorflow using,
pip uninstall tensorflow
Install tensorflow-gpu version,
pip install tensorflow-gpu==2.2.0
If using pip did't work you can try with conda install command.
conda install -c anaconda tensorflow-gpu
This will automatically install CUDA & cuDNN.
Hope this will solve your issue.
Remove the cpu version tensorflow using pip uninstall tensorflow and install the gpu version of the tensorflow, pip install tensorflow-gpu.
You can check this tutorial link as well.
It can be summarized by the following steps:
Uninstall your old tensorflow
Install tensorflow-gpu pip install tensorflow-gpu
Install Nvidia Graphics Card & Drivers (you probably already have)
Download & Install CUDA
Download & Install cuDNN
Verify with your program.

problem with importing tensorflow probability

I am using Anaconda and Ubuntu 18.04. I installed TensorFlow probability base on Anaconda's command:
conda install -c conda-forge tensorflow-probability
but when I wanted to import TensorFlow probability, I faced with below error:
ImportError: cannot import name 'compiler' from 'tensorflow.python.autograph.pyct' (/home/alireza/anaconda3/envs/tf-gpu/lib/python3.8/site-packages/tensorflow/python/autograph/pyct/init.py)
I check Anaconda by conda list tensorflow and TensorFlow probability version 0.8 was installed.
I appreciate your suggestion.
I think it's been a long time since the conda recipe for TFP was updated (TFP is now at 0.12), so you would need to ensure the version of TensorFlow you have is compatible. FWIW from the 0.8 release notes: "It is tested and stable against TensorFlow version 2.0.0 and 1.15.0rc1."

Installed pytorch with conda which changed my TF version to 1.13.0 now conda install tensorflow-gpu=2.0 not working?

Like I said in title I installed pytorch with conda install and that downgraded my tensorflow version to 1.13.0 and now conda install tensorflow-gpu=2.0 is not working how can I get the command to execute?
I would suggest that you try to install tensorflow with pip. pip install -U tensorflow-gpu
https://www.tensorflow.org/install/gpu
I am using pytorch, but my env has pytorch 1.2 + tensorflow 2.1
You should have installed pyTorch in another virtual environment but since now it has been installed.
I would recommend you to create a virtual environment and install TF plus other libraries in it. Because I am sure you would not use both PyTorch and TF in the same program for ML.

Is it compulsory to have GPU and CUDA to run Keras/Autokeras in Windows 10? Can it run only on CPU?

I have tried to install keras, tensorflow, pytorch and all other dependencies in order to run a simple toy example using aukeras explained in https://autokeras.com/start/
After a lot of version changes and googling I found a typical error which prompts me to ask this question -
ImportError: Could not find 'nvcuda.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Typically it is installed in 'C:\Windows\System32'. If it is not present, ensure that you have a CUDA-capable GPU with the correct driver installed.
I don't have GPU or CUDA installed. Can I still run a toy example using CPU only?
Dependencies as mentioned below :
tensorboard 1.10.0
tensorflow 1.13.1
tensorflow-estimator 1.13.0
tensorflow-gpu 1.10.0
Keras 2.2.4
Keras-Applications 1.0.7
Keras-Preprocessing 1.0.9
autokeras 0.4.0
torch 1.0.1
torchvision 0.2.1
Uninstall tensorflow-gpu, use only tensorflow if you don't have GPU.
The tensorflow is CPU only version, you don't need to install both of them but if you have both, it will choose the GPU version.
Maybe you need to reinstall the tensorflow, uninstall both of them and install only the CPU version might better.
pip[3] uninstall tensorflow-gpu tensorflow
pip[3] install tensorflow

Tensorflow import error: Naive Pip Windows 10

having problems while
screenshot given below. I want the solution badly.
import tensorflow as tf
https://i.stack.imgur.com/jgghK.png
You're using tensorflow-gpu but do not have CUDA / cuDNN installed on your computer.
Shor answer: run pip unintall tensorflow-gpu and pip install tensorflow.
Long answer: Install CUDA / cuDNN