TensorFlow在训练模型时指定GPU进行训练

来源:互联网 发布:oracle 数据备份 编辑:程序博客网 时间:2024/05/16 01:05

TensorflowGPU训练的时候默认选第0块GPU训练,同时占满所有卡的显存。

用tf.device()函数在指定训练时所用GPU

tf.device('/gpu:0')

通过CUDA_VISIBLE_DEVICES来指定(这时只用一块GPU的内存)

import osos.environ['CUDA_VISIBLE_DEVICES']='0'# os.environ['CUDA_VISIBLE_DEVICES']='1'

运行python程序前指定:

CUDA_VISIBLE_DEVICES=0 python train.py
原创粉丝点击