gpt4 book ai didi

python - Tensorflow 对象检测后续步骤

转载 作者:太空宇宙 更新时间:2023-11-03 14:38:43 25 4
gpt4 key购买 nike

我正在尝试训练模型来检查图像、识别指定对象并告诉我它的坐标(我什至不需要看到对象周围的正方形)。

为此,我使用了 Tensorflow 的对象检测,我所做的大部分工作都是在查看本教程:

How To Train an Object Detection Classifier for Multiple Objects Using TensorFlow (GPU) on Windows 10

但是有些事情发生了变化,可能是因为更新,然后我不得不自己做一些事情。我实际上可以训练模型(我猜)但我不了解评估结果。我曾经看到过损失和当前步骤,但这个输出对我来说很不寻常。我也不认为培训会被保存下来。

训练命令行:

model_main.py --logtostderr --train_dir=training/ --pipeline_config_path=training/faster_rcnn_inception_v2_coco.config

配置文件:

model {
faster_rcnn {
num_classes: 9
image_resizer {
keep_aspect_ratio_resizer {
min_dimension: 600
max_dimension: 1024
}
}
feature_extractor {
type: 'faster_rcnn_inception_v2'
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: 5
optimizer {
momentum_optimizer: {
learning_rate: {
manual_step_learning_rate {
initial_learning_rate: 0.0002
schedule {
step: 900000
learning_rate: .00002
}
schedule {
step: 1200000
learning_rate: .000002
}
}
}
momentum_optimizer_value: 0.9
}
use_moving_average: false
}
gradient_clipping_by_norm: 10.0
fine_tune_checkpoint: "faster_rcnn_inception_v2_coco_2018_01_28/model.ckpt"
from_detection_checkpoint: true
num_steps: 50000
data_augmentation_options {
random_horizontal_flip {
}
}
}

train_input_reader: {
tf_record_input_reader {
input_path: "C:/tensorflow1/models/research/object_detection/images/train.record"
}
label_map_path: "C:/tensorflow1/models/research/object_detection/training/object-detection.pbtxt"
}

eval_config: {
num_examples: 67
max_evals: 10
}

eval_input_reader: {
tf_record_input_reader {
input_path: "C:/tensorflow1/models/research/object_detection/images/test.record"
}
label_map_path: "C:/tensorflow1/models/research/object_detection/training/object-detection.pbtxt"
shuffle: false
num_readers: 1
}

输出:

2019-03-16 01:05:23.842424: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2019-03-16 01:05:23.842528: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-03-16 01:05:23.845561: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0
2019-03-16 01:05:23.845777: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N
2019-03-16 01:05:23.847854: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6390 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1)
creating index...
index created!
creating index...
index created!
Running per image evaluation...
Evaluate annotation type *bbox*
DONE (t=0.05s).
Accumulating evaluation results...
DONE (t=0.04s).
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.681
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 1.000
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.670
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.542
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.825
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.682
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.689
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.689
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.556
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.825
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = -1.000

另外 faster_rcnn_inception_v2_coco_2018_01_28 中的模型自 2018 年 1 月以来没有更改,这可能意味着即使它正在训练,也不会保存进度。

我的问题是:

  • 是我的配置有问题还是其他什么?
  • 是否保存训练进度?
  • 我如何理解这个输出? (IoU?maxDets?面积?负精确?是单批还是什么?)
  • 我应该等待它最终自行停止吗?我看不到我在哪一步以及我用作的这段输出这里的例子花了将近 15 分钟才出现。

最佳答案

哇,这里有很多问题要回答。

1 .我认为你的配置文件是正确的,通常需要仔细配置的字段是:

  • num_classes:数据集的类数
  • fine_tune_checkpoint:如果您采用转移学习,则开始训练的检查点,如果 from_detection_checkpoint 设置为 true,则应提供此检查点。
  • label_map_path:标签文件路径,类数应等于num_classes
  • input_path train_input_readereval_input_reader
  • num_exampleseval_config 中,这是您的验证数据集大小,例如验证数据集中的示例数量。
  • num_steps:这是在模型停止训练之前要达到的训练步数总数。

2 是的,你的训练过程正在被保存,它保存在train_dir(如果你使用旧版本的api,但是如果你使用最新的model_dir版),官方描述为here .您可以使用 tensorbard 可视化您的训练过程。

3 COCO 评估格式的输出,因为这是默认的评估指标选项。但是您可以通过在配置文件的 eval_config 中设置 metrics_set : 来尝试其他评估指标,其他选项可用 here .对于 coco 指标,具体来说:

  • IoUIntersection over Union,它定义了检测边界框与真实边界框的重叠程度。 This答案提供了更多详细信息,让您了解如何根据不同的 IoU 计算精度。
  • maxDets thresholds on max detections per image (参见 here 以获得更好的讨论)
  • area,区域分为三类,根据区域所占的像素数,small, medium, large 都有定义here .
  • 关于'large'类别的负精度,我认为这是因为如果没有检测被归类为'large',这是默认值(但我无法确认这一点,您可以引用coco官网http://cocodataset.org/#home )
  • 评估是在整个验证数据集上执行的,因此验证集中的所有图像。
  • This文件提供了有关 coco 指标的更多详细信息

4 一旦总训练步数达到 cofig 文件中设置的 num_steps,训练将停止。在您的案例中,每 15 分钟执行一次评估 session 。此外,还可以在配置 file 中配置每次评估执行的频率。 .

5 虽然你按照上面的教程,但我建议按照官方API文档https://github.com/tensorflow/models/tree/master/research/object_detection .

PS:确实我可以确认负精度分数是因为没有相应的类别。请参阅 cocoapi 中的引用资料.

关于python - Tensorflow 对象检测后续步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55193486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com