How can I solve 'ran out of gpu memory' in TensorFlow

后端 未结 8 1582
你的背包
你的背包 2020-12-04 10:46

I ran the MNIST demo in TensorFlow with 2 conv layers and a full-conect layer, I got an message that \'ran out of memeory trying to allocate 2.59GiB\' , but it shows that to

8条回答
  •  自闭症患者
    2020-12-04 11:27

    For Tensorflow 2 or Keras:

    from tensorflow.python.framework.config import set_memory_growth
    tf.compat.v1.disable_v2_behavior()
    gpus = tf.config.experimental.list_physical_devices('GPU')
    if gpus:
        try:
            for gpu in gpus:
                set_memory_growth(gpu, True)
        except RuntimeError as e:
            print(e)
    

提交回复
热议问题