Can I run Keras model on gpu?

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

    Sure. I suppose that you have already installed TensorFlow for GPU.

    You need to add the following block after importing keras. I am working on a machine which have 56 core cpu, and a gpu.

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

    Of course, this usage enforces my machines maximum limits. You can decrease cpu and gpu consumption values.

提交回复
热议问题