Slim版InceptionV1训练

常见问题2个:

(1)Slim的BatchNormalization,moving_vars系列参数需要更新和保存

update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
    with tf.control_dependencies(update_ops):
        optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
        train_op = optimizer.minimize(total_loss, global_step=global_step)
...
saver = tf.train.Saver(tf.trainable_variables() + tf.get_collection_ref("moving_vars"))

(2)设置适当滑动平均窗口的Decay(并非默认的0.997)

batch_norm_params = {
      # Decay for the moving averages.
      'decay': 0.9,
...

 完整代码在这里下载,只使用了30幅图片,仅用来确认训练效果,故未设置验证和测试数据。

其中也包括加载预训练权重进行推理的代码,预训练权重下载地址:https://github.com/tensorflow/models/tree/master/research/slim

猜你喜欢

转载自www.cnblogs.com/autosoftdev/p/9161572.html