ValueError: Variable E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable().
2017-09-05 11:55
691 查看
运行tf.train.AdamOptimizer()函数,例如下面代码:
出现错误:
解决方法:
在函数第一行添加:
例如原encoder()函数代码为:
def encoder(self, image, reuse_variables=False):
if reuse_variables:
tf.get_variable_scope().reuse_variables()
num_layers = int(np.log2(self.size_image)) - int(self.size_kernel / 2)
current = image
# conv layers with stride 2
for i in range(num_layers):
name = 'E_conv' + str(i)
current = conv2d(
input_map=current,
num_output_channels=self.num_encoder_channels * (2 ** i),
size_kernel=self.size_kernel,
name=name
)
current = tf.nn.relu(current)
# fully connection layer
name = 'E_fc'
current = fc(
input_vector=tf.reshape(current, [self.size_batch, -1]),
num_output_length=self.num_z_channels,
name=name
)
# output
return tf.nn.tanh(current)
修改后为:
def encoder(self, image, reuse_variables=False):
with tf.variable_scope("encoder") as scope:
if reuse_variables:
tf.get_variable_scope().reuse_variables()
num_layers = int(np.log2(self.size_image)) - int(self.size_kernel / 2)
current = image
# conv layers with stride 2
for i in range(num_layers):
name = 'E_conv' + str(i)
current = conv2d(
input_map=current,
num_output_channels=self.num_encoder_channels * (2 ** i),
size_kernel=self.size_kernel,
name=name
)
current = tf.nn.relu(current)
# fully connection layer
name = 'E_fc'
current = fc(
input_vector=tf.reshape(current, [self.size_batch, -1]),
num_output_length=self.num_z_channels,
name=name
)
# output
return tf.nn.tanh(current)
self.EG_optimizer = tf.train.AdamOptimizer( learning_rate=EG_learning_rate, beta1=beta1 ).minimize( loss=self.loss_EG, global_step=self.EG_global_step, var_list=self.E_variables + self.G_variables )
出现错误:
ValueError: Variable E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you mean to set reuse=None in VarScope?
解决方法:在函数第一行添加:
with tf.variable_scope("encoder") as scope:
例如原encoder()函数代码为:
def encoder(self, image, reuse_variables=False):
if reuse_variables:
tf.get_variable_scope().reuse_variables()
num_layers = int(np.log2(self.size_image)) - int(self.size_kernel / 2)
current = image
# conv layers with stride 2
for i in range(num_layers):
name = 'E_conv' + str(i)
current = conv2d(
input_map=current,
num_output_channels=self.num_encoder_channels * (2 ** i),
size_kernel=self.size_kernel,
name=name
)
current = tf.nn.relu(current)
# fully connection layer
name = 'E_fc'
current = fc(
input_vector=tf.reshape(current, [self.size_batch, -1]),
num_output_length=self.num_z_channels,
name=name
)
# output
return tf.nn.tanh(current)
修改后为:
def encoder(self, image, reuse_variables=False):
with tf.variable_scope("encoder") as scope:
if reuse_variables:
tf.get_variable_scope().reuse_variables()
num_layers = int(np.log2(self.size_image)) - int(self.size_kernel / 2)
current = image
# conv layers with stride 2
for i in range(num_layers):
name = 'E_conv' + str(i)
current = conv2d(
input_map=current,
num_output_channels=self.num_encoder_channels * (2 ** i),
size_kernel=self.size_kernel,
name=name
)
current = tf.nn.relu(current)
# fully connection layer
name = 'E_fc'
current = fc(
input_vector=tf.reshape(current, [self.size_batch, -1]),
num_output_length=self.num_z_channels,
name=name
)
# output
return tf.nn.tanh(current)
相关文章推荐
- Variable encoder/E_conv0/w/Adam/ does not exist, or was not created with tf.get_variable(). Did you
- [转] --- Error: “A field or property with the name was not found on the selected data source” get only on server
- ErrorList:Object variable or With block variable not set error
- Could not load file or assembly ... An attempt was made to load a program with an incorrect format.
- fatal error C1047: The object or library file "..."was created with an older compiler than other obj
- This Toast was not created with Toast.makeText()的解决办法
- ORA-27054 NFS file system where the file is created or resides is not mounted with correct options
- Swift 提示:Initialization of variable was never used consider replacing with assignment to _ or removing it
- This Toast was not created with Toast.makeText()
- xcode 项目 was compiled with optimization -stepping may behave oddly ;variable may not be available
- The object or library file 'xxx.obj' was created with an older compiler than other obj
- ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
- 【经验小谈】android4.2之后Toast定义的一个特点This Toast was not created with Toast.makeText()
- view not attached to windows manager与This Toast was not created with Toast.makeText()
- This Toast was not created with Toast.makeText()
- Initialization of variable was never used; consider replacing with assignment to ‘_’ or removing it
- [VB.NET]Object variable or With block variable not set
- tensorflow中使用tf.variable_scope和tf.get_variable的ValueError
- ORA-27054: NFS file system where the file is created or resides is not mounted with correct options
- Application failed codesign verification. The signature was invalid, contains disallowed entitlements, or it was not signed with an iPhone Distributi