mobilenetdet_preprocessing.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:MobileNet 作者: Zehaos 项目源码 文件源码
def flip_with_bboxes(image, bboxes):
  uniform_random = tf.random_uniform([], 0, 1.0)
  mirror_cond = tf.less(uniform_random, .5)
  stride = tf.where(mirror_cond, -1, 1)

  def flip(image, bboxes, stride):
    image = image[:, ::stride, :]
    img_w = tf.cast(tf.shape(image)[1], dtype=tf.float32)
    bbox_coords = tf.unstack(bboxes, num=4, axis=1)
    y_min = bbox_coords[0]
    x_min = bbox_coords[1]
    y_max = bbox_coords[2]
    x_max = bbox_coords[3]
    x_min_flip = img_w - x_max
    x_max_flip = img_w - x_min
    bboxes = tf.stack([y_min, x_min_flip, y_max, x_max_flip], 1, name='flip_bboxes')
    return image, bboxes

  def not_flip(image, bboxes):
    return image, bboxes

  image_fliped, bboxes = tf.cond(mirror_cond, lambda: flip(image, bboxes, stride), lambda: not_flip(image, bboxes))

  return tf_image.fix_image_flip_shape(image, image_fliped), bboxes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号