Python 对同一网络使用tf.train.AdamOptimizer两次

Python 对同一网络使用tf.train.AdamOptimizer两次,python,tensorflow,machine-learning,deep-learning,Python,Tensorflow,Machine Learning,Deep Learning,我试图为一个新的数据集对现有的神经网络(resnet v2 152)进行微调。我现在设置训练的方法是,首先训练最后一个完全连接的层几个时代,然后训练整个模型几个时代。为了实现这一点,我定义了两个优化器。当我使用梯度下降优化器时,我能够训练模型。然而。当我使用AdamOptimizer时,模型无法训练 我注意到的最重要的事情是,当我使用梯度下降优化器包含tf.global\u variables\u initializer()时,也不会进行训练。但是,似乎tf。使用AdamOptimizer需要全

我试图为一个新的数据集对现有的神经网络(resnet v2 152)进行微调。我现在设置训练的方法是,首先训练最后一个完全连接的层几个时代,然后训练整个模型几个时代。为了实现这一点,我定义了两个优化器。当我使用梯度下降优化器时,我能够训练模型。然而。当我使用AdamOptimizer时,模型无法训练

我注意到的最重要的事情是,当我使用梯度下降优化器包含
tf.global\u variables\u initializer()
时,也不会进行训练。但是,似乎
tf。使用AdamOptimizer需要全局变量初始化器()

如果我不包括
tf.global\u varaibles\u initializer()
并使用梯度下降,网络将按预期进行训练

我在下面包含了一段代码。该代码基于VGG培训师,可从以下网址获得:

培训时不会出现错误,但培训和验证精度不会更新,因此优化器似乎没有实际运行

正如我所说,我认为这与包含
tf.global\u variables\u initializer()
有关,但我不确定如何使用AdamOptimizer绕过这一点

提前谢谢

 variables_to_restore = tf.contrib.framework.get_variables_to_restore(exclude=['resnet_v2_152/logits'])

 init_fn = tf.contrib.framework.assign_from_checkpoint_fn(model_path, variables_to_restore)

 # Initialization operation from scratch for the new "fc" layers

 # `get_variables` will only return the variables whose name starts with the given pattern

 c_variables = tf.contrib.framework.get_variables('resnet_v2_152/logits')
 fc_init = tf.variables_initializer(fc_variables)

 full_variables =tf.contrib.framework.get_variables()
 full_init = tf.variables_initializer(full_variables)

 ## ---------------------------------------------------------------------

 ## Using tf.losses, any loss is added to the tf.GraphKeys.LOSSES collection

 ## We can then call the total loss easily

 loss = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=labels, logits=logits)

 ## First we want to train only the reinitialized last layer fc for a few epochs.
 ## We run minimize the loss only with respect to the fc variables (weight and bias).
 fc_optimizer = tf.train.AdamOptimizer(args.learning_rate1, name="adam1")
 fc_train_op = fc_optimizer.minimize(loss, var_list=[fc_variables])

 # Then we want to finetune the entire model for a few epochs.

 # We run minimize the loss only with respect to all the variables.

 full_optimizer = tf.train.AdamOptimizer(args.learning_rate2, name ="adam2")

 full_train_op = full_optimizer.minimize(loss, var_list=[full_variables])

 init = tf.global_variables_initializer()