【发布时间】:2018-02-01 23:19:27
【问题描述】:
对这个问题更准确的描述是,当 is_training 未明确设置为 true 时,MobileNet 表现不佳。 我指的是 TensorFlow 在其模型库 https://github.com/tensorflow/models/blob/master/slim/nets/mobilenet_v1.py 中提供的 MobileNet。
这就是我创建网络的方式(phase_train=True):
with slim.arg_scope(mobilenet_v1.mobilenet_v1_arg_scope(is_training=phase_train)):
features, endpoints = mobilenet_v1.mobilenet_v1(
inputs=images_placeholder, features_layer_size=features_layer_size, dropout_keep_prob=dropout_keep_prob,
is_training=phase_train)
我正在训练一个识别网络,并且在训练期间我在 LFW 上进行测试。我在训练期间获得的结果随着时间的推移而提高,并且获得了很好的准确性。
在部署之前,我冻结了图表。如果我用 is_training=True 冻结图表,我在 LFW 上得到的结果与训练期间相同。 但是如果我设置 is_training=False 我得到的结果就像网络根本没有训练一样......
这种行为实际上发生在 Inception 等其他网络中。
我倾向于认为我在这里遗漏了一些非常基本的东西,而且这不是 TensorFlow 中的错误...
任何帮助将不胜感激。
正在添加更多代码...
这就是我准备培训的方式:
images_placeholder = tf.placeholder(tf.float32, shape=(None, image_size, image_size, 1), name='input')
labels_placeholder = tf.placeholder(tf.int32, shape=(None))
dropout_placeholder = tf.placeholder_with_default(1.0, shape=(), name='dropout_keep_prob')
phase_train_placeholder = tf.Variable(True, name='phase_train')
global_step = tf.Variable(0, name='global_step', trainable=False)
# build graph
with slim.arg_scope(mobilenet_v1.mobilenet_v1_arg_scope(is_training=phase_train_placeholder)):
features, endpoints = mobilenet_v1.mobilenet_v1(
inputs=images_placeholder, features_layer_size=512, dropout_keep_prob=1.0,
is_training=phase_train_placeholder)
# loss
logits = slim.fully_connected(inputs=features, num_outputs=train_data.get_class_count(), activation_fn=None,
weights_initializer=tf.truncated_normal_initializer(stddev=0.1),
weights_regularizer=slim.l2_regularizer(scale=0.00005),
scope='Logits', reuse=False)
tf.losses.sparse_softmax_cross_entropy(labels=labels_placeholder, logits=logits,
reduction=tf.losses.Reduction.MEAN)
loss = tf.losses.get_total_loss()
# normalize output for inference
embeddings = tf.nn.l2_normalize(features, 1, 1e-10, name='embeddings')
# optimizer
optimizer = tf.train.AdamOptimizer()
train_op = optimizer.minimize(loss, global_step=global_step)
这是我的火车步骤:
batch_data, batch_labels = train_data.next_batch()
feed_dict = {
images_placeholder: batch_data,
labels_placeholder: batch_labels,
dropout_placeholder: dropout_keep_prob
}
_, loss_value = sess.run([train_op, loss], feed_dict=feed_dict)
我可以添加如何冻结图形的代码,但这并不是必需的。使用 is_train=false 构建图,加载最新的检查点并在 LWF 上运行评估以重现问题就足够了。
更新...
我发现问题出在批量标准化层。将此层设置为 is_training=false 即可重现问题。
我找到这个后发现的参考资料:
http://ruishu.io/2016/12/27/batchnorm/
https://github.com/tensorflow/tensorflow/issues/10118
Batch Normalization - Tensorflow
一旦我测试了一个解决方案,就会更新解决方案。
【问题讨论】:
标签: tensorflow