首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Tensorflow对象检测API过度拟合

Tensorflow对象检测API过度拟合
EN

Stack Overflow用户
提问于 2021-08-16 08:38:23
回答 1查看 298关注 0票数 1

在以下教程的帮助下,我正在使用Tensoflow对象检测API创建树检测器:https://www.youtube.com/watch?v=a1br6gW-8Ss

我的问题是,该模型是过分适合的培训集。我怎么才能避免呢?我的训练集由130幅图像组成,平均4棵树被标记在图像中。共有7种。我使用的模型是:“更快的R-CNN ResNet50 V1 640x640”,在COCO上接受预先培训(链接在下面) zoo.md在教程中使用以下模型'EfficientDet D0 512x512‘,但该模型也适合我的数据集,所以我尝试使用’更快的R ResNet50 V1 640x640‘。

我用来减少过度拟合的方法是

  1. 辍学(rate=0.675)
  2. 数据增强(Random_crop)
  3. 低学习率(learning_rate_base:.008,total_steps: 25000 .warmup_learning_rate:.0001)
  4. 原始图像尺寸为860x860,我调整了tp 640x640的大小,并在xml中更改了边界框坐标。

我应该在模型配置中添加或更改哪些内容以避免过度安装?

下面是我的模型配置文件:

代码语言:javascript
运行
复制
# Faster R-CNN with Resnet-50 (v1) with 640x640 input resolution
# Trained on COCO, initialized from Imagenet classification checkpoint
#
# Train on TPU-8
#
# Achieves 29.3 mAP on COCO17 Val

model {
  faster_rcnn {
    num_classes: 7
    image_resizer {
      keep_aspect_ratio_resizer {
        min_dimension: 640
        max_dimension: 640
        pad_to_max_dimension: true
      }
    }
    feature_extractor {
      type: 'faster_rcnn_resnet50_keras'
      batch_norm_trainable: true
    }
    first_stage_anchor_generator {
      grid_anchor_generator {
        scales: [0.25, 0.5, 1.0, 2.0]
        aspect_ratios: [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5]
        height_stride: 8
        width_stride: 8
      }
    }
    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: true
        dropout_keep_probability: 0.675
        fc_hyperparams {
          op: FC
          regularizer {
            l2_regularizer {
              weight: 0.0
            }
          }
          initializer {
            variance_scaling_initializer {
              factor: 1.0
              uniform: true
              mode: FAN_AVG
            }
          }
        }
        share_box_across_classes: true
      }
    }
    second_stage_post_processing {
      batch_non_max_suppression {
        score_threshold: 0.2
        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
    use_static_shapes: true
    use_matmul_crop_and_resize: true
    clip_anchors_to_image: true
    use_static_balanced_label_sampler: true
    use_matmul_gather_in_matcher: true
  }
}

train_config: {
  batch_size: 4
  sync_replicas: true
  startup_delay_steps: 0
  replicas_to_aggregate: 8
  num_steps: 25000
  optimizer {
    momentum_optimizer: {
      learning_rate: {
        cosine_decay_learning_rate {
          learning_rate_base: .008
          total_steps: 25000
          warmup_learning_rate: .0001
          warmup_steps: 2000
        }
      }
      momentum_optimizer_value: 0.9
    }
    use_moving_average: false
  }
  fine_tune_checkpoint_version: V2
  fine_tune_checkpoint: "faster_rcnn_resnet50_v1_640x640_coco17_tpu-8/checkpoint/ckpt-0"
  fine_tune_checkpoint_type: "detection"
    data_augmentation_options {
    random_crop_image {
      min_object_covered: 0.0
      min_aspect_ratio: 0.75
      max_aspect_ratio: 3.0
      min_area: 0.75
      max_area: 1.0
      overlap_thresh: 0.0
    }
  }

  max_number_of_boxes: 100
  unpad_groundtruth_tensors: false
  use_bfloat16: true  # works only on TPUs
}

train_input_reader: {
  label_map_path: "images/labelmap.pbtxt"
  tf_record_input_reader {
    input_path: "train.record"
  }
}

eval_config: {
  metrics_set: "coco_detection_metrics"
  use_moving_averages: false
  batch_size: 1;
}

eval_input_reader: {
  label_map_path: "images/labelmap.pbtxt"
  shuffle: false
  num_epochs: 1
  tf_record_input_reader {
    input_path: "test.record"
  }
}

EN

回答 1

Stack Overflow用户

发布于 2021-08-27 13:50:41

随着你正在采取的措施,以减少过度,你可以增加更多,并作出一些改变,现有的一个。

  • 确保您对数据进行了很好的洗牌,这样数据在训练和测试集中的分布都是一样的。
  • 尝试一些更多的增强技术(参考)或尝试收集更多的数据,因为现有的数据集看起来非常小,这会导致过度拟合。
  • 试着把辍学率从0.67降到0.2左右。
  • 增加正则化技术,以减少过度拟合。
  • 使用早停,当以后的历次的精度没有多大提高时,你可以称之为早停。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68799742

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档