【问题标题】:Problem detecting large number of objects in single image with Tensorflow Object Detection API使用 Tensorflow 对象检测 API 在单个图像中检测大量对象的问题
【发布时间】:2019-12-31 19:19:09
【问题描述】:

我需要在单个图像中检测大量的两类对象。通过使用以下配置文件从对象检测模型动物园重新训练 fast_rcnn_inception_resnet_v2_atrous_coco 网络,我使用 Tensorflow 对象检测 API 取得了一些成功:

model {
  faster_rcnn {
    num_classes: 2
    image_resizer {
      keep_aspect_ratio_resizer {
        min_dimension: 600
        max_dimension: 1024
      }
    }
    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]
        aspect_ratios: [0.5, 1.0, 2.0]
        height_stride: 8
        width_stride: 8
      }
    }
    first_stage_atrous_rate: 2
    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: 2000
    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: 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: 1000
        max_total_detections: 1000
      }
      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: "/path/model.ckpt"
  from_detection_checkpoint: true
  load_all_detection_checkpoint_vars: 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 {
    }
  }
}

train_input_reader: {
  tf_record_input_reader {
    input_path: "/path/train.record"
  }
  label_map_path: "/path/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: "/path/val.record"
  }
  label_map_path: "/path/label_map.pbtxt"
  shuffle: false
  num_readers: 1
}

但是,使用具有 8 GB 内存的 Nvidia M10,我只能(大致)在图像的上半部分进行检测:

这种模式在许多图像中都是一致的,有些图像在图像下方有几个边界框,但没有图像的边界框在整个图像中准确分布。我的第一个想法是这是一个内存问题,所以我尝试在具有更多内存的 GPU 上运行检测(Nvidia V100 具有 32 GB 内存)。我更改了配置文件,将 first_stage_max_proposals 从 2000 提高到 4000,将 max_detections_per_class/max_total_detections 从 1000 提高到 2000(在 8 GB GPU 上,这些设置导致 Aborted(core dumped)错误)。结果只是稍微好一点:

我尝试将 first_stage_max_proposals 提高到 8000,将 max_detections_per_class/max_total_detections 提高到 4000,但这会导致 32 GB GPU 上出现 Aborted(core dumped)错误。

我的问题是:

1) 这些是检测单个图像中大量对象的最佳配置设置吗?

2) 对于这个特定任务,是否有比 fast_rcnn_inception_resnet_v2_atrous_coco 更好的网络?

3) 是否有更适合此问题的完全不同的方法?

我考虑过将图像拆分成更小的图像并在这些图像上运行它,但如果可能的话,我希望将其保留为一个图像,因为对象的准确计数对我的应用程序和拆分对象很重要某些分界线可能会导致计数不准确。

谢谢!

【问题讨论】:

  • 你想要的最大检测数是多少?
  • 每张图像的最大检测数可能约为 800 个对象,每张图像的平均检测数约为 350-400 个对象。
  • 制作 max_proposalsmax_total_detections 800。
  • 结果与 max_proposals 和 max_total_detections 设置为 800 非常相似,示例图像的下半部分没有检测到对象,而下半部分检测到的对象通常较少。
  • 我从来没有找到好的解决方案。我最终将图像(和训练/注释)分割成更小的图像(每个图像分成 3 个子图像)并运行训练然后对子图像进行测试。对于最终输出,我将子图像与一些小东西重新组合以修复边缘的边界框。这运作良好。我正在写一篇即将发表的论文,写完后我会留在这里。

标签: python tensorflow object-detection-api


【解决方案1】:

我也遇到了同样的问题。所以,我只是在 Model Zoo 的 Faster R-CNN Inception ResNet V2 1024x1024 模型的配置文件中做了一些调整。喜欢:

first_stage_max_proposals: 1500
max_detections_per_class: 1500
max_total_detections: 1500

max_number_of_boxes: 1500 添加到train_configtrain_input_readereval_input_reader 块中。我还将max_num_boxes_to_visualize: 1500 添加到eval_config 块中。

这项工作对我来说完全没问题。所以,现在我可以在一张图像中检测到大约 1500 个物体。

【讨论】:

    【解决方案2】:

    除了调整max_detections_per_classmax_total_detections之外,您还需要将max_number_of_boxes添加到train_config、train_input_reader和eval_input_reader块中,并将max_num_boxes_to_visualize添加到eval_config块中,否则ground truth box将从训练和评估过程中被剪掉.我已经部署了一个模型来解决与您类似的问题,我们试图检测到许多小物体,并且 faster_rcnn_inception_resnet_v2_atrous_coco 工作得很好,所以这不应该是您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-01
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-02
      • 1970-01-01
      相关资源
      最近更新 更多