【发布时间】:2019-09-23 08:14:19
【问题描述】:
我在训练 CNN 从我自己的数据集中检测对象时遇到了一个奇怪的问题。我正在使用迁移学习,并且在训练开始时,损失值正在减少(如预期的那样)。但是一段时间后,它会越来越高,我不知道为什么会这样。
同时,当我查看 Tensorboard 上的 Images 选项卡以检查 CNN 预测对象的效果时,我可以看到它做得很好,看起来不像随着时间的推移变得更糟。此外,Precision 和 Recall 图表看起来不错,只有 Loss 图表(尤其是分类损失)显示出随时间增加的趋势。
以下是一些具体细节:
- 我有 10 种不同类别的徽标(例如 DHL、BMW、FedEx 等)
- 每类大约 600 张图片
- 我在 Ubuntu 18.04 上使用 tensorflow-gpu
-
我尝试了多个预训练模型,最新的是 faster_rcnn_resnet101_coco 使用此配置管道:
model { faster_rcnn { num_classes: 10 image_resizer { keep_aspect_ratio_resizer { min_dimension: 600 max_dimension: 1024 } } feature_extractor { type: 'faster_rcnn_resnet101' first_stage_features_stride: 16 } first_stage_anchor_generator { grid_anchor_generator { scales: [0.25, 0.5, 1.0, 2.0] aspect_ratios: [0.5, 1.0, 2.0] height_stride: 16 width_stride: 16 } } first_stage_box_predictor_conv_hyperparams { op: CONV regularizer { l2_regularizer { weight: 0.0 } } initializer { truncated_normal_initializer { stddev: 0.01 } } } first_stage_nms_score_threshold: 0.0 first_stage_nms_iou_threshold: 0.7 first_stage_max_proposals: 300 first_stage_localization_loss_weight: 2.0 first_stage_objectness_loss_weight: 1.0 initial_crop_size: 14 maxpool_kernel_size: 2 maxpool_stride: 2 second_stage_box_predictor { mask_rcnn_box_predictor { use_dropout: false dropout_keep_probability: 1.0 fc_hyperparams { op: FC regularizer { l2_regularizer { weight: 0.0 } } initializer { variance_scaling_initializer { factor: 1.0 uniform: true mode: FAN_AVG } } } } } second_stage_post_processing { batch_non_max_suppression { score_threshold: 0.0 iou_threshold: 0.6 max_detections_per_class: 100 max_total_detections: 300 } score_converter: SOFTMAX } second_stage_localization_loss_weight: 2.0 second_stage_classification_loss_weight: 1.0 } } train_config: { batch_size: 1 optimizer { momentum_optimizer: { learning_rate: { manual_step_learning_rate { initial_learning_rate: 0.0003 schedule { step: 900000 learning_rate: .00003 } schedule { step: 1200000 learning_rate: .000003 } } } momentum_optimizer_value: 0.9 } use_moving_average: false } gradient_clipping_by_norm: 10.0 fine_tune_checkpoint: "/home/franciszek/Pobrane/models-master/research/object_detection/logo_detection/models2/faster_rcnn_resnet101_coco/model.ckpt" from_detection_checkpoint: true data_augmentation_options { random_horizontal_flip { } } } train_input_reader: { tf_record_input_reader { input_path: "/home/franciszek/Pobrane/models-master/research/object_detection/logo_detection/data2/train.record" } label_map_path: "/home/franciszek/Pobrane/models-master/research/object_detection/logo_detection/data2/label_map.pbtxt" } eval_config: { num_examples: 8000 # Note: The below line limits the evaluation process to 10 evaluations. # Remove the below line to evaluate indefinitely. max_evals: 10 } eval_input_reader: { tf_record_input_reader { input_path: "/home/franciszek/Pobrane/models-master/research/object_detection/logo_detection/data2/test.record" } label_map_path: "/home/franciszek/Pobrane/models-master/research/object_detection/logo_detection/data2/label_map.pbtxt" shuffle: false num_readers: 1 }
在这里你可以看到我训练近 23 小时并达到超过 120k 步后得到的结果:
那么,我的问题是,为什么损失值会随着时间的推移而增加?它应该会变小或保持或多或少不变,但您可以在上图中清楚地看到增长趋势。 我认为一切都已正确配置,我的数据集相当不错(.tfrecord 文件也正确“构建”)。
为了检查是否是我的错,我尝试使用其他人的数据集和配置文件。所以我使用了racoon dataset作者的文件(他在his repo上提供了所有必要的文件)。我刚刚下载了它们并在没有任何修改的情况下开始训练,以检查我是否会得到与他相似的结果。
令人惊讶的是,经过 82k 步后,我得到的图表与链接文章中显示的完全不同(这是在 22k 步后捕获的)。在这里你可以看到我们的结果对比:
很明显,在我的电脑上有些东西的工作方式有所不同。我怀疑这可能与我在自己的数据集上的损失越来越大的原因相同,这就是我提到它的原因。
【问题讨论】:
标签: tensorflow object-detection loss-function