SSD的图片预处理

SSD为了增加数据量,使用了很多图片预处理技术。下面根据ssd_vgg_preprocessing.py看看SSD采用了哪些预处理方法。

训练时的预处理

Random Crop

dst_image, labels, bboxes, distort_bbox = \
            distorted_bounding_box_crop(image, labels, bboxes,
                                        min_object_covered=MIN_OBJECT_COVERED,
                                        aspect_ratio_range=CROP_RATIO_RANGE)

通过distorted_bounding_box_crop方法完成以下功能:

  • random crop
bbox_begin, bbox_size, distort_bbox =  tf.image.sample_distorted_bounding_box(
         tf.shape(image),
         bounding_boxes=tf.expand_dims(bboxes, 0),
         min_object_covered=min_object_covered,
         aspect_ratio_range=aspect_ratio_range,
         area_range=area_range,
         max_attempts=max_attempts,
         use_image_if_no_bounding_boxes=True)


 # Crop the image to the specified bounding box.
 cropped_image = tf.slice(image, bbox_begin, bbox_size)
 # Restore the shape since the dynamic slice loses 3rd dimension.
 cropped_image.set_shape([None, None, 3])

tf.image.sample_distorted_bounding_box返回的3个tensor表示一个bbox:前两个分别是它的左上角坐标和宽高,可直接用于裁剪原图;最后一个用坐标表示这个bbox, shape=[1, 1, 4], 在这里用于当作reference来调整原图的bbox。

  • resize bbox
distort_bbox = distort_bbox[0, 0]
bboxes = tfe.bboxes_resize(distort_bbox, bboxes)

tf_extended/bbox.py

 with tf.name_scope(name, 'bboxes_resize'):
     # Translate.
     v = tf.stack([bbox_ref[0], bbox_ref[1], bbox_ref[0], bbox_ref[1]])
     bboxes = bboxes - v
     # Scale.
     s = tf.stack([bbox_ref[2] - bbox_ref[0],
                   bbox_ref[3] - bbox_ref[1],
                   bbox_ref[2] - bbox_ref[0],
                   bbox_ref[3] - bbox_ref[1]])
     bboxes = bboxes / s
  • 过滤bbox
    对原图进行random crop操作后, 一些bbox会被截掉一部分甚至完全截掉,只有留在crop后图片上的比例大于一定阈值才会被留下来。这个阈值也是个超参数。

最后要将crop得到的图片resize到目标大小: 通过双线性插值将图片resize到512*512(如果是SSD512)。

dst_image = tf_image.resize_image(dst_image, out_shape,                                     method=tf.image.ResizeMethod.BILINEAR,                                          align_corners=False)

左右翻转

dst_image, bboxes = tf_image.random_flip_left_right(dst_image, bboxes)

随机颜色扰动

        # Randomly distort the colors. There are 4 ways to do it.
        dst_image = apply_with_random_selector(
                dst_image,
                lambda x, ordering: distort_color(x, ordering, fast_mode),
                num_cases=4)

白化操作

image = tf_image_whitened(image, [_R_MEAN, _G_MEAN, _B_MEAN])

其实就是减去各个channel的均值。

Evaluation与Test时的预处理

只有白化与resize操作。

  • 1
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值