Can I run Keras model on gpu?

前端 未结 5 1439
不知归路
不知归路 2020-12-02 03:42

I\'m running a Keras model, with a submission deadline of 36 hours, if I train my model on the cpu it will take approx 50 hours, is there a way to run Keras on gpu?

5条回答
  •  旧巷少年郎
    2020-12-02 04:15

    Yes you can run keras models on GPU. Few things you will have to check first.

    1. your system has GPU (Nvidia. As AMD doesn't work yet)
    2. You have installed the GPU version of tensorflow
    3. You have installed CUDA installation instructions
    4. Verify that tensorflow is running with GPU check if GPU is working

    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

    OR

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

    output will be something like this:

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

    Once all this is done your model will run on GPU:

    To Check if keras(>=2.1.1) is using GPU:

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

    All the best.

提交回复
热议问题