Keras in PyCharm not using GPU












4















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:UsersHOME-PCPyCharmProjectsenvlibsite-packagestheanoconfigdefaults.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?










share|improve this question




















  • 1





    So uninstalling tensorflow and keras didn't help?

    – Matthieu Brucher
    Nov 25 '18 at 8:55






  • 1





    But if it fails to load the native runtime, that's all right, that what we want. The native runtime is the CPU one.

    – Matthieu Brucher
    Nov 25 '18 at 9:07






  • 1





    So if you don't have TF, only TF-gpu, you get a failure with keras? Did you try using the TF keras layers instead of keras directly?

    – Matthieu Brucher
    Nov 25 '18 at 9:12






  • 1





    They are in tensorflow.keras, so you should be able to do from TensorFlow import keras and use the API more or less like before (tensorflow.org/guide/keras). If you use this API, you can have tensorflow.

    – Matthieu Brucher
    Nov 25 '18 at 9:20






  • 2





    Are you sure that you installed "exactly" the Cuda version required by tensorflow 1.4? Tensoflow is picky and it needs "excactly" the one version that is compatible. I suggest you go to the latest tensorflow and install the exact Cuda version it says in the tutorial. -- You cannot have both tensorflow and tensorflow-gpu. Install only tensorflow GPU (if you're using conda, give a try at installing keras-gpu)

    – Daniel Möller
    Nov 27 '18 at 18:24
















4















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:UsersHOME-PCPyCharmProjectsenvlibsite-packagestheanoconfigdefaults.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?










share|improve this question




















  • 1





    So uninstalling tensorflow and keras didn't help?

    – Matthieu Brucher
    Nov 25 '18 at 8:55






  • 1





    But if it fails to load the native runtime, that's all right, that what we want. The native runtime is the CPU one.

    – Matthieu Brucher
    Nov 25 '18 at 9:07






  • 1





    So if you don't have TF, only TF-gpu, you get a failure with keras? Did you try using the TF keras layers instead of keras directly?

    – Matthieu Brucher
    Nov 25 '18 at 9:12






  • 1





    They are in tensorflow.keras, so you should be able to do from TensorFlow import keras and use the API more or less like before (tensorflow.org/guide/keras). If you use this API, you can have tensorflow.

    – Matthieu Brucher
    Nov 25 '18 at 9:20






  • 2





    Are you sure that you installed "exactly" the Cuda version required by tensorflow 1.4? Tensoflow is picky and it needs "excactly" the one version that is compatible. I suggest you go to the latest tensorflow and install the exact Cuda version it says in the tutorial. -- You cannot have both tensorflow and tensorflow-gpu. Install only tensorflow GPU (if you're using conda, give a try at installing keras-gpu)

    – Daniel Möller
    Nov 27 '18 at 18:24














4












4








4








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:UsersHOME-PCPyCharmProjectsenvlibsite-packagestheanoconfigdefaults.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?










share|improve this question
















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:UsersHOME-PCPyCharmProjectsenvlibsite-packagestheanoconfigdefaults.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?







tensorflow keras pycharm cudnn






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 25 '18 at 7:35









talonmies

59.5k17129198




59.5k17129198










asked Nov 25 '18 at 7:22









AlirezaAlireza

15611




15611








  • 1





    So uninstalling tensorflow and keras didn't help?

    – Matthieu Brucher
    Nov 25 '18 at 8:55






  • 1





    But if it fails to load the native runtime, that's all right, that what we want. The native runtime is the CPU one.

    – Matthieu Brucher
    Nov 25 '18 at 9:07






  • 1





    So if you don't have TF, only TF-gpu, you get a failure with keras? Did you try using the TF keras layers instead of keras directly?

    – Matthieu Brucher
    Nov 25 '18 at 9:12






  • 1





    They are in tensorflow.keras, so you should be able to do from TensorFlow import keras and use the API more or less like before (tensorflow.org/guide/keras). If you use this API, you can have tensorflow.

    – Matthieu Brucher
    Nov 25 '18 at 9:20






  • 2





    Are you sure that you installed "exactly" the Cuda version required by tensorflow 1.4? Tensoflow is picky and it needs "excactly" the one version that is compatible. I suggest you go to the latest tensorflow and install the exact Cuda version it says in the tutorial. -- You cannot have both tensorflow and tensorflow-gpu. Install only tensorflow GPU (if you're using conda, give a try at installing keras-gpu)

    – Daniel Möller
    Nov 27 '18 at 18:24














  • 1





    So uninstalling tensorflow and keras didn't help?

    – Matthieu Brucher
    Nov 25 '18 at 8:55






  • 1





    But if it fails to load the native runtime, that's all right, that what we want. The native runtime is the CPU one.

    – Matthieu Brucher
    Nov 25 '18 at 9:07






  • 1





    So if you don't have TF, only TF-gpu, you get a failure with keras? Did you try using the TF keras layers instead of keras directly?

    – Matthieu Brucher
    Nov 25 '18 at 9:12






  • 1





    They are in tensorflow.keras, so you should be able to do from TensorFlow import keras and use the API more or less like before (tensorflow.org/guide/keras). If you use this API, you can have tensorflow.

    – Matthieu Brucher
    Nov 25 '18 at 9:20






  • 2





    Are you sure that you installed "exactly" the Cuda version required by tensorflow 1.4? Tensoflow is picky and it needs "excactly" the one version that is compatible. I suggest you go to the latest tensorflow and install the exact Cuda version it says in the tutorial. -- You cannot have both tensorflow and tensorflow-gpu. Install only tensorflow GPU (if you're using conda, give a try at installing keras-gpu)

    – Daniel Möller
    Nov 27 '18 at 18:24








1




1





So uninstalling tensorflow and keras didn't help?

– Matthieu Brucher
Nov 25 '18 at 8:55





So uninstalling tensorflow and keras didn't help?

– Matthieu Brucher
Nov 25 '18 at 8:55




1




1





But if it fails to load the native runtime, that's all right, that what we want. The native runtime is the CPU one.

– Matthieu Brucher
Nov 25 '18 at 9:07





But if it fails to load the native runtime, that's all right, that what we want. The native runtime is the CPU one.

– Matthieu Brucher
Nov 25 '18 at 9:07




1




1





So if you don't have TF, only TF-gpu, you get a failure with keras? Did you try using the TF keras layers instead of keras directly?

– Matthieu Brucher
Nov 25 '18 at 9:12





So if you don't have TF, only TF-gpu, you get a failure with keras? Did you try using the TF keras layers instead of keras directly?

– Matthieu Brucher
Nov 25 '18 at 9:12




1




1





They are in tensorflow.keras, so you should be able to do from TensorFlow import keras and use the API more or less like before (tensorflow.org/guide/keras). If you use this API, you can have tensorflow.

– Matthieu Brucher
Nov 25 '18 at 9:20





They are in tensorflow.keras, so you should be able to do from TensorFlow import keras and use the API more or less like before (tensorflow.org/guide/keras). If you use this API, you can have tensorflow.

– Matthieu Brucher
Nov 25 '18 at 9:20




2




2





Are you sure that you installed "exactly" the Cuda version required by tensorflow 1.4? Tensoflow is picky and it needs "excactly" the one version that is compatible. I suggest you go to the latest tensorflow and install the exact Cuda version it says in the tutorial. -- You cannot have both tensorflow and tensorflow-gpu. Install only tensorflow GPU (if you're using conda, give a try at installing keras-gpu)

– Daniel Möller
Nov 27 '18 at 18:24





Are you sure that you installed "exactly" the Cuda version required by tensorflow 1.4? Tensoflow is picky and it needs "excactly" the one version that is compatible. I suggest you go to the latest tensorflow and install the exact Cuda version it says in the tutorial. -- You cannot have both tensorflow and tensorflow-gpu. Install only tensorflow GPU (if you're using conda, give a try at installing keras-gpu)

– Daniel Möller
Nov 27 '18 at 18:24












2 Answers
2






active

oldest

votes


















1














It might not be the case but, installing and importing the same librariy can sometimes be confusing.
More clearly, my guess is your pycharm environment is different than the default python environment, youre installing packages in the default environment and importing from the pycharm's environment.
To ensure you have a package installed in pycharm's environment,



you can try the following,
from pycharm's python console



!python -m pip install --upgrade tensorflow, keras



this shall properly install the packages, and you can be sure of that installation isn't at fault






share|improve this answer
























  • I assume you mean tensorflow-gpu. but I have tried installing packages from PyCharm project interpreter also. No change.

    – Alireza
    Dec 1 '18 at 19:11











  • You've followed the official installation guide? maybe checking out the steps again can help link

    – dragonLOLz
    Dec 2 '18 at 7:35





















1














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.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465477%2fkeras-in-pycharm-not-using-gpu%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    It might not be the case but, installing and importing the same librariy can sometimes be confusing.
    More clearly, my guess is your pycharm environment is different than the default python environment, youre installing packages in the default environment and importing from the pycharm's environment.
    To ensure you have a package installed in pycharm's environment,



    you can try the following,
    from pycharm's python console



    !python -m pip install --upgrade tensorflow, keras



    this shall properly install the packages, and you can be sure of that installation isn't at fault






    share|improve this answer
























    • I assume you mean tensorflow-gpu. but I have tried installing packages from PyCharm project interpreter also. No change.

      – Alireza
      Dec 1 '18 at 19:11











    • You've followed the official installation guide? maybe checking out the steps again can help link

      – dragonLOLz
      Dec 2 '18 at 7:35


















    1














    It might not be the case but, installing and importing the same librariy can sometimes be confusing.
    More clearly, my guess is your pycharm environment is different than the default python environment, youre installing packages in the default environment and importing from the pycharm's environment.
    To ensure you have a package installed in pycharm's environment,



    you can try the following,
    from pycharm's python console



    !python -m pip install --upgrade tensorflow, keras



    this shall properly install the packages, and you can be sure of that installation isn't at fault






    share|improve this answer
























    • I assume you mean tensorflow-gpu. but I have tried installing packages from PyCharm project interpreter also. No change.

      – Alireza
      Dec 1 '18 at 19:11











    • You've followed the official installation guide? maybe checking out the steps again can help link

      – dragonLOLz
      Dec 2 '18 at 7:35
















    1












    1








    1







    It might not be the case but, installing and importing the same librariy can sometimes be confusing.
    More clearly, my guess is your pycharm environment is different than the default python environment, youre installing packages in the default environment and importing from the pycharm's environment.
    To ensure you have a package installed in pycharm's environment,



    you can try the following,
    from pycharm's python console



    !python -m pip install --upgrade tensorflow, keras



    this shall properly install the packages, and you can be sure of that installation isn't at fault






    share|improve this answer













    It might not be the case but, installing and importing the same librariy can sometimes be confusing.
    More clearly, my guess is your pycharm environment is different than the default python environment, youre installing packages in the default environment and importing from the pycharm's environment.
    To ensure you have a package installed in pycharm's environment,



    you can try the following,
    from pycharm's python console



    !python -m pip install --upgrade tensorflow, keras



    this shall properly install the packages, and you can be sure of that installation isn't at fault







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Dec 1 '18 at 16:22









    dragonLOLzdragonLOLz

    564




    564













    • I assume you mean tensorflow-gpu. but I have tried installing packages from PyCharm project interpreter also. No change.

      – Alireza
      Dec 1 '18 at 19:11











    • You've followed the official installation guide? maybe checking out the steps again can help link

      – dragonLOLz
      Dec 2 '18 at 7:35





















    • I assume you mean tensorflow-gpu. but I have tried installing packages from PyCharm project interpreter also. No change.

      – Alireza
      Dec 1 '18 at 19:11











    • You've followed the official installation guide? maybe checking out the steps again can help link

      – dragonLOLz
      Dec 2 '18 at 7:35



















    I assume you mean tensorflow-gpu. but I have tried installing packages from PyCharm project interpreter also. No change.

    – Alireza
    Dec 1 '18 at 19:11





    I assume you mean tensorflow-gpu. but I have tried installing packages from PyCharm project interpreter also. No change.

    – Alireza
    Dec 1 '18 at 19:11













    You've followed the official installation guide? maybe checking out the steps again can help link

    – dragonLOLz
    Dec 2 '18 at 7:35







    You've followed the official installation guide? maybe checking out the steps again can help link

    – dragonLOLz
    Dec 2 '18 at 7:35















    1














    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.






    share|improve this answer




























      1














      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.






      share|improve this answer


























        1












        1








        1







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 18 '18 at 17:46









        AlirezaAlireza

        15611




        15611






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53465477%2fkeras-in-pycharm-not-using-gpu%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'