相关疑难解决方法(0)

在Tensorflow中,获取图表中所有张量的名称

我用Tensorflow和创造神经网络skflow; 出于某种原因,我想获得给定输入的一些内部张量的值,所以我正在使用myClassifier.get_layer_value(input, "tensorName"),myClassifier作为一个skflow.estimators.TensorFlowEstimator.

但是,我发现很难找到张量名称的正确语法,即使知道它的名字(我在操作和张量之间感到困惑),所以我使用tensorboard绘制图形并查找名称.

有没有办法在不使用张量板的情况下枚举图中的所有张量?

python tensorflow tensorboard skflow

101
推荐指数
6
解决办法
11万
查看次数

Tensorflow:如何通过名称获得张量?

我无法通过名字恢复张量,我甚至不知道它是否可能.

我有一个创建我的图形的函数:

def create_structure(tf, x, input_size,dropout):    
 with tf.variable_scope("scale_1") as scope:
  W_S1_conv1 = deep_dive.weight_variable_scaling([7,7,3,64], name='W_S1_conv1')
  b_S1_conv1 = deep_dive.bias_variable([64])
  S1_conv1 = tf.nn.relu(deep_dive.conv2d(x_image, W_S1_conv1,strides=[1, 2, 2, 1], padding='SAME') + b_S1_conv1, name="Scale1_first_relu")
.
.
.
return S3_conv1,regularizer
Run Code Online (Sandbox Code Playgroud)

我想访问此函数外的变量S1_conv1.我试过了:

with tf.variable_scope('scale_1') as scope_conv: 
 tf.get_variable_scope().reuse_variables()
 ft=tf.get_variable('Scale1_first_relu')
Run Code Online (Sandbox Code Playgroud)

但这给了我一个错误:

ValueError:欠共享:变量scale_1/Scale1_first_relu不存在,不允许.你是不是要在VarScope中设置reuse = None?

但这有效:

with tf.variable_scope('scale_1') as scope_conv: 
 tf.get_variable_scope().reuse_variables()
 ft=tf.get_variable('W_S1_conv1')
Run Code Online (Sandbox Code Playgroud)

我可以解决这个问题

return S3_conv1,regularizer, S1_conv1
Run Code Online (Sandbox Code Playgroud)

但我不想那样做.

我认为我的问题是S1_conv1实际上不是一个变量,它只是一个张量.有办法做我想要的吗?

python scope tensorflow

47
推荐指数
2
解决办法
6万
查看次数

如何列出节点所依赖的所有Tensorflow变量?

如何列出节点所依赖的所有Tensorflow变量/常量/占位符?

示例1(添加常量):

import tensorflow as tf

a = tf.constant(1, name = 'a')
b = tf.constant(3, name = 'b')
c = tf.constant(9, name = 'c')
d = tf.add(a, b, name='d')
e = tf.add(d, c, name='e')

sess = tf.Session()
print(sess.run([d, e]))
Run Code Online (Sandbox Code Playgroud)

我想有一个功能list_dependencies(),如:

  • list_dependencies(d) 回报 ['a', 'b']
  • list_dependencies(e) 回报 ['a', 'b', 'c']

示例2(占位符和权重矩阵之间的矩阵乘法,然后添加偏差向量):

tf.set_random_seed(1)
input_size  = 5
output_size = 3
input       = tf.placeholder(tf.float32, shape=[1, input_size], name='input')
W           = tf.get_variable(
                "W",
                shape=[input_size, output_size],
                initializer=tf.contrib.layers.xavier_initializer())
b           = tf.get_variable(
                "b",
                shape=[output_size],
                initializer=tf.constant_initializer(2))
output      = …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

13
推荐指数
1
解决办法
3899
查看次数

标签 统计

python ×3

tensorflow ×3

scope ×1

skflow ×1

tensorboard ×1