小编pro*_*tas的帖子

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万
查看次数

标签 统计

python ×1

scope ×1

tensorflow ×1