Exemplo n.º 1
0
 def _load_crop_helper(self, img_file_name, img_bbox):
   img_whole_im = load_image_tensorflow(img_file_name, jpg=self.jpg, channels=3)
   dims = tf.shape(img_whole_im)
   img_x = img_bbox[0]
   img_y = img_bbox[1]
   img_w = img_bbox[2]
   img_h = img_bbox[3]
   # add context region
   img_x -= 0.5 * img_w * (self.context_region_factor - 1.0)
   img_y -= 0.5 * img_h * (self.context_region_factor - 1.0)
   img_w *= self.context_region_factor
   img_h *= self.context_region_factor
   # round to integer coordinates
   img_x = tf.cast(tf.round(img_x), tf.int32)
   img_y = tf.cast(tf.round(img_y), tf.int32)
   img_w = tf.cast(tf.round(img_w), tf.int32)
   img_h = tf.cast(tf.round(img_h), tf.int32)
   # clip to image size
   img_x = tf.maximum(img_x, 0)
   img_y = tf.maximum(img_y, 0)
   img_excess_w = tf.maximum(img_x + img_w - dims[1], 0)
   img_excess_h = tf.maximum(img_y + img_h - dims[0], 0)
   img_w = img_w - img_excess_w
   img_h = img_h - img_excess_h
   # crop
   img_cropped = img_whole_im[img_y:img_y + img_h, img_x:img_x + img_w]
   # resize
   img = resize_image(img_cropped, self.input_size, True)
   img.set_shape(self.input_size + (3,))
   # augment and normalize
   tensors = {"unnormalized_img": img}
   tensors = apply_augmentors(tensors, self.augmentors)
   img = tensors["unnormalized_img"]
   img_norm = normalize(img)
   return img_norm, img, img_cropped
Exemplo n.º 2
0
    def _load_crop_helper(self, img_file_name, img_bbox):
        img = load_image_tensorflow(img_file_name, jpg=self.jpg, channels=3)

        img.set_shape(self.input_size + (3, ))
        # augment and normalize
        tensors = {"unnormalized_img": img}
        tensors = apply_augmentors(tensors, self.augmentors)
        img = tensors["unnormalized_img"]
        img_norm = normalize(img)
        return img_norm, img, None
Exemplo n.º 3
0
    def do_one_crop(self, box):
        # Do the crop and resize myself
        x = tf.cast(box[0], tf.int32)
        y = tf.cast(box[1], tf.int32)
        w = tf.cast(box[2], tf.int32)
        h = tf.cast(box[3], tf.int32)
        # image = tf.expand_dims(self.image, 0)
        img_cropped = self.conv_image[y:y + h, x:x + w]
        min_dim = tf.minimum(h, w)

        # # resize
        # img = resize_image(img_cropped, self.input_size, True)

        # resize
        img = tf.cond(
            min_dim > 10,
            lambda: resize_image(img_cropped, self.input_size, True),
            lambda: tf.zeros([self.input_size[0], self.input_size[1], 3]))

        # img.set_shape(self.input_size + (3,))
        norm_img = normalize(img)
        return norm_img
Exemplo n.º 4
0
def load_normalized_image_tensorflow(im_path, jpg):
    img = load_image_tensorflow(im_path, jpg=jpg)
    img = normalize(img)
    return img
Exemplo n.º 5
0
def assemble_input_tensors(tensors, img_size=(None, None)):
  img_size = list(img_size)
  assert "unnormalized_img" in tensors
  assert "tag" in tensors

  img = tensors["unnormalized_img"]
  img = normalize(img)
  tag = tensors["tag"]
  if "label" in tensors:
    label = tensors["label"]
  else:
    label = None
  if "raw_label" in tensors:
    raw_label = tensors["raw_label"]
  else:
    raw_label = label
  concats = [img]
  n_input_channels = 3
  if "old_label" in tensors:
    old_label = tf.cast(tensors["old_label"], tf.float32)

    if Constants.OLD_LABEL_AS_DT in tensors and tensors[Constants.OLD_LABEL_AS_DT] is True:
      clip_value = tf.ones_like(old_label) * 255
      old_label = tf.where(tf.greater(old_label, 255), clip_value, old_label)
      old_label /= 255.0

    concats.append(old_label)
    n_input_channels += 1

  if Constants.DT_NEG in tensors:
    # Do not use the click channel as they can be deciphered from the distance transforms.
    u0 = tensors[Constants.DT_NEG]
    u0 = tf.cast(u0, tf.float32)
    clip_value = tf.ones_like(u0)*255
    u0 = tf.where(tf.greater(u0, 255), clip_value, u0)
    u0 /= 255.0
    concats.append(u0)
    n_input_channels += u0.get_shape().as_list()[-1]
  if Constants.DT_POS in tensors:
    u1 = tensors[Constants.DT_POS]
    u1 = tf.cast(u1, tf.float32)
    clip_value = tf.ones_like(u1) * 255
    u1 = tf.where(tf.greater(u1, 255), clip_value, u1 )
    u1 /= 255.0
    concats.append(u1)
    n_input_channels += u1.get_shape().as_list()[-1]
  if "flow_past" in tensors:
    concats.append(tensors["flow_past"])
    n_input_channels += 2
  if "flow_future" in tensors:
    concats.append(tensors["flow_future"])
    n_input_channels += 2
  if len(concats) > 1:
    img = tf.concat(concats, axis=2)

  img.set_shape(img_size + [n_input_channels])

  tensors_out = {"inputs": img, "tags": tag}
  if label is not None:
    tensors_out["labels"] = label
  if raw_label is not None:
    tensors_out["raw_labels"] = raw_label
  if "index_img" in tensors:
    tensors_out["index_imgs"] = tensors["index_img"]
  #TODO: maybe just start with a copy of tensors instead of doing every case separately?
  if Constants.BBOXES in tensors:
    tensors_out[Constants.BBOXES] = tensors[Constants.BBOXES]
  if Constants.IDS in tensors:
    tensors_out[Constants.IDS] = tensors[Constants.IDS]
  if Constants.CLASSES in tensors:
    tensors_out[Constants.CLASSES] = tensors[Constants.CLASSES]
  if Constants.IMG_IDS in tensors:
    tensors_out[Constants.IMG_IDS] = tensors[Constants.IMG_IDS]
  if Constants.ORIGINAL_SIZES in tensors:
    tensors_out[Constants.ORIGINAL_SIZES] = tensors[Constants.ORIGINAL_SIZES]
  if Constants.RESIZED_SIZES in tensors:
    tensors_out[Constants.RESIZED_SIZES] = tensors[Constants.RESIZED_SIZES]
  if Constants.IGNORE_REGIONS in tensors:
    tensors_out[Constants.IGNORE_REGIONS] = tensors[Constants.IGNORE_REGIONS]
  if Constants.SCENE_INFOS in tensors:
    tensors_out[Constants.SCENE_INFOS] = tensors[Constants.SCENE_INFOS]
  if Constants.OLD_LABEL_AS_DT in tensors:
    tensors_out[Constants.OLD_LABEL_AS_DT] = tensors[Constants.OLD_LABEL_AS_DT]
  return tensors_out