snowkylin / tensorflow-handbook

简单粗暴 TensorFlow 2 | A Concise Handbook of TensorFlow 2 | 一本简明的 TensorFlow 2 入门指导教程
https://tf.wiki
3.94k stars 841 forks source link

设置显存使用策略 #37

Open moriwang opened 4 years ago

moriwang commented 4 years ago

设置显存按需使用的 code 报错。

gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
for gpu in gpus:
    tf.config.experimental.set_memory_growth(device=gpu, True)

显示 SyntaxError: positional arguments follows keyword argument

第三行需要修改一下才能运行

tf.config.experimental.set_memory_growth(gpu, True)
或
tf.config.experimental.set_memory_growth(device=gpu, enable=True)