【问题标题】:Understanding data augmentation in the object detection API了解对象检测 API 中的数据增强
【发布时间】:2018-04-27 22:01:56
【问题描述】:

我正在使用对象检测 API 来使用不同的数据集进行训练,我想知道在训练期间是否可以获取到达网络的样本图像。

我问这个是因为我试图找到数据增强选项的良好组合 (here the options),但添加它们的结果更糟。在训练中查看到达网络的内容会非常有帮助。

另一个问题是,如果传递的数据集不平衡,是否可以让 API 帮助平衡类。

谢谢!

【问题讨论】:

  • 您的问题是关于分别理解每个增强的含义还是关于跟踪模型在训练时学习检测的内容?如果是前者,我建议查看 preprocessor.py (github.com/tensorflow/models/blob/master/research/…),如果是后者,请考虑在 TensorBoard“图像”窗格旁边使用 eval.py,它会显示您当前的评估结果。

标签: tensorflow object-detection object-detection-api


【解决方案1】:

是的,这是可能的。简而言之,您需要获取一个 tf.data.Dataset 的实例。然后,您可以对其进行迭代并将网络输入数据作为 NumPy 数组获取。使用 PIL 或 OpenCV 将其保存到图像文件是微不足道的。

假设你使用 TF2 的伪代码是这样的:

ds = ... get dataset object somehow

sample_num = 0
for features, _ in ds:
    images = features[fields.InputDataFields.image]  # is a [batch_size, H, W, C] float32 tensor with preprocessed images
    batch_size = images.shape[0]
    for i in range(batch_size):
        image = np.array(images[i] * 255).astype(np.uint8)  # assuming input data is only scaled to [0..1]
        cv2.imwrite(output_path, image)

    sample_num += 1
    if sample_num >= MAX_SAMPLES:
        break

这里的诀窍是获取 Dataset 实例。 Google 对象检测 API 非常复杂,但我想您应该先在此处调用 train_input 函数:https://github.com/tensorflow/models/blob/3c8b6f1e17e230b68519fd8d58c4dd9e9570d789/research/object_detection/inputs.py#L763

它需要描述训练、train_input 和模型的管道配置子部分。

您可以在此处找到一些关于如何使用管道的代码 sn-ps:Dynamically Editing Pipeline Config for Tensorflow Object Detection

import argparse

import tensorflow as tf
from google.protobuf import text_format
from object_detection.protos import pipeline_pb2


def parse_arguments():                                                                                                                                                                                                                                                
    parser = argparse.ArgumentParser(description='')                                                                                                                                                                                                                  
    parser.add_argument('pipeline')                                                                                                                                                                                                                                   
    parser.add_argument('output')                                                                                                                                                                                                                                     
    return parser.parse_args()                                                                                                                                                                                                                                        


def main():                                                                                                                                                                                                                                                           
    args = parse_arguments()                                                                                                                                                                                                                                          
    pipeline_config = pipeline_pb2.TrainEvalPipelineConfig()                                                                                                                                                                                                          

    with tf.gfile.GFile(args.pipeline, "r") as f:                                                                                                                                                                                                                     
        proto_str = f.read()                                                                                                                                                                                                                                          
        text_format.Merge(proto_str, pipeline_config)   

【讨论】:

    猜你喜欢
    • 2018-10-21
    • 2018-04-30
    • 2019-09-12
    • 2019-04-22
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    • 2020-04-17
    • 2018-08-03
    相关资源
    最近更新 更多