Can I run Keras model on gpu ?

Can I run Keras model on gpu ?

Asked on December 19, 2018 in Tensorflow.
Add Comment


  • 2 Answer(s)

    It is possible to run Keras model on gpu. For that just check the below things.

    • System should have GPU
    • Check if your system installed the GPU version of tensorflow
    • You have installed CUDA installation instructions
    • Check whether tensorflow is running with GPU.
    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
    

    Or, try this

    from tensorflow.python.client import device_lib
    print(device_lib.list_local_devices())
    

    Output:

    [
      name: "/cpu:0"device_type: "CPU",
      name: "/gpu:0"device_type: "GPU"
    ]
    

    After Finishing this your system will run on GPU.

    Verify that Keras model is using GPU:

    from keras import backend as K
    K.tensorflow_backend._get_available_gpus()
    
    Answered on December 19, 2018.
    Add Comment

          First install TensorFlow for GPU. And add the below block after importing keras. In this it had an 56 core CPU, and 1 GPU.

    import keras
     
    config = tf.ConfigProto( device_count = {'GPU': 1 , 'CPU': 56} ) 
    sess = tf.Session(config=config) 
    keras.backend.set_session(sess)
    

          This usage enforces to maximum limits. Hence decrease the CPU and GPU consumption values.

    Answered on December 19, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.