def _random_crop_and_resize_image(cls, image, bbox, height, width,
val=False):
with tf.name_scope('random_crop_and_resize'):
if not val:
# bbox_begin, bbox_size, distorted_bbox = \
bbox_begin, bbox_size, _ = \
tf.image.sample_distorted_bounding_box(
tf.shape(image),
bounding_boxes=bbox,
min_object_covered=0.1,
aspect_ratio_range=[0.8, 1.25],
area_range=[0.1, 1.0],
max_attempts=100,
use_image_if_no_bounding_boxes=True)
# Crop the image to the distorted bounding box
image = tf.slice(image, bbox_begin, bbox_size)
# Resize to the desired output size
image = tf.image.resize_images(
image,
[height, width],
tf.image.ResizeMethod.BILINEAR,
align_corners=False)
image.set_shape([height, width, 3])
return image
评论列表
文章目录