Esempio n. 1
0
    def read_file_from_db(self, is_training: bool, train_key: List,
                          val_key: List) -> str:
        if is_training:
            if train_key is None:
                raise Exception(
                    "Initialized with validation only.  Training data not downloaded."
                )
            return DATA_STORE.get_file(train_key[0])["fpath"]

        return DATA_STORE.get_file(val_key[0])["fpath"]
Esempio n. 2
0
    def read_file_from_db(self, is_train, task_key, sample=True):
        if sample and not is_train:
            task_path = task_key + "_test"
        else:
            task_path = task_key + "_train" if is_train else task_key

        if not DATA_STORE.is_valid(task_path):
            raise NameError("{0} does not exist.".format(task_path))
        return DATA_STORE.get_file(task_path)["fpath"]
Esempio n. 3
0
    def val_data_stream(self):
        if self.images_val is None:
            raise Exception(
                "Download val_data first by setting validation_only to True")

        for img_id, q_id, a_id in self.index:
            img_key = "vqa/images-val/val2014/COCO_val2014_%012d" % img_id
            img_file = DATA_STORE.get_file(img_key)
            img = self.image_from_file(img_file["fpath"])
            q = self.question_index[q_id]
            #TODO: Fix this hardcode
            a = self.answer_index(True)[(q_id, a_id)]
            yield (img, q, a)
Esempio n. 4
0
    def train_data_stream(self):
        if self.images_train is None:
            raise Exception(
                "Download train_data_first by setting validation_only to False"
            )

        if not self.is_training:
            raise Exception(
                "Build index first with build_index(is_training=True)")

        for img_id, q_id, a_id in self.index:
            img_key = "vqa/images-train/train2014/COCO_train2014_%012d" % img_id
            img_file = DATA_STORE.get_file(img_key)
            img = self.image_from_file(img_file["fpath"])
            q = self.question_index[q_id]
            #TODO: Fix this hardcode
            a = self.answer_index(True)[(q_id, a_id)]
            yield (img, q, a)
        return