為tensorflow指定GPU,原因是慢味,默認(rèn)創(chuàng)建session時(shí)场梆,會將所有顯存占滿,發(fā)現(xiàn)有人在用的時(shí)候纯路,就會session不能創(chuàng)建而報(bào)錯或油。
首先nvidia-smi查看顯卡的編號,最左邊一列驰唬,看看哪個空的
1.在終端設(shè)置使用的GPU
如果用方法一顶岸,雖然方便,但有的時(shí)候還是需要指定其他的GPU叫编,這時(shí)可以這樣辖佣,例如
CUDA_VISIBLE_DEVICES=2 python test.py
這樣就只會使用序號為2的GPU
2.在程序中指定使用的GPU
import os
os.environ["CUDA_VISIBLE_DEVICES"]=‘2’
3.No dashboards are active for the current data set. 解決tensorboard無法啟動(can not create session)和顯示問題(no dashboards)
CUDA_VISIBLE_DEVICES=3 tensorboard --host=1.1.1.1 --port=6666 --logdir="/data1/wangning/tutorials/tensorflowTUT/tf14_tensorboard/
host是你自己的主機(jī)ip,port是你可以指定tensorboard的端口號,logdir要記得寫絕對路徑搓逾,不然總出現(xiàn)no dashboard錯誤
這里僅做一下小記錄卷谈,請忽略,以防清華鏡像不穩(wěn)定霞篡。
linux世蔗,GPU, py2.7
pip install \
-i https://pypi.tuna.tsinghua.edu.cn/simple/ \
https://mirrors.tuna.tsinghua.edu.cn/tensorflow/linux/gpu/tensorflow_gpu-1.4.0-cp27-none-linux_x86_64.whl
config = tf.ConfigProto(allow_soft_placement=True)
最多占gpu資源的70%
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.7)
開始不會給tensorflow全部gpu資源 而是按需增加
config.gpu_options.allow_growth = True
sess = tf.Session(config=config)