def poly_to_mask_job( image_def: oft.ListListNumpy.Placeholder(shape=tuple(image_shape), dtype=flow.float), poly_def: oft.ListListNumpy.Placeholder(shape=tuple(poly_shape), dtype=flow.float), poly_index_def: oft.ListListNumpy.Placeholder( shape=tuple(poly_index_shape), dtype=flow.int32), ): images_buffer = flow.tensor_list_to_tensor_buffer(image_def) resized_images_buffer, new_size, scale = flow.image_target_resize( images_buffer, target_size=target_size, max_size=max_size) poly_buffer = flow.tensor_list_to_tensor_buffer(poly_def) poly_index_buffer = flow.tensor_list_to_tensor_buffer(poly_index_def) scaled_poly_buffer = flow.object_segmentation_polygon_scale( poly_buffer, scale) mask_buffer = flow.object_segmentation_polygon_to_mask( scaled_poly_buffer, poly_index_buffer, new_size) mask_list = flow.tensor_buffer_to_tensor_list(mask_buffer, shape=(max_num_segms, target_size, max_size), dtype=flow.int8) scaled_poly_list = flow.tensor_buffer_to_tensor_list( scaled_poly_buffer, shape=poly_shape[1:], dtype=flow.float) return mask_list, scaled_poly_list
def image_target_resize_job(images_def: oft.ListListNumpy.Placeholder( shape=image_static_shape, dtype=flow.float)): images_buffer = flow.tensor_list_to_tensor_buffer(images_def) resized_images_buffer, size, scale = flow.image_target_resize( images_buffer, target_size, max_size) resized_images = flow.tensor_buffer_to_tensor_list( resized_images_buffer, shape=(target_size, max_size, image_static_shape[-1]), dtype=flow.float, ) return resized_images, size, scale
def target_resize_bbox_scale_job( image_def: oft.ListListNumpy.Placeholder(shape=tuple(image_shape), dtype=flow.float), bbox_def: oft.ListListNumpy.Placeholder(shape=tuple(bbox_shape), dtype=flow.float), ): images_buffer = flow.tensor_list_to_tensor_buffer(image_def) resized_images_buffer, new_size, scale = flow.image_target_resize( images_buffer, target_size, max_size) bbox_buffer = flow.tensor_list_to_tensor_buffer(bbox_def) scaled_bbox = flow.object_bbox_scale(bbox_buffer, scale) scaled_bbox_list = flow.tensor_buffer_to_tensor_list( scaled_bbox, shape=bbox_shape[1:], dtype=flow.float) return scaled_bbox_list, new_size
def image_target_resize_job( image: otp.ListListNumpy.Placeholder(shape=image_static_shape, dtype=flow.float) ) -> tp.Tuple[otp.ListListNumpy, otp.ListNumpy, otp.ListNumpy]: image_buffer = flow.tensor_list_to_tensor_buffer(image) res_image_buffer, new_size, scale = flow.image_target_resize( image_buffer, target_size=target_size, max_size=max_size, resize_side="shorter", ) out_shape = image_test_util.infer_keep_aspect_ratio_resized_images_static_shape( target_size=target_size, min_size=None, max_size=max_size, aspect_ratio_list=aspect_ratio_list, resize_side="shorter", channels=3, ) res_image = flow.tensor_buffer_to_tensor_list( res_image_buffer, shape=out_shape, dtype=flow.float, ) return res_image, new_size, scale