根据TensorFlow 文档,类prefetch和map方法tf.contrib.data.Dataset,都有一个名为的参数buffer_size.
对于prefetch方法,该参数称为buffer_size并且根据文档:
buffer_size:tf.int64标量tf.Tensor,表示预取时将被缓冲的最大元素数.
对于该map方法,该参数称为output_buffer_size并且根据文档:
output_buffer_size :(可选.)tf.int64标量tf.Tensor,表示将被缓冲的最大处理元素数.
类似地,对于该shuffle方法,出现相同的数量并且根据文档:
buffer_size:tf.int64标量tf.Tensor,表示新数据集将从中采样的数据集中的元素数.
这些参数之间有什么关系?
假设我创建一个Dataset对象如下:
tr_data = TFRecordDataset(trainfilenames)
tr_data = tr_data.map(providefortraining, output_buffer_size=10 * trainbatchsize, num_parallel_calls\
=5)
tr_data = tr_data.shuffle(buffer_size= 100 * trainbatchsize)
tr_data = tr_data.prefetch(buffer_size = 10 * trainbatchsize)
tr_data = tr_data.batch(trainbatchsize)
Run Code Online (Sandbox Code Playgroud)
buffer上述代码段中的参数扮演了什么角色?
我想指定运行我的进程的gpu.我将其设置如下:
import tensorflow as tf
with tf.device('/gpu:0'):
a = tf.constant(3.0)
with tf.Session() as sess:
while True:
print sess.run(a)
Run Code Online (Sandbox Code Playgroud)
但是它仍然在我的两个gpus中分配内存.
| 0 7479 C python 5437MiB
| 1 7479 C python 5437MiB
Run Code Online (Sandbox Code Playgroud) 根据
https://www.tensorflow.org/install/install_mac注意:从版本1.2开始,TensorFlow不再在Mac OS X上提供GPU支持.不再提供对OS X的GPU支持.
但是,我想通过thunderbolt 3来运行像akitio节点这样的e-gpu设置.
要使此设置生效,需要执行哪些步骤?到目前为止,我知道
是必要的.还有什么需要让CUDA/tensorflow工作?
我可以通过以下命令从命令行运行一个具有访问GPU的tensorflow容器
$ sudo docker run --runtime=nvidia --rm gcr.io/tensorflow/tensorflow:latest-gpu
我希望能够从docker-compose运行这个容器.可以从中指定--runtime标志docker-compose.yml吗?
docker docker-compose tensorflow nvidia-docker tensorflow-gpu
我无法optimize_for_inference在一个简单的,保存的TensorFlow图(Python 2.7;安装包pip install tensorflow-gpu==1.0.1)上成功运行该模块.
这是我的Python脚本,用于生成并保存一个简单的图形,以便为我的输入x placeholder操作添加5 .
import tensorflow as tf
# make and save a simple graph
G = tf.Graph()
with G.as_default():
x = tf.placeholder(dtype=tf.float32, shape=(), name="x")
a = tf.Variable(5.0, name="a")
y = tf.add(a, x, name="y")
saver = tf.train.Saver()
with tf.Session(graph=G) as sess:
sess.run(tf.global_variables_initializer())
out = sess.run(fetches=[y], feed_dict={x: 1.0})
print(out)
saver.save(sess=sess, save_path="test_model")
Run Code Online (Sandbox Code Playgroud)
我有一个简单的恢复脚本,可以重新创建已保存的图形并恢复图形参数.保存/恢复脚本都生成相同的输出.
import tensorflow as tf
# Restore simple graph and test model output
G = tf.Graph()
with tf.Session(graph=G) …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用tensorflow实现跳过思维模型,并在此处放置当前版本.

目前我使用我的机器的一个GPU(总共2个GPU)和GPU信息
2017-09-06 11:29:32.657299: I tensorflow/core/common_runtime/gpu/gpu_device.cc:940] Found device 0 with properties:
name: GeForce GTX 1080 Ti
major: 6 minor: 1 memoryClockRate (GHz) 1.683
pciBusID 0000:02:00.0
Total memory: 10.91GiB
Free memory: 10.75GiB
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试向模型提供数据时,我得到了OOM.我尝试调试如下:
我运行后立即使用以下代码段 sess.run(tf.global_variables_initializer())
logger.info('Total: {} params'.format(
np.sum([
np.prod(v.get_shape().as_list())
for v in tf.trainable_variables()
])))
Run Code Online (Sandbox Code Playgroud)
得到了2017-09-06 11:29:51,333 INFO main main.py:127 - Total: 62968629 params,大概是关于240Mb如果全部使用tf.float32.输出tf.global_variables是
[<tf.Variable 'embedding/embedding_matrix:0' shape=(155229, 200) dtype=float32_ref>,
<tf.Variable 'encoder/rnn/gru_cell/gates/kernel:0' shape=(400, 400) dtype=float32_ref>,
<tf.Variable 'encoder/rnn/gru_cell/gates/bias:0' shape=(400,) dtype=float32_ref>,
<tf.Variable 'encoder/rnn/gru_cell/candidate/kernel:0' shape=(400, …Run Code Online (Sandbox Code Playgroud) 我有一个形状[a,n] 的张量A,我需要my_op用另一个形状[b,n]的张量B执行一个op ,使得得到的张量C具有形状[a,b].
换句话说:对于A中的每个子指标(A [0],A 1,... A [n]),我需要对B中的每个子指标执行元素操作.
因此产生的张量将包含以下内容:
[ [ A[0] op B[0] , A[0] op B[1], ... , A[0] op B[b] ],
[ A[1] op B[0] , A[1] op B[1], ... , A[1] op B[b] ],
[ ... ],
[ A[a] op B[0] , A[a] op B[1], ... , A[a] op B[b] ] ]
Run Code Online (Sandbox Code Playgroud)
我能够找到的唯一方法就是通过嵌套使用tf.map_fn 这样:
import tensorflow as tf
import time …Run Code Online (Sandbox Code Playgroud) 我用keras版本2.0.0和tensorflow版本0.12.1构建了docker 镜像https://github.com/floydhub/dl-docker的gpu版本.然后我运行了mnist教程https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py,但意识到keras没有使用GPU.以下是我的输出
root@b79b8a57fb1f:~/sharedfolder# python test.py
Using TensorFlow backend.
Downloading data from https://s3.amazonaws.com/img-datasets/mnist.npz
x_train shape: (60000, 28, 28, 1)
60000 train samples
10000 test samples
Train on 60000 samples, validate on 10000 samples
Epoch 1/12
2017-09-06 16:26:54.866833: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-09-06 16:26:54.866855: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are …Run Code Online (Sandbox Code Playgroud) 我们在Tensorflow上运行多GPU作业,并评估从基于队列的模型(使用string_input_producer接口)到新的Tensorflow Dataset API的迁移.后者似乎提供了一种更容易的方式来同时切换列车和验证.
下面的代码片段显示了我们如何做到这一点.
train_dataset, train_iterator = get_dataset(train_files, batch_size, epochs)
val_dataset, val_iterator = get_dataset(val_files, batch_size, epochs)
is_validating = tf.placeholder(dtype=bool, shape=())
next_batch = tf.cond(is_validating,
lambda: val_iterator.get_next(),
lambda: train_iterator.get_next())
validation_tower = self.num_gpus - 1
tower_grads = []
for i in range(self.num_gpus):
with tf.variable_scope(tf.get_variable_scope(),reuse=(i > 0)):
with tf.device('/gpu:%d' % i), tf.name_scope('%s_%d' % ('gpu_', i)) as scope:
if i == validation_tower:
images, labels = next_batch
# Loss funcs snipped out
else:
images, labels = next_batch
# Loss funcs snipped out
Run Code Online (Sandbox Code Playgroud)
get_dataset函数构建数据集,设置映射函数和批处理大小.它还构建了一个迭代器,但没有初始化它.迭代器的初始化发生在会话开始之前.
会话运行时提供is_validating布尔值,我们通过feed_dict传递的每个步骤is_validating为True,以使用验证数据集
我的问题是:
假设我有8个gpus,所以我们对7个GPU进行了培训.对于这7个GPU中的每一个,Iterator是否从同一点前进,从而为所有7个GPU提供相同的数据?
我有一个标准的tensorflow Estimator和一些模型,并希望在多个GPU而不是一个GPU上运行它.如何使用数据并行来完成?
我搜索了Tensorflow文档,但没有找到示例; 只有句子说Estimator会很容易.
有没有人使用tf.learn.Estimator有一个很好的例子?或指向教程的链接?
tensorflow ×10
tensorflow-gpu ×10
docker ×2
python ×2
keras ×1
macos ×1
multi-gpu ×1
python-2.7 ×1
python-3.x ×1