image_size,
bounding_boxes,
seed=None,
seed2=None,
min_object_covered=0.1,
aspect_ratio_range=None,
area_range=None,
max_attempts=None,
use_image_if_no_bounding_boxes=None,
name=None
)
定义于:tensorflow/python/ops/image_ops_impl.py。
为图像生成单个随机扭曲的边界框。
除了图像识别或对象定位任务中的地面实况标签之外,通常还提供边界框注释。用于训练这种系统的常用技术是随机地扭曲图像,同时保留其内容,即数据增强。这个运算输出中的对象的经随机畸变的局部化。
此Op的输出是单个边界框,可用于裁剪原始图像。输出被返回为3个张量:begin, size和bboxes。前2个张量可以直接输入tf.slice来裁剪图像。后者可以提供给tf.image.draw_bounding_boxes以可视化边界框的外观。
返回的边界框是[y_min, x_min, y_max, x_max]。边界框坐标是[0.0, 1.0]。
参数:
image_size:A Tensor。必须是下列类型之一:uint8,int8,int16,int32,int64。1-D,值是[height, width, channels]。
bounding_boxes:A Tensor,float32型。3-D,形状是[batch, N, 4],描述与图像相关联的N个边界框。
seed:可选,int型,默认为0。如果任一seed或seed2设置为非零值,随机数发生器由给定的seed产生。否则,它由随机数种子产生。
seed2:可选,int型,默认为0。第二粒种子以避免种子碰撞。
min_object_coverd:A Tensor,类型为float32,默认为0.1。图像的裁剪区域必须至少包含所提供的任何边界框的这一部分。此参数的值应为非负值。在0的情况下,裁剪区域不需要与提供的任何边界框重叠。
aspect_ratio_range:可选列表,float型,默认为[0.75, 1.33]。图像的裁剪区域必须具有此范围内的宽高比=宽度/高度。
area_range:可选列表,float型,默认为[0.05, 1]。图像的裁剪区域必须包含此范围内所提供图像的一小部分。
max_attempts:可选,int型,默认为100。生成指定约束的图像的裁剪区域的尝试次数。max_attempts次失败之后,返回整个图像。
use_image_if_no_bouding_boxes:可选,bool型,默认为False。如果未提供边界框,则控制行为。如果为true,则假设覆盖整个输入的隐式边界框。如果为false,则引发错误。
name:操作的名称(可选)。
返回值:
Tensor 对象组成的元组。
begin:A Tensor,和image_size具有相同的类型。1-D,值为[offset_height, offset_width, 0]。作为tf.slice的输入。
size:A Tensor,和image_size具有相同的类型。1-D,值为[target_height, target_width, -1]。作为tf.slice的输入。
bboxes:A Tensor,float32类型。3-D,形状为[1, 1, 4]。作为tf.image.draw_bounding_boxes的输入。
# Generate a single distorted bounding box.
begin, size, bbox_for_draw = tf.image.sample_distorted_bounding_box(
tf.shape(image),
bounding_boxes=bounding_boxes,
min_object_covered=0.1)
# Draw the bounding box in an image summary.
image_with_box = tf.image.draw_bounding_boxes(tf.expand_dims(image, 0),
bbox_for_draw)
tf.summary.image('images_with_box', image_with_box)
# Employ the bounding box to distort the image.
distorted_image = tf.slice(image, begin, size)