指定gpu训练
1.在終端執行程序時指定GPU
CUDA_VISIBLE_DEVICES=0 python your_file.py # 指定GPU集群中第一塊GPU使用,其他的屏蔽掉
CUDA_VISIBLE_DEVICES=1 Only device 1 will be seen
CUDA_VISIBLE_DEVICES=0,1 Devices 0 and 1 will be visible
CUDA_VISIBLE_DEVICES=“0,1” Same as above, quotation marks are optional 多GPU一起使用
CUDA_VISIBLE_DEVICES=0,2,3 Devices 0, 2, 3 will be visible; device 1 is masked
CUDA_VISIBLE_DEVICES=“” No GPU will be visible
2.在Python代碼中指定GPU
import os
os.environ[“CUDA_VISIBLE_DEVICES”] = “0” #指定第一塊gpu
3.設置定量的GPU使用量
config = tf.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.9 # 占用GPU90%的顯存
session = tf.Session(config=config)
4.設置最小的GPU使用量
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
session = tf.Session(config=config)
————————————————
版權聲明:本文為CSDN博主「Litchi Kong」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/kongli524/article/details/85202879
總結