2018/5/8
tensorflow 分配显存的问题
如果程序中不指定,tensorflow 默认分配全部显存,指定分配内存的代码如下:
import tensorflow as tf
config = tf.ConfigProto()
# 设置每个进程 GPU 最大占用量
config.gpu_options.per_process_gpu_memory_fraction = 0.5
# 程序按需申请显存
config.gpu_options.allow_growth = Ture
# Session 中设置配置
with tf.Session(config=config) as sess:
...
tf.gather()函数
x = tf.range(4,14)
# 索引
idx = [1,2,3,6,7,1,2]
# 按索引挑出对应的值
result = tf.gather(x, idx)
with tf.Session as sess:
print sess.run(result)
# 结果
[5 6 7 10 11 5 6]