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
def create_input_tensors_dict(self, batch_size): use_index_img = self.subset != "train" tensors = create_tensor_dict( unnormalized_img=self.img_placeholder, label=self.label_placeholder, tag=self.tag_placeholder, raw_label=self.label_placeholder, old_label=self.old_label_placeholder, flow_past=self.flow_into_past_placeholder, flow_future=self.flow_into_future_placeholder, use_index_img=use_index_img, u0=self.u0_placeholder, u1=self.u1_placeholder) # TODO: need to set shape here? resize_mode, input_size = self._get_resize_params( self.subset, self.image_size) tensors = resize(tensors, resize_mode, input_size) if len(input_size) == 3: input_size = input_size[1:] tensors = self._prepare_augmented_batch(tensors, batch_size, image_size=input_size) if self.use_summaries: inputs = tensors["inputs"] summ0 = tf.summary.image("inputs", unnormalize(inputs[:, :, :, :3])) summ1 = tf.summary.image( "labels", tensors["labels"] * 255) # will only work well for binary segmentation self.summaries.append(summ0) self.summaries.append(summ1) # Old label would be present either as a single channel, or along with 2 other distance transform channels. if inputs.get_shape()[-1] == 4 or inputs.get_shape == 6: summ2 = tf.summary.image("old_labels", inputs[:, :, :, 3:4] * 255) self.summaries.append(summ2) return tensors
def create_input_tensors_dict(self, batch_size): use_index_img = self.subset != "train" tensors = create_tensor_dict( unnormalized_img=self.img_placeholder, label=self.label_placeholder, tag=self.tag_placeholder, raw_label=self.label_placeholder, old_label=self.old_label_placeholder, flow_past=self.flow_into_past_placeholder, flow_future=self.flow_into_future_placeholder, use_index_img=use_index_img, u0=self.u0_placeholder, u1=self.u1_placeholder, flow=self.flow_placeholder) # TODO: need to set shape here? resize_mode, input_size = self._get_resize_params( self.subset, self.image_size) tensors = resize(tensors, resize_mode, input_size) if len(input_size) == 3: input_size = input_size[1:] tensors = self._prepare_augmented_batch(tensors, batch_size, image_size=input_size) if self.use_summaries: inputs = tensors["inputs"] summ0 = tf.summary.image("inputs", unnormalize(inputs[:, :, :, :3])) summ1 = tf.summary.image( "labels", tensors["labels"] * 255) # will only work well for binary segmentation self.summaries.append(summ0) self.summaries.append(summ1) return tensors
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
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