tensorflow - tf.name_scope 的用法

标签 tensorflow

我的问题是关于教程代码 ptb/reader.pytf.name_scope 的使用,

  with tf.name_scope(name, "PTBProducer", [raw_data, batch_size, num_steps]):
      #use raw_data, batch_size, num_steps to construct tf objects 

使用列表 [raw_data, batch_size, num_steps] 调用 tf.name_scope 的目的是什么? raw_data 是一个 python 列表,batch_sizenum_steps 是 python int。根据 name_scope 的文档:

tf.name_scope(name,default_name=None,values=None):此上下文管理器验证给定值是否来自同一个图表,使该图表成为默认图表,并在该图表中推送名称范围(有关更多详细信息,请参阅 Graph.name_scope())。

但是 raw_databatch_sizenum_step 不是图中的任何节点。验证它们来自同一个图表是什么意思?事实上,当列表从 tf.name_scope 调用中删除时,代码仍然运行:

      with tf.name_scope(name, "PTBProducer"):
      #use raw_data, batch_size, num_steps to construct tf objects 

使用和不使用 values=[raw_data,batch_size,num_steps] 调用 tf.name_scope 有什么区别?

最佳答案

ptb/reader.py 错误地使用了 tf.name_scope() values 参数。应传递图形元素。

name_scope() 将使默认图形上下文与传入元素的图形相匹配。如果您正在处理多个图表,这非常有用。

如果列表(图形元素)并非全部来自同一个图形,tf.name_scope 将引发错误。

关于tensorflow - tf.name_scope 的用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41646532/

相关文章:

machine-learning - 在 TensorFlow 中使用 ReLU 构建非线性模型

python - 如何限制 TFLearn 中的 GPU 内存使用?

python-3.x - 使用梅尔谱图的罕见事件卷积神经网络

python - 如何解决 TensorFlow 中的 'BiasGrad requires tensor size <= int32 max' InvalidArgumentError?

tensorflow - 如何使用 tensorflow.Estimator 进行强化学习

python - Tensorflow/Keras Conv2D 层中的输入形状错误

tensorflow - 在 Tensorflow Keras 中创建自定义指标类

python - 在 TensorFlow 中构建自定义损失函数

machine-learning - Optimizer.compute_gradients 如何以编程方式计算梯度?

python - 不可散列类型 : 'list' in printing Tensorflow vector