Search code examples
tensorflowkeraspycharm

Keras in PyCharm not using GPU


These threads did not solve my problem: Keras does not use GPU on Pycharm having python 3.5 and Tensorflow 1.4

Keras with TensorFlow backend not using GPU

I have installed Tensorflow and Tensorflow-gpu (v.1.12.0) on my PC which is running Windows 10 and has GTX 750 Ti graphics card, So it does support CUDA. I have also installed CUDA Toolkit v10 and cuDNN libraries and when I run nvcc -V on command prompt I get:

nvcc: NVIDIA (R) Cuda compiler...

I am using PyCharm and I don't have any problem running Keras on CPU. But it doesn't use my GPU.

When I type

from keras import backend as K
K.tensorflow_backend._get_available_gpus()

it says

2018-11-25 10:47:57.448275: I tensorflow/core/platform/cpu_feature_gaurd.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2

[ ]

What I have tried:

1) I tried uninstalling Tensorflow and Tensorflow-gpu and reinstalling Tensorflow-gpu like the above thread says. Didn't work and my code didn't run on CPU anymore and gave an error regarding Tensorflow. Once I reinstalled Tensorflow, It was OK again.

2) I tried using a library named Theano, which is mentioned on Keras official documentation here. When I add the following lines

import theano
theano.config.device='gpu'
theano.config.floatX='float32'

it says

WARNING (theano.configdefaults): g++ not available, if using conda: 'conda install m2w64-toolchain' C:\Users\HOME-PC\PyCharmProjects\env\lib\site-packages\theano\configdefaults.py.=:560: UserWarning: DeprecationWarning: there is no c++ compiler.This is deprecated and with theano 0.11 a c++ compiler will be mandatory. warning.warn("DeprecationWarning: there is no c++ compiler."

3) I tried adding these lines and also nothing happened.

import os
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]="0" 

What am I missing here? How should I introduce CUDA to PyCharm?


Solution

  • The problem was with CUDA's version. I had installed CUDA v10.0 but Tensorflow seems to work only with v9.0. Installed it and it works like a charm.