Can I run Keras model on gpu?

前端 未结 5 1441
不知归路
不知归路 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:35

    2.0 Compatible Answer: While above mentioned answer explain in detail on how to use GPU on Keras Model, I want to explain how it can be done for Tensorflow Version 2.0.

    To know how many GPUs are available, we can use the below code:

    print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
    

    To find out which devices your operations and tensors are assigned to, put tf.debugging.set_log_device_placement(True) as the first statement of your program.

    Enabling device placement logging causes any Tensor allocations or operations to be printed. For example, running the below code:

    tf.debugging.set_log_device_placement(True)
    
    # Create some tensors
    a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
    b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
    c = tf.matmul(a, b)
    
    print(c)
    

    gives the Output shown below:

    Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0 tf.Tensor( [[22. 28.] [49. 64.]], shape=(2, 2), dtype=float32)

    For more information, refer this link

提交回复
热议问题