对此问题的更准确描述是,当is_training未明确设置为true时,MobileNet表现不佳。 我指的是TensorFlow在其模型库https://github.com/tensorflow/models/blob/master/slim/nets/mobilenet_v1.py中提供的MobileNet。设置is_training为false时,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我得到的结果像网络没有训练...
这种行为实际上发生在像其他网络,如先知。
我倾向于相信,我错过了一些非常基本的这里,这是不是在TensorFlow一个bug ......
任何帮助,将不胜感激。
添加更多的代码...
这是我的训练做准备:
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
将与解决方案更新一次我有一个测试之一。
增加了更多的代码。谢谢 –