Example #1
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)
Example #2
0
 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)
Example #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)
Example #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 = image_test_util.infer_keep_aspect_ratio_resized_images_static_shape(
         target_size=target_size,
         min_size=min_size,
         max_size=max_size,
         aspect_ratio_list=aspect_ratio_list,
         resize_side=resize_side,
         channels=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)
Example #5
0
 def coco_load_fn():
     with flow.scope.placement("cpu", "0:0-{}".format(nthread - 1)):
         (
             image,
             image_id,
             image_size,
             gt_bbox,
             gt_label,
             gt_segm,
             gt_segm_index,
         ) = flow.data.coco_reader(
             annotation_file=anno_file,
             image_dir=image_dir,
             batch_size=batch_size,
             shuffle=shuffle_after_epoch,
             stride_partition=stride_partition,
             name="COCOReader",
         )
         if ret_image_id_only:
             return image_id
         decoded_image = flow.image_decode(image, dtype=flow.float)
         image_list = flow.tensor_buffer_to_tensor_list(decoded_image,
                                                        shape=(800, 1333,
                                                               3),
                                                        dtype=flow.float)
         bbox_list = flow.tensor_buffer_to_tensor_list(gt_bbox,
                                                       shape=(128, 4),
                                                       dtype=flow.float)
         label_list = flow.tensor_buffer_to_tensor_list(gt_label,
                                                        shape=(128, ),
                                                        dtype=flow.int32)
         segm_list = flow.tensor_buffer_to_tensor_list(gt_segm,
                                                       shape=(1024, 2),
                                                       dtype=flow.float)
         segm_index_list = flow.tensor_buffer_to_tensor_list(
             gt_segm_index, shape=(1024, 3), dtype=flow.int32)
     return (
         image_id,
         image_size,
         image_list,
         bbox_list,
         label_list,
         segm_list,
         segm_index_list,
     )
Example #6
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)
 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)
Example #8
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=target_size,
                                        max_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)
Example #9
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)