Esempio n. 1
0
    def _get_metainfo(self, index):
        question = gdef.translate_question(self.questions[index])
        scene = gdef.translate_scene(self.scenes[question['image_index']])
        question['scene'] = scene

        question['image_index'] = question['image_index']
        question['image_filename'] = gdef.get_image_filename(scene)
        question['question_index'] = index
        question['question_tokenized'] = nltk.word_tokenize(question['question'])

        # program section
        has_program = False
        if 'program_nsclseq' in question:
            question['program_raw'] = question['program_nsclseq']
            question['program_seq'] = question['program_nsclseq']
            has_program = True
        elif 'program' in question:
            question['program_raw'] = question['program']
            question['program_seq'] = gdef.program_to_nsclseq(question['program'], question)
            has_program = True

        if has_program:
            question['program_tree'] = nsclseq_to_nscltree(question['program_seq'])
            question['program_qsseq'] = nsclseq_to_nsclqsseq(question['program_seq'])
            question['program_qstree'] = nscltree_to_nsclqstree(question['program_tree'])
            question['question_type'] = question['program_seq'][-1]['op']
        else:
            question['question_type'] = None

        return question
Esempio n. 2
0
    def _get_metainfo(self, index):
        question = gdef.translate_question(self.questions[index])
        scene = gdef.translate_scene(self.scenes[question["image_index"]])
        question["scene"] = scene

        question["image_index"] = question["image_index"]
        question["image_filename"] = gdef.get_image_filename(scene)
        question["question_index"] = index
        question["question_tokenized"] = nltk.word_tokenize(question["question"])

        # program section
        has_program = False
        if "program_nsclseq" in question:
            question["program_raw"] = question["program_nsclseq"]
            question["program_seq"] = question["program_nsclseq"]
            has_program = True
        elif "program" in question:
            question["program_raw"] = question["program"]
            question["program_seq"] = gdef.program_to_nsclseq(
                question["program"], question
            )
            has_program = True

        if has_program:
            question["program_tree"] = nsclseq_to_nscltree(question["program_seq"])
            question["program_qsseq"] = nsclseq_to_nsclqsseq(question["program_seq"])
            question["program_qstree"] = nscltree_to_nsclqstree(
                question["program_tree"]
            )
            question["question_type"] = question["program_seq"][-1]["op"]
        else:
            question["question_type"] = None

        return question
Esempio n. 3
0
    def _get_metainfo(self, index):
        qid = index // len(VIEWS)
        view_id = index % len(VIEWS)
        question = gdef.translate_question(self.questions[qid])
        question = copydict(question)
        question["index"] = index
        scene = gdef.translate_scene(self.scenes[question["image_index"]])
        scene = copydict(scene)
        scene["objects_detection"] = scene["objects_detection"][VIEWS[view_id]]
        for obj in scene["objects"]:
            obj["mask"] = obj["mask"][VIEWS[view_id]]
        question["scene"] = scene
        # question["image_index"] = question["image_index"]
        question["view_id"] = view_id
        question["image_filename"] = osp.join(
            gdef.get_image_filename(scene), VIEWS[view_id] + ".png"
        )
        question["question_index"] = qid
        question["question_tokenized"] = nltk.word_tokenize(question["question"])
        # program section
        has_program = False
        if "program_nsclseq" in question:
            question["program_raw"] = question["program_nsclseq"]
            question["program_seq"] = question["program_nsclseq"]
            has_program = True
        elif "program" in question:
            question["program_raw"] = question["program"]
            question["program_seq"] = gdef.program_to_nsclseq(
                question["program"], question
            )
            has_program = True

        if has_program:
            question["program_tree"] = nsclseq_to_nscltree(question["program_seq"])
            question["program_qsseq"] = nsclseq_to_nsclqsseq(question["program_seq"])
            question["program_qstree"] = nscltree_to_nsclqstree(
                question["program_tree"]
            )
            question["question_type"] = question["program_seq"][-1]["op"]
        else:
            question["question_type"] = None
        return question
Esempio n. 4
0
    def __getitem__(self, index):
        feed_dict = deepcopy(self.get_metainfo(index))
        image_index = feed_dict['image_index']

        if self.image_root is not None:
            feed_dict['image'] = Image.open(
                osp.join(self.image_root,
                         feed_dict['image_filename'])).convert('RGB')
            feed_dict['image'] = self.image_transform(feed_dict['image'])
        if self.features_h5 is not None:
            feed_dict['feature'] = self.features[image_index]

        feed_dict['question_raw'] = feed_dict.pop('question')
        feed_dict['question_raw_tokenized'] = feed_dict['question_raw'].split()
        feed_dict['question_type'] = 'exist'
        feed_dict['program_seq'] = gdef.program_to_nsclseq(
            feed_dict.pop('program'))
        feed_dict['program_qsseq'] = nsclseq_to_nsclqsseq(
            feed_dict['program_seq'])
        feed_dict['answer'] = gdef.canonize_answer(feed_dict['answer'],
                                                   feed_dict['question_type'])

        return feed_dict