GPU not captured by TensorFlow - 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.

Related

how to run dlib face recognition with gpu

I have installed visual studio 2019, and Cuda 10.1 and TensorFlow 2.1.0 and I still can't run face recognition with GPU, can someone give me a complete guide on the steps to use GPU instead of CPU.
note: I'm using windows 10, my GPU is gtx1050 and I am using anaconda spider.
Firstly, you should install tensorflow-gpu package instead of tensorflow.
If your tf is installed correctly, you can run face recognition in gpu within deepface. You can test it with allocate memory function.
#!pip install deepface
from deepface import DeepFace
DeepFace.allocateMemory()
If everything is OK, then it returns "DeepFace will run on GPU" message.
All face recogntion models except Dlib will run on tensorflow-gpu. You can run face recognition with verification function.
from deepface import DeepFace
models = ["VGG-Face", "Facenet", "OpenFace", "DeepFace", "DeepID", "Dlib"]
obj = DeepFace.verify("img1.jpg", "img2.jpg", model_name = models[0])
print(obj)
i solved this by these steps using an anaconda enviroment:
cuda 10.2 installed
python (3.7.7)
conda install pip
conda install tensorflow (latest 2.1.0)
conda install tensorflow-gpu
pip install imutils
pip install opencv-python
pip install opencv-contrib-python
pip install dlib
pip install face_recognition
As Adrian Rosebrock mentioned at https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-learning/, it is better to build Dlib from source, so the library is aware of the presence of the exact GPU in your system. My guess is - during the building process, it probes the capabilities of the GPU through the CUDA driver and builds and installs accordingly.
git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build
cd build
cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1
cmake --build .
cd ..
python setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA

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.

How to use Tensorflow-gpu when both Tensorflow and Tensorflow-gpu are installed?

I have both TF and TF-GPU installed in the same virtual environment. when I test it in iPython terminal, it shows that TensorFlow, not TensorFlow-GPU is used. However, I want the GPU version to be used.
How to do that? Shouldn't I installed both in the same environment? Thanks.
I can recommend this:
pip uninstall tensorflow
pip uninstall tensorflow-gpu
pip install tensorflow
pip install tensorflow-gpu
Wish I knew a better answer

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

Pip only install cpu tensorflow of tensorflow 0.11

I previously installed tensorflow-gpu v 0.12 which worked fine, but for a code of a colleague I need v0.11. So I uninstalled tensorflow and tensorflow-gpu 0.12 and I tried to install v 0.11 with:
pip install https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
It successfully installs tensorflow, but not the gpu version, even though in the link above I took the gpu and not cpu version. Apparently, it doesn't matter if I choose cpu or gpu, it always only installs the cpu version.
Any idea how to fix this problem?
For tensorflow versions 0.11.x and below there isn't any tensorflow-gpu package in pip. The wheel corresponding to https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl is the correct wheel with gpu support. If you install this wheel via pip, it'll say Installed tensorflow==0.11.0 but has support of CUDA-8. By downloading the individual wheels, for the cpu and gpu folder have a different md5 signature, hence they are different.
See here.
On running
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.11.0-cp27-none-linux_x86_64.whl
I can successfully install tensorflow v 0.11.
Thaks for #user8289596 answer the following command was useful for my case and i have successfully installed tensorflow 0.11
pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.11.0rc0-cp27-none-linux_x86_64.whl
Note: I am using anaconda with python 2.7 and linux
For MacOS, Python 3, this worked for me:
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/mac/cpu/tensorflow-0.11.0-py3-none-any.whl
then install with:
sudo pip3 install --upgrade $TF_BINARY_URL
Source also has instructions for Python 2 and 3 on a variety of Ubuntu/Linux and MacOS configurations.