Esempio n. 1
0
 def map_fn(image):
     input_processor = dataloader.DetectionInputProcessor(
         image, image_size)
     input_processor.normalize_image(mean_rgb, stddev_rgb)
     input_processor.set_scale_factors_to_output_size()
     image = input_processor.resize_and_crop_image()
     image_scale = input_processor.image_scale_to_original
     return image, image_scale
Esempio n. 2
0
def image_preprocess(image, image_size, mean_rgb, stddev_rgb):
    """Preprocess image for inference.

  Args:
    image: input image, can be a tensor or a numpy arary.
    image_size: single integer of image size for square image or tuple of two
      integers, in the format of (image_height, image_width).
    mean_rgb: Mean value of RGB, can be a list of float or a float value.
    stddev_rgb: Standard deviation of RGB, can be a list of float or a float
      value.

  Returns:
    (image, scale): a tuple of processed image and its scale.
  """
    input_processor = dataloader.DetectionInputProcessor(image, image_size)
    input_processor.normalize_image(mean_rgb, stddev_rgb)
    input_processor.set_scale_factors_to_output_size()
    image = input_processor.resize_and_crop_image()
    image_scale = input_processor.image_scale_to_original
    return image, image_scale
  def build_preprocess(self, image):
    config = self.config
    img_size = config.max_size

    bgr = True  # cv2 load image is bgr

    p_image = image
    if bgr:
      # to RGB, efficientdet is trained with PIL
      p_image = p_image[:, :, ::-1]
    #input_processor = dataloader.DetectionInputProcessor(p_image, img_size)
    input_processor = dataloader.DetectionInputProcessor(
        p_image, img_size, config.short_edge_size)
    # make image [0,1] and -mean/var
    input_processor.normalize_image()
    input_processor.set_scale_factors_to_output_size()
    # here the original efficientdet pad image to (max_size, max_size)
    p_image = input_processor.resize_and_crop_image()
    p_image_scale = input_processor.image_scale_to_original
    p_image = tf.expand_dims(p_image, 0)  # [1, H, W, C]
    return p_image, p_image_scale