Exemplo n.º 1
0
    def _prepare_augmented_batch(self, tensors, batch_size, image_size=None):
        if self.subset == "train":
            assert batch_size == 1, "only implemented for 1 so far"
            augmentor_strs = self.config.unicode_list("augmentors_train", [])
            augmentors = parse_augmentors(augmentor_strs, self.void_label())
            for augmentor in augmentors:
                tensors = augmentor.apply(tensors)
            if image_size is None:
                image_size = self.image_size
            tensors = assemble_input_tensors(tensors, image_size)

            # batchify
            keys = tensors.keys()
            tensors = {k: tf.expand_dims(tensors[k], axis=0) for k in keys}
        else:
            augmentor_strs = self.config.unicode_list("augmentors_val", [])
            assert "scale" not in augmentor_strs, "scale augmentation during test time not implemented yet"
            assert "translation" not in augmentor_strs, "translation augmentation during test time not implemented yet"
            augmentors = parse_augmentors(augmentor_strs, self.void_label())
            tensors = [tensors for _ in xrange(batch_size)]
            tensors = [apply_augmentors(t, augmentors) for t in tensors]
            tensors = [assemble_input_tensors(t) for t in tensors]
            # batchify
            keys = tensors[0].keys()
            tensors = {
                k: tf.stack([t[k] for t in tensors], axis=0)
                for k in keys
            }
        return tensors
Exemplo n.º 2
0
    def _prepare_augmented_batch(self, tensors, batch_size, image_size=None):
        if self.subset == "train":
            assert batch_size == 1, "only implemented for 1 so far"
            augmentor_strs = self.config.unicode_list("augmentors_train", [])
            augmentors = parse_augmentors(augmentor_strs, self.void_label())
            for augmentor in augmentors:
                tensors = augmentor.apply(tensors)
            if image_size is None:
                image_size = self.image_size
            tensors = assemble_input_tensors(tensors, image_size)

            # batchify
            keys = list(tensors.keys())
            tensors = {k: tf.expand_dims(tensors[k], axis=0) for k in keys}

            # for testing
            # from datasets.Util.Normalization import unnormalize
            # summ0 = tf.summary.image("inputs", unnormalize(tensors["inputs"][:, :, :, :3]))
            # summ1 = tf.summary.image("labels", tensors["labels"] * 255)
            # summ2 = tf.summary.image("old_labels", tensors["inputs"][:, :, :, 3:4])
            # flow0 = tensors["inputs"][:, :, :, 4:5]
            # flow0 -= tf.reduce_min(flow0)
            # flow0 /= tf.reduce_max(flow0)
            # flow1 = tensors["inputs"][:, :, :, 5:6]
            # flow1 -= tf.reduce_min(flow1)
            # flow1 /= tf.reduce_max(flow1)
            # summ3 = tf.summary.image("flow_future_3", flow3)
            # summ4 = tf.summary.image("flow_future_4", flow4)
            # self.summaries += [summ0, summ1, summ2, summ3, summ4]
        else:
            augmentor_strs = self.config.unicode_list("augmentors_val", [])
            assert "scale" not in augmentor_strs, "scale augmentation during test time not implemented yet"
            assert "translation" not in augmentor_strs, "translation augmentation during test time not implemented yet"
            augmentors = parse_augmentors(augmentor_strs, self.void_label())
            tensors = [tensors for _ in range(batch_size)]
            tensors = [apply_augmentors(t, augmentors) for t in tensors]
            tensors = [assemble_input_tensors(t) for t in tensors]
            # batchify
            keys = list(tensors[0].keys())
            tensors = {
                k: tf.stack([t[k] for t in tensors], axis=0)
                for k in keys
            }
        return tensors
Exemplo n.º 3
0
    def _read_inputfiles(self, queue, resize_mode, input_size, augmentors):
        im_path = queue[0]
        label_path = queue[1]
        old_label_path = queue[2]

        img = load_image_tensorflow(im_path, jpg=True)
        old_label = load_png_mask_tensorflow(old_label_path)

        def my_damage_mask(mask):
            return damage_mask(mask, self.old_mask_scale_factor,
                               self.old_mask_shift_absolute,
                               self.old_mask_shift_factor)

        old_label, = tf.py_func(my_damage_mask, [old_label], [tf.float32])

        label = load_png_mask_tensorflow(label_path)

        flow_past = flow_future = None
        if self.flow_into_past:
            flow_past_path = queue[3]
            flow_past = load_flow_from_flo_tensorflow(flow_past_path,
                                                      self.flow_as_angle)
        if self.flow_into_future:
            flow_future_path = queue[4] if self.flow_into_past else queue[3]
            flow_future = load_flow_from_flo_tensorflow(
                flow_future_path, self.flow_as_angle)

        tensors = create_tensor_dict(unnormalized_img=img,
                                     label=label,
                                     tag=im_path,
                                     raw_label=label,
                                     old_label=old_label,
                                     flow_past=flow_past,
                                     flow_future=flow_future)

        resize_mode, input_size = self._get_resize_params(
            self.subset, self.image_size)
        tensors = resize(tensors, resize_mode, input_size)

        for augmentor in augmentors:
            tensors = augmentor.apply(tensors)

        tensors = assemble_input_tensors(tensors, DAVIS_IMAGE_SIZE)
        label.set_shape(list(DAVIS_IMAGE_SIZE) + [1])

        summaries = []

        return tensors, summaries
Exemplo n.º 4
0
def read_images_from_disk(
        input_queue,
        input_size,
        resize_mode,
        label_postproc_fn=lambda x: x,
        augmentors=(),
        label_load_fn=load_label_default,
        img_load_fn=load_img_default,
        distance_transform_fn=Util.create_distance_transform):
    im_path = input_queue[0]
    label_path = input_queue[1]
    if len(input_queue) > 2:
        img_id = input_queue[2]
    else:
        img_id = None
    img = img_load_fn(img_path=im_path)

    #TODO: clean up all this stuff!
    labels = label_load_fn(im_path, label_path)
    if 'label' in list(labels.keys()):
        label = labels['label']
        label = label_postproc_fn(label)
        label.set_shape(img.get_shape().as_list()[:-1] + [1])
    else:
        label = None
    if 'old_label' in list(labels.keys()):
        old_label = labels['old_label']
        old_label.set_shape(img.get_shape().as_list()[:-1] + [1])
    else:
        old_label = None
    if Constants.BBOXES in list(labels.keys()):
        bboxes = labels[Constants.BBOXES]
    else:
        bboxes = None
    if Constants.IDS in list(labels.keys()):
        ids = labels[Constants.IDS]
    else:
        ids = None
    if Constants.CLASSES in list(labels.keys()):
        classes = labels[Constants.CLASSES]
    else:
        classes = None
    if Constants.IGNORE_REGIONS in list(labels.keys()):
        ignore_regions = labels[Constants.IGNORE_REGIONS]
    else:
        ignore_regions = None
    if Constants.SCENE_INFOS in list(labels.keys()):
        scene_infos = labels[Constants.SCENE_INFOS]
    else:
        scene_infos = None
    if Constants.OLD_LABEL_AS_DT in list(labels.keys()):
        old_label_as_dt = labels[Constants.OLD_LABEL_AS_DT]
    else:
        old_label_as_dt = None
    u0 = None
    u1 = None

    tensors = create_tensor_dict(unnormalized_img=img,
                                 label=label,
                                 old_label=old_label,
                                 u0=u0,
                                 u1=u1,
                                 tag=im_path,
                                 raw_label=label,
                                 bboxes=bboxes,
                                 ids=ids,
                                 classes=classes,
                                 img_id=img_id,
                                 ignore_regions=ignore_regions,
                                 scene_infos=scene_infos,
                                 old_label_as_dt=old_label_as_dt)

    tensors = resize(tensors, resize_mode, input_size)

    # Create distance transform after image resize to speed up the computation.
    if Constants.USE_CLICKS in list(labels.keys()):
        assert Constants.STRATEGY in labels and Constants.IGNORE_CLASSES in labels
        tensors = add_distance_transform(tensors, labels,
                                         distance_transform_fn)
    elif Constants.OLD_LABEL_AS_DT in list(labels.keys()):
        tensors["old_label"] = tf.py_func(distance_transform_fn,
                                          [tensors["label"]], [tf.float32])[0]
        tensors["old_label"].set_shape(tensors["label"].get_shape())

    tensors = apply_augmentors(tensors, augmentors)
    tensors = assemble_input_tensors(tensors)

    summaries = []

    return tensors, summaries
Exemplo n.º 5
0
def read_images_from_disk(input_queue,
                          input_size,
                          resize_mode,
                          label_postproc_fn=lambda x: x,
                          augmentors=(),
                          label_load_fn=load_label_default,
                          img_load_fn=load_img_default):
    im_path = input_queue[0]
    label_path = input_queue[1]
    img = img_load_fn(img_path=im_path)

    labels = label_load_fn(im_path, label_path)
    label = labels['label']

    label = label_postproc_fn(label)
    label.set_shape(img.get_shape().as_list()[:-1] + [1])

    old_label = u0 = u1 = None

    if len(input_queue) == 3:
        flow_path = input_queue[2]
        flow = img_load_fn(img_path=flow_path)
    else:
        flow = None

    if 'old_label' in labels.keys():
        old_label = labels['old_label']
        old_label.set_shape(img.get_shape().as_list()[:-1] + [1])
    if Constants.DT_NEG in labels.keys() and Constants.DT_POS in labels.keys():
        u0 = labels[Constants.DT_NEG]
        u0.set_shape(img.get_shape().as_list()[:-1] + [1])
        # Create a negative click map, where the click points are denoted as 1 and the rest of it as 0.
        # This would majorly be used to show the clicks in summaries.
        [neg_clicks] = tf.py_func(create_clicks_map,
                                  [labels['neg_clicks'], u0], [tf.float32],
                                  name="create_click_map")
        neg_clicks.set_shape(img.get_shape().as_list()[:-1] + [1])
        u0 = tf.concat([u0, neg_clicks], axis=2)

        u1 = labels[Constants.DT_POS]
        u1.set_shape(img.get_shape().as_list()[:-1] + [1])
        [pos_clicks] = tf.py_func(create_clicks_map,
                                  [labels['pos_clicks'], u1], [tf.float32],
                                  name="create_click_map")
        pos_clicks.set_shape(img.get_shape().as_list()[:-1] + [1])
        u1 = tf.concat([u1, pos_clicks], axis=2)

        shape = im_path.get_shape()
        im_path = tf.string_join(
            [im_path, tf.as_string(labels['num_clicks'])],
            separator=":",
            name="JoinPath")
        im_path.set_shape(shape)

    tensors = create_tensor_dict(unnormalized_img=img,
                                 label=label,
                                 old_label=old_label,
                                 u0=u0,
                                 u1=u1,
                                 tag=im_path,
                                 raw_label=label,
                                 flow=flow)

    tensors = resize(tensors, resize_mode, input_size)
    tensors = apply_augmentors(tensors, augmentors)
    tensors = assemble_input_tensors(tensors)

    summaries = []

    return tensors, summaries