【问题标题】:Tensorflow, object detection APITensorFlow,对象检测 API
【发布时间】:2019-04-05 20:42:40
【问题描述】:

有没有办法查看 tensorflow object detection api 在所有预处理/增强后训练的图像。

我想验证事情是否正确。我能够验证在推理中查看图表后调整大小的调整大小,但对于增强选项,我显然无法做到这一点。

TIA

【问题讨论】:

    标签: object-detection-api


    【解决方案1】:

    我回答了一个类似的问题here

    您可以利用 api 提供的测试脚本并进行一些更改以满足您的需要。

    我编写了一个名为augmentation_test.py 的小测试脚本。它借用了input_test.py的一些代码

    from __future__ import absolute_import
    from __future__ import division
    from __future__ import print_function
    
    import functools
    import os
    from absl.testing import parameterized
    
    import numpy as np
    import tensorflow as tf
    from scipy.misc import imsave, imread
    
    from object_detection import inputs
    from object_detection.core import preprocessor
    from object_detection.core import standard_fields as fields
    from object_detection.utils import config_util
    from object_detection.utils import test_case
    
    FLAGS = tf.flags.FLAGS
    
    class DataAugmentationFnTest(test_case.TestCase):
    
      def test_apply_image_and_box_augmentation(self):
        data_augmentation_options = [
            (preprocessor.random_horizontal_flip, {
            })
        ]
        data_augmentation_fn = functools.partial(
            inputs.augment_input_data,
            data_augmentation_options=data_augmentation_options)
        tensor_dict = {
            fields.InputDataFields.image:
                tf.constant(imread('lena.jpeg').astype(np.float32)),
            fields.InputDataFields.groundtruth_boxes:
                tf.constant(np.array([[.5, .5, 1., 1.]], np.float32))
        }
        augmented_tensor_dict = 
            data_augmentation_fn(tensor_dict=tensor_dict)
        with self.test_session() as sess:
          augmented_tensor_dict_out = sess.run(augmented_tensor_dict)
        imsave('lena_out.jpeg',augmented_tensor_dict_out[fields.InputDataFields.image])
    
    
    if __name__ == '__main__':
      tf.test.main()
    

    你可以把这个脚本放在models/research/object_detection/ 下,用python augmentation_test.py 运行它(当然你需要先安装API)。要成功运行它,您应该提供任何图像名称“lena.jpeg”,增强后的输出图像将保存为“lena_out.jpeg”。

    我使用“lena”图像运行它,这是增强前和增强后的结果。

    .

    请注意,我在脚本中使用了preprocessor.random_horizontal_flip。结果准确地显示了输入图像在random_horizontal_flip 之后的样子。要使用其他增强选项对其进行测试,您可以将random_horizontal_flip 替换为其他方法(均在preprocessor.py 中定义),您可以将其他选项附加到data_augmentation_options 列表中,例如:

    data_augmentation_options = [(preprocessor.resize_image, {
            'new_height': 20,
            'new_width': 20,
            'method': tf.image.ResizeMethod.NEAREST_NEIGHBOR
        }),(preprocessor.random_horizontal_flip, {
        })]
    

    【讨论】:

      猜你喜欢
      • 2017-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-17
      • 2021-02-01
      • 2019-11-14
      • 2019-09-12
      • 1970-01-01
      相关资源
      最近更新 更多