為tensorflow指定GPU,原因是,默認(rèn)創(chuàng)建session時,會將所有顯存占滿,發(fā)現(xiàn)有人在用的時候,就會session不能創(chuàng)建而報錯。
首先nvidia-smi查看顯卡的編號,最左邊一列,看看哪個空的
1.在終端設(shè)置使用的GPU
如果用方法一,雖然方便,但有的時候還是需要指定其他的GPU,這時可以這樣,例如
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是你自己的主機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)