【问题标题】:Data augmentation in the object detection API: random_image_scale对象检测 API 中的数据增强:random_image_scale
【发布时间】:2018-04-30 04:04:10
【问题描述】:

我正在尝试使用对象检测 API 的数据增强功能,特别是 random_image_scale。

挖掘了一下,我找到了实现它的函数(粘贴在下面)。我遗漏了一些东西,或者这里没有处理盒子的基本事实?我环顾四周,没有发现任何东西。如果不根据对图像进行的缩放来相应地修改基本事实,它会弄乱正在训练的模型,不是吗?

如果我遗漏了什么,请告诉我,或者我应该避免使用此功能来训练我的网络。

文件是/object_detection/core/preprocessor.py

def random_image_scale(image,
                       masks=None,
                       min_scale_ratio=0.5,
                       max_scale_ratio=2.0,
                       seed=None):
  """Scales the image size.

  Args:
    image: rank 3 float32 tensor contains 1 image -> [height, width, channels].
    masks: (optional) rank 3 float32 tensor containing masks with
      size [height, width, num_masks]. The value is set to None if there are no
      masks.
    min_scale_ratio: minimum scaling ratio.
    max_scale_ratio: maximum scaling ratio.
    seed: random seed.

  Returns:
    image: image which is the same rank as input image.
    masks: If masks is not none, resized masks which are the same rank as input
      masks will be returned.
  """
  with tf.name_scope('RandomImageScale', values=[image]):
    result = []
    image_shape = tf.shape(image)
    image_height = image_shape[0]
    image_width = image_shape[1]
    size_coef = tf.random_uniform([],
                                  minval=min_scale_ratio,
                                  maxval=max_scale_ratio,
                                  dtype=tf.float32, seed=seed)
    image_newysize = tf.to_int32(
        tf.multiply(tf.to_float(image_height), size_coef))
    image_newxsize = tf.to_int32(
        tf.multiply(tf.to_float(image_width), size_coef))
    image = tf.image.resize_images(
        image, [image_newysize, image_newxsize], align_corners=True)
    result.append(image)
    if masks:
      masks = tf.image.resize_nearest_neighbor(
          masks, [image_newysize, image_newxsize], align_corners=True)
      result.append(masks)
    return tuple(result)

【问题讨论】:

  • 没有使用不同旋转来增加数据的代码?

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


【解决方案1】:

如果您使用的是 tfrecord 文件,则框边界不是绝对像素,而是相对百分比。因此,如果您缩放图像,框保持不变。

所以使用它应该没问题。

【讨论】:

  • 根据代码,只有比例、亮度和一些焊盘选项。旋转呢?对于数据增强,我更喜欢在输入数据之前手动进行(每个样本都经过旋转、缩放以便获得更多数据)。
猜你喜欢
  • 2018-10-21
  • 2018-04-27
  • 2019-09-12
  • 2019-04-22
  • 1970-01-01
  • 2021-02-09
  • 2020-04-17
  • 2018-08-03
  • 2020-01-15
相关资源
最近更新 更多