Python Tensorflow对象检测API在单个图像中检测大量对象时遇到的问题
我需要在一张图像中检测大量的两类对象。我使用Tensorflow对象检测API取得了一些成功,通过使用以下配置文件从对象检测模型Zoo重新培训更快的\u rcnn\u inception\u resnet\u v2\u atrus\u coco网络:Python Tensorflow对象检测API在单个图像中检测大量对象时遇到的问题,python,tensorflow,object-detection-api,Python,Tensorflow,Object Detection Api,我需要在一张图像中检测大量的两类对象。我使用Tensorflow对象检测API取得了一些成功,通过使用以下配置文件从对象检测模型Zoo重新培训更快的\u rcnn\u inception\u resnet\u v2\u atrus\u coco网络: model { faster_rcnn { num_classes: 2 image_resizer { keep_aspect_ratio_resizer { min_dimension: 600
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上运行检测(内存为32GB的Nvidia V100)。我更改了配置文件,将第一个\u阶段的\u max\u建议从2000提高到4000,将每个\u类的最大\u检测数/max\u总检测数从1000提高到2000(在8GB GPU上,这些设置导致中止(内核转储)错误)。结果只是稍微好一点:
我尝试将第一阶段的max建议提高到8000,将每个类的max检测次数/max检测总数提高到4000,但这导致了32 GB GPU上的中止(内核转储)错误
我的问题是:
1) 这些是检测单个图像中大量对象的最佳配置设置吗
2) 对于这项具体任务,是否有比更快的网络更好的网络
3) 有没有一种完全不同的方法更适合这个问题
我考虑过将图像分割成更小的图像并在这些图像上运行,但如果可能的话,我希望将其保留为一个图像,因为对象的准确计数对我的应用程序很重要,并且沿某条分界线分割对象可能会导致不准确的计数
谢谢 除了调整每个类别的
最大检测次数
和最大总检测次数
之外,您还需要将最大检测箱数
添加到列车配置中,训练输入读卡器和评估输入读卡器块和max\u num\u boxes\u可视化
到评估配置块,否则地面真相框将从训练和评估过程中删除。我已经部署了一个模型来解决一个与您类似的问题,我们尝试检测许多小对象,而更快的\u rcnn\u inception\u resnet\u v2\u atrus\u coco工作得很好,所以这不应该是您的问题。除了调整每个类的最大检测次数
和最大总检测次数
之外,您需要将max_number_of_box
添加到train_config、train_input_reader和eval_input_reader块中,并将max_num_box_to_visualize
添加到eval_config块中,否则地面真相框将从培训和评估过程中删除。我部署了一个模型来解决与您类似的问题,我们尝试检测许多小对象,而更快的\u rcnn\u inception\u resnet\u v2\u atrus\u coco工作得很好,所以这不应该是您的问题。您想要的最大检测次数是多少?每个图像的最大检测次数可能约为800个对象,每个图像的平均检测数约为350-400个对象。提出max\u建议
和max\u总检测数
800。结果非常类似,max\u建议和max\u总检测数设置为800,在示例图像的下半部分没有检测到任何对象,而在下半部分检测到的对象通常较少。我从未找到一个好的解决方案。最后,我将图像(以及训练/注释)分割成更小的图像(每个图像分为3个子图像)并运行训练,然后对子图像进行测试。对于最终输出,我用一些次要的东西重新组合了子图像,以修复沿边缘的边界框。这很有效。我正在写一篇即将发表的论文,写完后我会把它放在这里。你想要的最大探测次数是多少?每个图像的最大探测次数大概是800个物体左右,每个图像的平均检测数约为350-400个对象。提出max\u建议
和max\u总检测数
800。结果非常类似,max\u建议和max\u总检测数设置为800,在示例图像的下半部分没有检测到任何对象,而在下半部分检测到的对象通常较少。我从未找到一个好的解决方案。最后,我将图像(以及训练/注释)分割成更小的图像(每个图像分为3个子图像)并运行训练,然后对子图像进行测试。对于最终输出,我用一些次要的东西重新组合了子图像,以修复沿边缘的边界框。这很有效。我正在写一篇即将发表的论文,写完后我会把它留在这里。