def __init__(self, config, subset): super(Davis2017OneshotDataset, self).__init__(config, NUM_CLASSES, VOID_LABEL, subset, image_size=DAVIS2017_IMAGE_SIZE) self._video = None data_dir = config.unicode("davis_data_dir", DAVIS2017_DEFAULT_PATH) self.split = config.unicode("split", "val") assert self.split in ("val", "dev", "eval") if self.split == "val": list_file = "ImageSets/2017/val.txt" elif self.split == "eval": list_file = "ImageSets/2017/test-challenge.txt" else: list_file = "ImageSets/2017/test-dev.txt" if not config.bool("adjustable_output_layer", False): list_file = list_file.replace(".txt", "_ids.txt") imgs, ans = read_image_and_annotation_list_2017(data_dir + list_file, data_dir) self._video_tags = unique_list([im.split("/")[-2] for im in imgs]) self.imgs_seqs = group_into_sequences(imgs) self.ans_seqs = group_into_sequences(ans) only_first_frame_annotation_available = self.split in ("dev", "eval") if only_first_frame_annotation_available: self.ans_seqs = [[ans_seq[0]] + ([None] * (len(ans_seq) - 1)) for ans_seq in self.ans_seqs] self.use_lucid_data = config.int("lucid_interval", -1) != -1 self.lucid_data_dir = config.unicode("davis_lucid_data_dir", DAVIS2017_LUCID_DEFAULT_PATH) self.lucid_data_video = None self.lucid_data_video_current = None
def load_videos(self, fn, data_dir, video_range=None): load_adaptation_data = self.adaptation_model != "" if load_adaptation_data: assert self.config.unicode( "task") == "offline", self.config.unicode("task") elif DavisOneshotDataset._video_data is not None: #use this cache only if not doing offline adaptation! return DavisOneshotDataset._video_data print >> log.v4, "loading davis dataset..." imgs, ans, flows = read_image_and_annotation_list( fn, data_dir, flow_flag=self.twostream) video_tags = unique_list([im.split("/")[-2] for im in imgs]) imgs_seqs = group_into_sequences(imgs) ans_seqs = group_into_sequences(ans) if load_adaptation_data and self.subset == "train": #change annotations from groundtruth to adaptation data for video_tag, ans in zip(video_tags, ans_seqs): for idx in xrange(1, len(ans)): ans[idx] = "forwarded/" + self.adaptation_model + "/valid/" + video_tag + ( "/adaptation_%05d.png" % idx) start = time.time() videos = [None] * len(imgs_seqs) if video_range is None: video_range = [0, len(imgs_seqs)] # from joblib import Parallel, delayed # videos[video_range[0]:video_range[1]] = Parallel(n_jobs=20, backend="threading")(delayed(_load_video)( # imgs, ans, self.flow_dir, self.flow_into_past, self.flow_into_future, self.flow_as_angle) for # (imgs, ans) in zip(imgs_seqs, ans_seqs)[video_range[0]:video_range[1]]) if self.twostream: flows_seqs = group_into_sequences(flows) videos[video_range[0]:video_range[1]] = [ _load_video(imgs, ans, self.flow_dir, self.flow_into_past, self.flow_into_future, self.flow_as_angle, flows) for (imgs, ans, flows) in zip(imgs_seqs, ans_seqs, flows_seqs) [video_range[0]:video_range[1]] ] else: videos[video_range[0]:video_range[1]] = [ _load_video(imgs, ans, self.flow_dir, self.flow_into_past, self.flow_into_future, self.flow_as_angle) for (imgs, ans) in zip(imgs_seqs, ans_seqs) [video_range[0]:video_range[1]] ] DavisOneshotDataset._video_data = (video_tags, videos) end = time.time() elapsed = end - start print >> log.v4, "loaded davis in", elapsed, "seconds" return DavisOneshotDataset._video_data
def read_inputfile_lists(self): assert self.subset in ("train", "valid"), self.subset list_file = get_input_list_file(self.subset, self.trainsplit) imgs, labels = read_image_and_annotation_list( self.data_dir + list_file, self.data_dir) imgs = group_into_sequences(imgs) labels = group_into_sequences(labels) old_labels = [x[:-1] for x in labels] # filter out first frames, since we have no old masks and no flow imgs = [x[1:] for x in imgs] labels = [x[1:] for x in labels] # if we use flow_into_future also filter out last frames if self.flow_into_future: imgs = [x[:-1] for x in imgs] labels = [x[:-1] for x in labels] old_labels = [x[:-1] for x in old_labels] #flatten lists of lists imgs = sum(imgs, []) labels = sum(labels, []) old_labels = sum(old_labels, []) flows = [] if self.flow_into_past: flow_past = [ self.flow_dir + "Flow_backward/" + x[x.index("480p"):].replace(".jpg", ".flo") for x in imgs ] flows.append(flow_past) if self.flow_into_future: flow_future = [ self.flow_dir + "Flow_forward/" + x[x.index("480p"):].replace(".jpg", ".flo") for x in imgs ] flows.append(flow_future) assert len(imgs) == len(labels) == len(old_labels) assert all([len(f) == len(imgs) for f in flows]) return [imgs, labels, old_labels] + flows