Tensorflow 1.15 + CUDA + cuDNN installation using Conda - tensorflow

I am trying to install tensorflow-gpu 1.15 using Conda for an easy install of CUDA and cuDNN. The problem is that checking the compatibility chart of the official web I need python 3.6, CUDA 10.0 and cuDNN 7.4.
Searching the Conda rep via conda search cudnn it says that there isn't cuDNN 7.4. Is there any other way to install the required packages? Or maybe tensorflow 1.15 also works with other combinations of versions?
As a side note, python 3.6, tensorflow-gpu 1.15 and CUDA 10 install correctly, but it seems I can't use the GPU correctly without cuDNN.
I just recently started using Conda, so maybe there is a straight forward way to do this that I don't realize. My Conda version is 4.9.1 (miniconda version).
---update---
Just in case I add the error while trying conda create -n myenv -c conda-forge tensorflow-gpu=1.15:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: -
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed
UnsatisfiableError: The following specifications were found to be incompatible with each other:
Output in format: Requested package -> Available versions
Package _tflow_select conflicts for:
_tflow_select==2.1.0=gpu
tensorflow==1.15.0 -> _tflow_select[version='2.1.0|2.3.0|2.2.0',build='gpu|mkl|eigen']
Note that strict channel priority may have removed packages required for satisfiability.

I am not sure if that is the problem, but I installed the following way
conda create -n tensorflow1.15 python=3.5
conda activate tensorflow1.15
conda install cudatoolkit=10.0
conda install cudnn=7.3.1
pip3 install tensorflow-gpu==1.15
And it seems to works perfectly with the GPU. I didn't know that cuDNN 7.3.1 worked like 7.4. The best way is to install tensorflow with conda, but it give me an error of trying to install tensorflow-gpu=2.X.
Also maybe it's interesting to say that you can search CUDA and similar official installers with conda search -c nvidia <packageName>.

I would let conda handle all the dependencies itself by installing tensorflow via conda, not pip. The GPU version of tensorflow is available e.g. in the popular conda-forge channel:
conda create -n myenv -c conda-forge tensorflow-gpu=1.15

The best setup for TensorFlow 1.15 is to follow this guide here: https://tensorflow-object-detection-api-tutorial.readthedocs.io/en/tensorflow-1.14/install.html#tf-install. The CUDA version which is recommended is 10.0 and the cudNN version 7.6.5
Attention to the protobuf version which will be installed, if you execute the gpu version it's 4.21.1, but you have to rewrite it with the command: pip install --upgrade tensorflow-gpu==1.15 "protobuf<4.0". If you use the cpu version its recommended to use this version here:(https://github.com/protocolbuffers/protobuf/releases/tag/v3.4.0) to avoid errors.Just download the protoc-3.4.0-win32.zip (windows)
Hope that helps.

Related

'conda install tensorflow-gpu' is not installing any CUDNN libraries

When I run conda install tensorflow-gpu in a new venv, conda gives the list of packages that it will install, but there are no CUDNN or cudatoolkit packages which I would expect, and that other people have. I am expecting an output like in this question (Is it still necessary to install CUDA before using the conda tensorflow-gpu package?
) but instead I get this:
Edit: I was able to get it to work by running this command instead
conda create -n tf-gpu python=3.7 anaconda followed by
conda install tensorflow-gpu
After doing this it installed all the cudnn libraries on its own and I was able to run tensorflow with GPU. However, for some reason it is installing tensorflow 1.14, and I need 2.x so does anyone know why this is?
conda install tensorflow-gpu install only gpu version of Tensorflow and not supporting packages such as CUDA and cuDNN.
Follow steps to install
conda install cudatoolkit=10.0.130
conda install cudnn=7.6.0=cuda10.0_0
conda install tensorflow-gpu

Python 3.8.3 incompatible with tensorflow

I recently installed python with the version 3.8.3 and upgraded pip to 20.1.1. According to enter link description here, conda install -c conda-forge tensorflow should work. However, I get this result
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: -
Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed
UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:
Specifications:
- tensorflow -> python[version='3.5.*|3.6.*|>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0|3.7.*']
Your python: python=3.8
If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
since I use
(base) C:\Users\ivan>python --version
Python 3.8.3
(base) C:\Users\ivan>pip --version
pip 20.1.1 from C:\Users\ivan\anaconda3\lib\site-packages\pip (python 3.8)
I wonder if it is possible to solve this issue without downgrading. For users of anaconda 2020.07, python 3.8 is used by default. Downgrading it will break anaconda.
People have reported problems using tensorflow with python 3.8, it is best to use 3.7. You are incorrect about breaking Anaconda. Here is what to do.
In Anaconda home page click on environments. At the bottom left of the page click on create. A window will appear. Give the new environment a name (say python3.7). In the drop down menu select 3.7. Now a new environment is created using python 3.7. Now in the conda terminal type conda activate python3.7. Then use conda to install tensorflow. It will install version 2.1.1, the cuda toolkit version 10.1.243 and cudnn version 7.6.5. Note conda can only install tensorflow up to version 2.1.1. If you want tensorflow 2.2 install it with pip using pip install tensorflow ==2.2.0. after you have installed 2.1. The cuda toolkit and cudnn work with version 2.2. Now use pip or conda to install any other packages you need in your python3.7 environment and you should be good to go!

How to install latest cuDNN to conda?

In conda the latest version of conda is:
cudnn 7.3.1 cuda10.0_0 anaconda
But i need 7.4.2 for tensorflow-gpu.1.13
How install cuDNN==7.4.2 in conda?
conda update --force conda
conda update conda
conda install -c anaconda cudnn
conda list cudnn
You can install with conda-forge
conda install -c conda-forge cudnn
https://anaconda.org/conda-forge/cudnn
It is more up to date than anaconda channel - for example as of today, latest version of cudnn on anaconda is still 7.6.5, but on conda-forge v8.2.0.53.
Same applies to cudatoolkit package.
You need to uninstall cudnn: conda uninstall cudnn.
Uninstall any tensorflow dependencies: "conda uninstall tensorflow"
Install tensorflow using pip: "pip install tensorflow"
Install CuDNN and Cuda ToolKit following the instructions in here: https://www.tensorflow.org/install/gpu#linux_setup
Use PyCharm or Spyder to run Scripts using tensorflow
The best use is to install both cuda-toolkit and CuDNN using conda environment for the best compatibility. But in some cases people might need the latest version. Moreover sometimes cuda packages are updated in different schedules such as the time being this answer is provided, conda provides cudatoolkit-11.0 but cant provide CuDNN-8.0 at the same time. which happened in my case. There is a workaround for this problem.
install conda-toolkit using conda enviroment and download the latest matching CuDNN version from Nvidia CuDNN page for installed cuda-toolkit. Use tar and unzip the packages and copy the CuDNN files to your anaconda environment.
sudo cp cuda/include/cudnn*.h /anaconda3/envs/<your environment here>/include
sudo cp cuda/lib64/libcudnn* /anaconda3/envs/<your environment here>/lib
sudo chmod a+r /usr/local/cuda/include/cudnn*.h /anaconda3/envs/<your environment here>/lib/libcudnn*
In the given snipped "cuda" path represent the unzipped CuDNN folder. This workaround is tested with tensorflow-2.4 & cudatoolkit-11.0 & CuDNN 8.0.4
This is how i installed cudnn.
1. You can download cudnn tar file of a version which you want from NVIDIA and extract it.
Then, you can see "cuda" folder including cudnn files.
2. Copy and paste the cudnn files to conda envs lib and include folder:
sudo cp cuda/include/cudnn*.h anaconda3/envs/"your_env_name"/include
sudo cp cuda/lib64/libcudnn* anaconda3/envs/"your_env_name"/lib
anaconda3 is your anaconda installation folder.
In my case, it worked.
This was not possible to do it with conda at the time the question was made. That is way it was suggested to try this. However, now it is possible. Follow the other answers

How to install Keras with gpu support?

I installed Tensorflow for GPU using: pip install tensorflow-gpu
But when I tried the same for Keras pip install keras-gpu, it pulled me an error: could not find the version that satisfies the requirements.
Adding to the answer below which is the correct answer in terms of recommending to use Anaconda package manager, but out of date in that there is now a keras-gpu package on Anaconda Cloud.
So once you have Anaconda installed, you simply need to create a new environment where you want to install keras-gpu and execute the command:
conda install -c anaconda keras-gpu
This will install Keras along with both tensorflow and tensorflow-gpu libraries as the backend. (There is also no need to install separately the CUDA runtime and cudnn libraries as they are also included in the package - tested on Windows 10 and working).
There is not any keras-gpu package [UPDATE: now there is, see other answer above]; Keras is a wrapper around some backends, including Tensorflow, and these backends may come in different versions, such as tensorflow and tensorflow-gpu. But this does not hold for Keras itself, which should be installed simply with
pip install keras
independently of whatever backend is used (see the PyPi docs).
Additionally, and since you have tagged the question as anaconda, too, be informed that it is generally not advisable to mix your package managers (i.e pip with conda), and you may be better off installing Keras from the Anaconda cloud with
conda install -c conda-forge keras
Finally, you may be also interested to know that recent versions of Tensorflow include Keras as a subpackage, so you can use it without any additional installation; see https://www.tensorflow.org/guide/keras
For installing tensorflow-gpu from Anaconda cloud, you should use
conda install -c anaconda tensorflow-gpu
before installing Keras. Be sure you do it in a different virtual environment, or after having uninstalled other versions (i.e. pip-installed ones), as there have been reported problems otherwise.
Adding to the above two answers, ensure your TensorFlow/Keras environment is using Python 3.6. Keras/TensorFlow doesn't work very well with Python 3.7, as of May 10, 2019.
I tried to use Keras/TensorFlow with Python 3.7 and I ended up having to reinstall Anaconda, since it sort of broke my Anaconda Prompt.
To install tensorflow-gpu with particular cuda version 9.0, use:
conda install tensorflow-gpu cudatoolkit==9.0 -c anaconda
Similarly for keras-gpu

TensorFlow: unsatisfiableError: the following specifications were found to be in conflict

I am trying to install tensorflow in anaconda with python 2.7 in Win10, by conda installation:
conda install -c conda-forge tensorflow=1.1.0
Then, I get the error message:
- python 2.7*
- tensorflow 1.1.0* -> python 3.5*
Use 'conda info <package>' to see the dependencies for each package.
Does the message mean I need to use python 3.5?
Yes.
TensorFlow only supports version 3.5.x of Python on Windows. Note that Python 3.5.x comes with the pip3 package manager, which is the program you'll use to install TensorFlow.
There are instructions for installing TF with Anaconda on Win10 on that page.