Beispiel #1
0
    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
Beispiel #3
0
def group_into_sequences(fns):
    seqs = unique_list([fn.split("/")[-2] for fn in fns])
    seq_fns = [[fn for fn in fns if fn.split("/")[-2] == seq] for seq in seqs]
    return seq_fns