相关疑难解决方法(0)

Tensorflow中的Tensor和Variable之间有什么区别

Tensorflow Tensor和 之间的区别是什么Variable?我注意到在这个stackoverflow的答案中,我们可以Variable在任何Tensor可以使用的地方使用.但是,我没有尽到session.run()一个Variable:

A = tf.zeros([10])   # A is a Tensor
B = tf.Variable([111, 11, 11]) # B is a Variable
sess.run(A) # OK. Will return the values in A
sess.run(B) # Error.
Run Code Online (Sandbox Code Playgroud)

tensorflow

23
推荐指数
1
解决办法
7659
查看次数

使用tf.contrib.graph_editor克隆网络

我有这样的功能可以构建网络。

def build_network(inputs):
  # Some arbitrary set of variables and ops here. For example...
  out = tf.contrib.layers.fully_connected(inputs, 123)
  (...)
  return out
Run Code Online (Sandbox Code Playgroud)

然后,我用它来建立这样的网络。

inputs = tf.placeholder(...)
outputs = build_network(inputs)
Run Code Online (Sandbox Code Playgroud)

如果我想构建更多具有相同结构但有独立变量的网络,我只需要在其他变量范围以及可选的其他输入下再次调用build_network即可

我的问题是:如果此build_network不再可用,但原始网络的输入和输出可用,该怎么办?换句话说:如何将整个子图从输出一直克隆到另一个具有自己独立变量集但结构相同的变量作用域中的输入

我的理解是,一般来说tf.contrib.graph_editor尤其是graph_editor.copy正是我要做这些事情所需的工具。但是,我找不到使用它们的任何好例子。有什么建议么?

tensorflow

5
推荐指数
1
解决办法
1192
查看次数

张量流中的变量内部

我将探讨如何在图中表示变量.我创建一个变量,初始化它并在每个动作后创建图形快照:

import tensorflow as tf

def dump_graph(g, filename):
    with open(filename, 'w') as f:
        print(g.as_graph_def(), file=f)

g = tf.get_default_graph()
var = tf.Variable(2)
dump_graph(g, 'data/after_var_creation.graph')

init = tf.global_variables_initializer()
dump_graph(g, 'data/after_initializer_creation.graph')

with tf.Session() as sess:
    sess.run(init)
    dump_graph(g, 'data/after_initializer_run.graph')
Run Code Online (Sandbox Code Playgroud)

变量创建后的图形看起来像

node {
  name: "Variable/initial_value"
  op: "Const"
  attr {
    key: "dtype"
    value {
      type: DT_INT32
    }
  }
  attr {
    key: "value"
    value {
      tensor {
        dtype: DT_INT32
        tensor_shape {
        }
        int_val: 2
      }
    }
  }
}
node {
  name: "Variable"
  op: "VariableV2"
  attr {
    key: …
Run Code Online (Sandbox Code Playgroud)

tensorflow

4
推荐指数
1
解决办法
1879
查看次数

标签 统计

tensorflow ×3