def crop_or_resize_to_fixed_size_and_rotate_output(img_tensor,
annotation_tensor,
output_shape,
mask_out_num=None):
"""Returns tensor of a size (output_shape, output_shape, depth) and (output_shape, output_shape, 1).
The function returns tensor that is of a size (output_shape, output_shape, depth)
which is randomly cropped and rotate
Parameters
----------
img_tensor : Tensor of size (width, height, depth)
Tensor with image
annotation_tensor : Tensor of size (width, height, 1)
Tensor with respective annotation
output_shape : Tensor or list [int, int]
Tensor of list representing desired output shape
mask_out_number : int
Number representing the mask out value.
Returns
-------
cropped_padded_img : Tensor of size (output_shape[0], output_shape[1], 3).
Image Tensor that was randomly scaled
cropped_padded_annotation : Tensor of size (output_shape[0], output_shape[1], 1)
Respective annotation Tensor that was randomly scaled with the same parameters
"""
input_shape = tf.shape(img_tensor)[0:2]
image_width, image_height = input_shape[0],input_shape[1]
crop_width, crop_height = output_shape[0],output_shape[1]
cropped_padded_img,cropped_padded_annotaion = control_flow_ops.cond(
tf.logical_and(
tf.greater_equal(image_height, crop_height),
tf.greater_equal(image_width, crop_width)),
fn1=lambda:crop_to_fixed_size(img_tensor,annotation_tensor,output_shape),
fn2=lambda:resize_to_fixed_size(img_tensor,annotation_tensor,output_shape,mask_out_num=mask_out_num))
return cropped_padded_img,cropped_padded_annotaion
评论列表
文章目录