根据我的需求优化更快的R-CNN Inception Resnet v2

时间:2019-07-08 10:07:01

标签: tensorflow machine-learning deep-learning object-detection faster-rcnn

我正在使用在COCO上预先训练的Faster R-CNN Inception Resnet v2模型来训练我自己的对象检测器,目的是检测3类物体。与图像的尺寸(分辨率)相比,物体较小。我对ML和OD比较陌生。

我想知道应该对模型进行哪些更改以使其更适合我的目的。因为我只检测3个类,所以降低模型某些部分的复杂性是一个好主意吗?有没有更适合小物体的特征提取器?通常最好是使用预先训练的模型进行训练,还是应该从头开始训练?

我知道根据特定需求调整网络是一个反复试验的过程,但是,由于训练网络大约需要3天,我正在寻找一些有根据的猜测。

模型配置:

model {
  faster_rcnn {
    num_classes: 3
    image_resizer {
      keep_aspect_ratio_resizer {
        min_dimension: 600 
        max_dimension: 4048 
      }
    }
    feature_extractor {
      type: 'faster_rcnn_inception_resnet_v2'
      first_stage_features_stride: 8
    }
    first_stage_anchor_generator {
     # grid_anchor_generator {
     #   scales: [0.25, 0.5, 1.0, 2.0, 3.0]
     #   aspect_ratios: [0.25,0.5, 1.0, 2.0]
     #   height_stride: 8
     #   width_stride: 8
     # }
      grid_anchor_generator {
        scales: [0.25, 0.5, 1.0, 2.0, 3.0]
        aspect_ratios: [1.0, 2.0, 3.0]
        height: 64
        width: 64 
        height_stride: 8
        width_stride: 8
      }
    }
    first_stage_atrous_rate: 2
    first_stage_box_predictor_conv_hyperparams {
      op: CONV
      regularizer {
        l2_regularizer {
          weight: 0.01
        }
      }
      initializer {
        truncated_normal_initializer {
          stddev: 0.01
        }
      }
    }
    first_stage_nms_score_threshold: 0.0
    first_stage_nms_iou_threshold: 0.4
    first_stage_max_proposals: 1000
    first_stage_localization_loss_weight: 2.0
    first_stage_objectness_loss_weight: 1.0
    initial_crop_size: 17
    maxpool_kernel_size: 1
    maxpool_stride: 1
    second_stage_box_predictor {
      mask_rcnn_box_predictor {
        use_dropout: True
        dropout_keep_probability: 0.9
        fc_hyperparams {
          op: FC
          regularizer {
            l2_regularizer {
              weight: 0.01
            }
          }
          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.5
        max_detections_per_class: 20
        max_total_detections: 20
      }
      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.00001
          schedule {
            step: 100000
            learning_rate: .000001
          }
          schedule {
            step: 150000
            learning_rate: .0000001
          }
        }
      }
      momentum_optimizer_value: 0.9
    }
    use_moving_average: false
  }
  gradient_clipping_by_norm: 10.0
# PATH_TO_BE_CONFIGURED: Below line needs to match location of model checkpoint: Either use checkpoint from rcnn model, or checkpoint from previously trained model on other dataset. 
  fine_tune_checkpoint: "/.../model.ckpt"

  from_detection_checkpoint: true
  # Note: The below line limits the training process to 200K steps, which we
  # empirically found to be sufficient enough to train the pets dataset. This
  # effectively bypasses the learning rate schedule (the learning rate will
  # never decay). Remove the below line to train indefinitely.
  # num_steps: 200000
  data_augmentation_options {
    random_horizontal_flip {}
  }
  data_augmentation_options {
    random_crop_image {
    min_object_covered : 1.0
    min_aspect_ratio: 0.5
    max_aspect_ratio: 2
    min_area: 0.2
    max_area: 1.
    }
  }
  data_augmentation_options {
    random_distort_color {}
  }
}

# PATH_TO_BE_CONFIGURED: Need to make sure folder structure below is correct for both train-record and label_map.pbtxt
train_input_reader: {
  tf_record_input_reader {
    input_path: "/.../train.record"
  }
  label_map_path: "/..../label_map.pbtxt"
  queue_capacity: 500
  min_after_dequeue: 250
}

#PATH_TO_BE_CONFIGURED: Make sure folder structure for eval_export, validation.record and label_map.pbtxt below are correct. 
eval_config: {
  num_examples: 30
  # Note: The below line limits the evaluation process to 10 evaluations.
  # Remove the below line to evaluate indefinitely.
  max_evals: 10
  num_visualizations: 30
  eval_interval_secs: 600
  visualization_export_dir: "/.../eval_export"
}

eval_input_reader: {
  tf_record_input_reader {
    input_path: "/.../test.record"
  }
  label_map_path: "/.../label_map.pbtxt"
  shuffle: True
  num_readers: 1
}

0 个答案:

没有答案