Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 def image_flip_job(images_def: oft.ListListNumpy.Placeholder(
     shape=image_shape, dtype=flow.float)):
     images_buffer = flow.tensor_list_to_tensor_buffer(images_def)
     flip_images = flow.image_flip(images_buffer, flip_code)
     return flow.tensor_buffer_to_tensor_list(flip_images,
                                              shape=image_shape[1:],
                                              dtype=flow.float)
Ejemplo n.º 4
0
    def image_resize_keep_aspect_ratio(
        image_list: otp.ListListNumpy.Placeholder(shape=image_static_shape,
                                                  dtype=dtype),
    ) -> tp.Tuple[otp.ListListNumpy, otp.ListNumpy, otp.ListNumpy]:
        image_buffer = flow.tensor_list_to_tensor_buffer(image_list)
        res_image, scale, new_size = flow.image.resize(
            image_buffer,
            target_size=target_size,
            min_size=min_size,
            max_size=max_size,
            keep_aspect_ratio=True,
            resize_side=resize_side,
            interpolation_type=interpolation_type,
        )

        out_shape = _infer_resized_image_static_shape(
            target_size,
            origin_image_size_range,
            resize_side,
            channels,
        )
        if print_debug_info:
            print("resized image_static_shape: {}".format(out_shape))

        res_image = flow.tensor_buffer_to_tensor_list(
            res_image,
            shape=out_shape,
            dtype=dtype,
        )

        return res_image, scale, new_size
 def image_normalize_job(images_def: oft.ListListNumpy.Placeholder(
     shape=image_shape, dtype=flow.float)):
     images_buffer = flow.tensor_list_to_tensor_buffer(images_def)
     norm_images = flow.image_normalize(images_buffer, std, mean)
     return flow.tensor_buffer_to_tensor_list(norm_images,
                                              shape=image_shape[1:],
                                              dtype=flow.float)
Ejemplo n.º 6
0
 def image_decode_job(images_def: oft.ListListNumpy.Placeholder(
     shape=static_shape, dtype=flow.int8)):
     images_buffer = flow.tensor_list_to_tensor_buffer(images_def)
     decoded_images_buffer = flow.image_decode(images_buffer)
     return flow.tensor_buffer_to_tensor_list(decoded_images_buffer,
                                              shape=(640, 640, 3),
                                              dtype=flow.uint8)
 def foo_job(
     input_def: oft.ListListNumpy.Placeholder(shape=(2, 5, 4), dtype=flow.float)
 ):
     tensor_buffer = flow.tensor_list_to_tensor_buffer(input_def)
     return flow.tensor_buffer_to_tensor_list(
         tensor_buffer, shape=(5, 4), dtype=flow.float
     )
Ejemplo n.º 8
0
 def image_batch_align_job(images_def: oft.ListListNumpy.Placeholder(
     shape=input_shape, dtype=flow.float)):
     images_buffer = flow.tensor_list_to_tensor_buffer(images_def)
     image = flow.image_batch_align(images_buffer,
                                    shape=output_shape[1:],
                                    dtype=flow.float,
                                    alignment=alignment)
     return image
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
 def object_segm_poly_flip_job(
     poly_def: oft.ListListNumpy.Placeholder(shape=tuple(poly_shape),
                                             dtype=flow.float),
     image_size_def: oft.ListNumpy.Placeholder(shape=image_size.shape,
                                               dtype=flow.int32),
 ):
     poly_buffer = flow.tensor_list_to_tensor_buffer(poly_def)
     flip_poly = flow.object_segmentation_polygon_flip(
         poly_buffer, image_size_def, flip_code)
     return flow.tensor_buffer_to_tensor_list(flip_poly,
                                              shape=poly_shape[1:],
                                              dtype=flow.float)
Ejemplo n.º 11
0
 def object_bbox_flip_job(
     bbox_def: oft.ListListNumpy.Placeholder(shape=tuple(bbox_shape),
                                             dtype=flow.float),
     image_size_def: oft.ListNumpy.Placeholder(shape=image_size.shape,
                                               dtype=flow.int32),
 ):
     bbox_buffer = flow.tensor_list_to_tensor_buffer(bbox_def)
     flip_bbox = flow.object_bbox_flip(bbox_buffer, image_size_def,
                                       flip_code)
     return flow.tensor_buffer_to_tensor_list(flip_bbox,
                                              shape=bbox_shape[1:],
                                              dtype=flow.float)
Ejemplo n.º 12
0
    def image_resize_to_fixed(image_list: otp.ListListNumpy.Placeholder(
        shape=image_static_shape,
        dtype=origin_dtype)) -> tp.Tuple[otp.ListNumpy, otp.ListNumpy]:
        image_buffer = flow.tensor_list_to_tensor_buffer(image_list)
        res_image, scale, _ = flow.image.resize(
            image_buffer,
            target_size=target_size,
            keep_aspect_ratio=False,
            channels=channels,
            dtype=dtype,
            interpolation_type=interpolation_type,
        )

        return res_image, scale
Ejemplo n.º 13
0
 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
 def job_fn(x_def: oft.ListListNumpy.Placeholder(shape=(2, 5, 4), dtype=flow.float)):
     x = flow.tensor_list_to_tensor_buffer(x_def)
     return flow.tensor_buffer_to_tensor_list(x, shape=(5, 4), dtype=flow.float)