How to install Keras with gpu support? - tensorflow

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

Related

Tensorflow 1.15 + CUDA + cuDNN installation using Conda

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.

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!

Tensorflow 2.0 version clash with scikit-learn 0.21 with conda

In order to install Tensorflow 2.0, I updated all my packages in conda using conda update --all. I later realised that although I got TF2.0, my scikit-learn module was not there. While trying to install it manually, I got a message that TF2.0 will be downgraded to 1.15(Downgrade message). Is there any way I can keep TF2.0 and scikit-learn together?
My python version is 3.6.9
I have all of them in the base environment. Will installing everything again in another environment resolve the issue?

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.

What is the difference in installing tensorflow with pip command and conda or directing cloning?

For the first time I'v installed tensorflow with conda installation. Then I actually work with a seq2seq model. After that I have again installed the tensorflow with the pip installation. But now the libraries are very different. All the old scripts are misplaced etc. Why is that ? Why I didn't face this when I was working with coda instillation
It has been claimed that Tensorflow installed with Conda performs a lot faster than a Pip installation, for example:
https://towardsdatascience.com/stop-installing-tensorflow-using-pip-for-performance-sake-5854f9d9eb0c
Conda also installs all of the package dependencies automatically, which Pip does not, as far as I'm aware.
https://www.anaconda.com/blog/developer-blog/tensorflow-in-anaconda/
Pip and conda install to two different locations. You should try to stick to one or the other. I would recommend uninstalling the conda version and sticking to pip but it's up to you how to proceed.
Update 01-02-2019: It seems that conda is now the faster and preferred way to install tensorflow. Note this may change again in the future.