我有计划使用分布式TensorFlow,我看到TensorFlow可以使用GPU进行培训和测试.在群集环境中,每台计算机可能有0个或1个或更多GPU,我想在尽可能多的计算机上运行我的TensorFlow图形到GPU.
我发现在运行tf.Session()TensorFlow时会在日志消息中提供有关GPU的信息,如下所示:
I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:838] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0)
Run Code Online (Sandbox Code Playgroud)
我的问题是如何从TensorFlow获取有关当前可用GPU的信息?我可以从日志中获取加载的GPU信息,但我希望以更复杂的程序化方式完成.我也可以故意使用CUDA_VISIBLE_DEVICES环境变量限制GPU,所以我不想知道从OS内核获取GPU信息的方法.
简而言之,如果机器中有两个可用的GPU ,我希望这样的函数tf.get_available_gpus()将返回['/gpu:0', '/gpu:1'].我该如何实现呢?
我正在阅读Tensorflow中的一些示例代码,我发现以下代码
flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_float('learning_rate', 0.01, 'Initial learning rate.')
flags.DEFINE_integer('max_steps', 2000, 'Number of steps to run trainer.')
flags.DEFINE_integer('hidden1', 128, 'Number of units in hidden layer 1.')
flags.DEFINE_integer('hidden2', 32, 'Number of units in hidden layer 2.')
flags.DEFINE_integer('batch_size', 100, 'Batch size. '
'Must divide evenly into the dataset sizes.')
flags.DEFINE_string('train_dir', 'data', 'Directory to put the training data.')
flags.DEFINE_boolean('fake_data', False, 'If true, uses fake data '
'for unit testing.')
Run Code Online (Sandbox Code Playgroud)
在 tensorflow/tensorflow/g3doc/tutorials/mnist/fully_connected_feed.py
但我找不到任何关于这种用法的文档tf.app.flags.
我发现这个标志的实现在
tensorflow/tensorflow/python/platform/default/_flags.py
显然,这tf.app.flags在某种程度上用于配置网络,那么为什么它不在API文档中呢?谁能解释一下这里发生了什么?
我最近回顾了一个卷积文本分类的有趣实现.但是,我所评论的所有TensorFlow代码都使用随机(未预先训练)的嵌入向量,如下所示:
with tf.device('/cpu:0'), tf.name_scope("embedding"):
W = tf.Variable(
tf.random_uniform([vocab_size, embedding_size], -1.0, 1.0),
name="W")
self.embedded_chars = tf.nn.embedding_lookup(W, self.input_x)
self.embedded_chars_expanded = tf.expand_dims(self.embedded_chars, -1)
Run Code Online (Sandbox Code Playgroud)
有谁知道如何使用Word2vec的结果或GloVe预训练的单词嵌入而不是随机的?
根据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上述代码段中的参数扮演了什么角色?
我已经使用TensorFlow训练了一个ConvNet模型,我希望在图层中获得特定的权重.例如在torch7中,我只是访问model.modules[2].weights.得到第2层的权重.我如何在TensorFlow中做同样的事情?
我所追求的功能是能够在给定一些数据的情况下告诉给定变量的梯度与我的误差函数有关.
实现这一目标的一种方法是查看变量在调用训练后变化了多少,但显然可以根据学习算法大量变化(例如,几乎不可能用RProp这样的东西来判断)并且只是不是很干净.
提前致谢.
使用TensorFlow Python API时,我创建了一个变量(没有name在构造函数中指定它),并且它的name属性具有值"Variable_23:0".当我尝试使用这个变量时tf.get_variable("Variable23"),"Variable_23_1:0"会创建一个名为的新变量.如何正确选择"Variable_23"而不是创建新的?
我想要做的是按名称选择变量,并重新初始化它,以便我可以微调权重.
我目前正在看theano的API,
theano.tensor.nnet.conv2d(input, filters, input_shape=None, filter_shape=None, border_mode='valid', subsample=(1, 1), filter_flip=True, image_shape=None, **kwargs)
Run Code Online (Sandbox Code Playgroud)
在哪里filter_shape是一个元组(num_filter, num_channel, height, width),我对此感到困惑,因为在图像上滑动滤镜窗口时,不是由步幅决定的滤镜数量?我怎样才能像这样指定过滤器编号?如果它是由参数stride(如果有的话)计算的,那对我来说是合理的.
此外,我也对术语特征映射感到困惑,它是每层的神经元吗?批量大小怎么样?它们如何相关?
我是第一次运行TensorFlow并使用一些示例代码.运行我的代码时出现此错误.有谁知道为什么会这样,以及如何解决它?谢谢!
2017-03-31 02:12:59.346109: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE instructions, but these are available on your machine and could speed up CPU computations.
2017-03-31 02:12:59.346968: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE2 instructions, but these are available on your machine and could speed up CPU computations.
2017-03-31 02:12:59.346975: W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_feature_guard.cc:45] The TensorFlow libbrary wasn't compiled to use SSE3 instructions, but these are available on your machine and could speed up CPU computations.
2017-03-31 …Run Code Online (Sandbox Code Playgroud) 有什么区别
tf.add(x, y)
Run Code Online (Sandbox Code Playgroud)
和
x + y
Run Code Online (Sandbox Code Playgroud)
在TensorFlow中?当您使用+而不是tf.add()?构建图形时,计算图形会有什么不同?
更一般地说,是否 +为张量超载或其他操作?