TF 設置GPU模式訓練


https://blog.csdn.net/confuciust/article/details/78982264 

在終端執行程序時指定GPU

CUDA_VISIBLE_DEVICES=1 python your_file.py

這樣在跑你的網絡之前,告訴程序只能看到1號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 
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

在Python代碼中指定GPU

import os

os.environ[“CUDA_DEVICE_ORDER”] = “PCI_BUS_ID” 
os.environ[“CUDA_VISIBLE_DEVICES”] = “0”

設置定量的GPU使用量

config = tf.ConfigProto() 
config.gpu_options.per_process_gpu_memory_fraction = 0.9 # 占用GPU90%的顯存 
session = tf.Session(config=config)

設置最小的GPU使用量

config = tf.ConfigProto() 
config.gpu_options.allow_growth = True 
session = tf.Session(config=config)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM