python类load()的实例源码

vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def load_genome_json():
        """
        Parses the genome json file. Returns the question dictionary and the
        answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS['genome']['genome_file'], 'r') as f:
            qdata = json.load(f)
            for q in qdata:
                key = 'genome' + QID_KEY_SEPARATOR + str(q['id'])
                qdic[key] = {'qstr': q['question'], 'iid': q['image']}
                adic[key] = [{'answer': q['answer']}]

        write_log('parsed ' + str(len(qdic)) + ' questions for genome', 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, batchsize=64, max_length=config.MAX_WORDS_IN_QUESTION, mode='train'):
        self.batchsize = batchsize
        self.d_vocabulary = None
        self.batch_index = None
        self.batch_len = None
        self.rev_adict = None
        self.max_length = max_length
        self.mode = mode
        #self.max_length, self.qdic, self.adic = VQADataProvider.load_data(mode)
        self.qdic, self.adic = VQADataProvider.load_data(mode)

        with open('./result/vdict.json','r') as f:
            self.vdict = json.load(f)
        with open('./result/adict.json','r') as f:
            self.adict = json.load(f)

        self.n_ans_vocabulary = len(self.adict)
        # self.nlp = spacy.load('en', vectors='en_glove_cc_300_1m_vectors')
        # self.glove_dict = {} # word -> glove vector
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def load_vqa_json(data_split):
        """
        Parses the question and answer json files for the given data split.
        Returns the question dictionary and the answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS[data_split]['ques_file'], 'r') as f:
            qdata = json.load(f)['questions']
            for q in qdata:
                qdic[data_split + QID_KEY_SEPARATOR + str(q['question_id'])] = \
                    {'qstr': q['question'], 'iid': q['image_id']}

        if 'test' not in data_split:
            with open(config.DATA_PATHS[data_split]['ans_file'], 'r') as f:
                adata = json.load(f)['annotations']
                for a in adata:
                    adic[data_split + QID_KEY_SEPARATOR + str(a['question_id'])] = \
                        a['answers']

        write_log('parsed ' + str(len(qdic)) + ' questions for ' + data_split, 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def load_genome_json():
        """
        Parses the genome json file. Returns the question dictionary and the
        answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS['genome']['genome_file'], 'r') as f:
            qdata = json.load(f)
            for q in qdata:
                key = 'genome' + QID_KEY_SEPARATOR + str(q['id'])
                qdic[key] = {'qstr': q['question'], 'iid': q['image']}
                adic[key] = [{'answer': q['answer']}]

        write_log('parsed ' + str(len(qdic)) + ' questions for genome', 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def __init__(self, batchsize=64, max_length=config.MAX_WORDS_IN_QUESTION, max_w_length=config.LENGTH_OF_LONGEST_WORD, mode='train'):
        self.batchsize = batchsize
        self.d_vocabulary = None
        self.batch_index = None
        self.batch_len = None
        self.rev_adict = None
        self.max_length = max_length
        self.max_w_length = max_w_length
        self.mode = mode
        self.qdic, self.adic = VQADataProvider.load_data(mode)

        with open('./result/cdict.json','r') as f:
            self.cdict = json.load(f)
        with open('./result/vdict.json','r') as f:
            self.vdict = json.load(f)
        with open('./result/adict.json','r') as f:
            self.adict = json.load(f)

        self.n_ans_vocabulary = len(self.adict)
        #self.nlp = spacy.load('en', vectors='en_glove_cc_300_1m_vectors')
        #self.glove_dict = {} # word -> glove vector
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def load_vqa_json(data_split):
        """
        Parses the question and answer json files for the given data split. 
        Returns the question dictionary and the answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS[data_split]['ques_file'], 'r') as f:
            qdata = json.load(f)['questions']
            for q in qdata:
                qdic[data_split + QID_KEY_SEPARATOR + str(q['question_id'])] = \
                    {'qstr': q['question'], 'iid': q['image_id']}

        if 'test' not in data_split:
            with open(config.DATA_PATHS[data_split]['ans_file'], 'r') as f:
                adata = json.load(f)['annotations']
                for a in adata:
                    adic[data_split + QID_KEY_SEPARATOR + str(a['question_id'])] = \
                        a['answers']

        write_log('parsed ' + str(len(qdic)) + ' questions for ' + data_split, 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def load_genome_json():
        """
        Parses the genome json file. Returns the question dictionary and the
        answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS['genome']['genome_file'], 'r') as f:
            qdata = json.load(f)
            for q in qdata:
                key = 'genome' + QID_KEY_SEPARATOR + str(q['id'])
                qdic[key] = {'qstr': q['question'], 'iid': q['image']}
                adic[key] = [{'answer': q['answer']}]

        write_log('parsed ' + str(len(qdic)) + ' questions for genome', 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, batchsize=64, max_length=config.MAX_WORDS_IN_QUESTION, mode='train'):
        self.batchsize = batchsize
        self.d_vocabulary = None
        self.batch_index = None
        self.batch_len = None
        self.rev_adict = None
        self.max_length = max_length
        self.mode = mode
        # self.max_length, self.qdic, self.adic = VQADataProvider.load_data(mode)
        self.qdic, self.adic = VQADataProvider.load_data(mode)

        with open('./result/vdict.json','r') as f:
            self.vdict = json.load(f)
        with open('./result/adict.json','r') as f:
            self.adict = json.load(f)

        self.n_ans_vocabulary = len(self.adict)
        # self.nlp = spacy.load('en', vectors='en_glove_cc_300_1m_vectors')
        # self.glove_dict = {} # word -> glove vector
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def load_genome_json():
        """
        Parses the genome json file. Returns the question dictionary and the
        answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS['genome']['genome_file'], 'r') as f:
            qdata = json.load(f)
            for q in qdata:
                key = 'genome' + QID_KEY_SEPARATOR + str(q['id'])
                qdic[key] = {'qstr': q['question'], 'iid': q['image']}
                adic[key] = [{'answer': q['answer']}]

        write_log('parsed ' + str(len(qdic)) + ' questions for genome', 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, batchsize=64, max_length=config.MAX_WORDS_IN_QUESTION, mode='train'):
        self.batchsize = batchsize
        self.d_vocabulary = None
        self.batch_index = None
        self.batch_len = None
        self.rev_adict = None
        self.max_length = max_length
        self.mode = mode
        self.qdic, self.adic = VQADataProvider.load_data(mode)

        with open('./result/vdict.json','r') as f:
            self.vdict = json.load(f)
        with open('./result/adict.json','r') as f:
            self.adict = json.load(f)

        self.n_ans_vocabulary = len(self.adict)
        # self.nlp = spacy.load('en', vectors='en_glove_cc_300_1m_vectors')
        # self.glove_dict = {} # word -> glove vector
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def load_vqa_json(data_split):
        """
        Parses the question and answer json files for the given data split. 
        Returns the question dictionary and the answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS[data_split]['ques_file'], 'r') as f:
            qdata = json.load(f)['questions']
            for q in qdata:
                qdic[data_split + QID_KEY_SEPARATOR + str(q['question_id'])] = \
                    {'qstr': q['question'], 'iid': q['image_id']}

        if 'test' not in data_split:
            with open(config.DATA_PATHS[data_split]['ans_file'], 'r') as f:
                adata = json.load(f)['annotations']
                for a in adata:
                    adic[data_split + QID_KEY_SEPARATOR + str(a['question_id'])] = \
                        a['answers']

        write_log('parsed ' + str(len(qdic)) + ' questions for ' + data_split, 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def load_genome_json():
        """
        Parses the genome json file. Returns the question dictionary and the
        answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS['genome']['genome_file'], 'r') as f:
            qdata = json.load(f)
            for q in qdata:
                key = 'genome' + QID_KEY_SEPARATOR + str(q['id'])
                qdic[key] = {'qstr': q['question'], 'iid': q['image']}
                adic[key] = [{'answer': q['answer']}]

        write_log('parsed ' + str(len(qdic)) + ' questions for genome', 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, batchsize=64, max_length=config.MAX_WORDS_IN_QUESTION, mode='train'):
        self.batchsize = batchsize
        self.d_vocabulary = None
        self.batch_index = None
        self.batch_len = None
        self.rev_adict = None
        self.max_length = max_length
        self.mode = mode
        #self.max_length, self.qdic, self.adic = VQADataProvider.load_data(mode)
        self.qdic, self.adic = VQADataProvider.load_data(mode)

        with open('./result/vdict.json','r') as f:
            self.vdict = json.load(f)
        with open('./result/adict.json','r') as f:
            self.adict = json.load(f)

        self.n_ans_vocabulary = len(self.adict)
        # self.nlp = spacy.load('en', vectors='en_glove_cc_300_1m_vectors')
        # self.glove_dict = {} # word -> glove vector
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def load_vqa_json(data_split):
        """
        Parses the question and answer json files for the given data split.
        Returns the question dictionary and the answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS[data_split]['ques_file'], 'r') as f:
            qdata = json.load(f)['questions']
            for q in qdata:
                qdic[data_split + QID_KEY_SEPARATOR + str(q['question_id'])] = \
                    {'qstr': q['question'], 'iid': q['image_id']}

        if 'test' not in data_split:
            with open(config.DATA_PATHS[data_split]['ans_file'], 'r') as f:
                adata = json.load(f)['annotations']
                for a in adata:
                    adic[data_split + QID_KEY_SEPARATOR + str(a['question_id'])] = \
                        a['answers']

        write_log('parsed ' + str(len(qdic)) + ' questions for ' + data_split, 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def load_genome_json():
        """
        Parses the genome json file. Returns the question dictionary and the
        answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS['genome']['genome_file'], 'r') as f:
            qdata = json.load(f)
            for q in qdata:
                key = 'genome' + QID_KEY_SEPARATOR + str(q['id'])
                qdic[key] = {'qstr': q['question'], 'iid': q['image']}
                adic[key] = [{'answer': q['answer']}]

        write_log('parsed ' + str(len(qdic)) + ' questions for genome', 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def __init__(self, batchsize=64, max_length=config.MAX_WORDS_IN_QUESTION, mode='train'):
        self.batchsize = batchsize
        self.d_vocabulary = None
        self.batch_index = None
        self.batch_len = None
        self.rev_adict = None
        self.max_length = max_length
        self.mode = mode
        #self.max_length, self.qdic, self.adic = VQADataProvider.load_data(mode)
        self.qdic, self.adic = VQADataProvider.load_data(mode)

        with open('./result/vdict.json','r') as f:
            self.vdict = json.load(f)
        with open('./result/adict.json','r') as f:
            self.adict = json.load(f)

        self.n_ans_vocabulary = len(self.adict)
        # self.nlp = spacy.load('en', vectors='en_glove_cc_300_1m_vectors')
        # self.glove_dict = {} # word -> glove vector
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def load_genome_json():
        """
        Parses the genome json file. Returns the question dictionary and the
        answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS['genome']['genome_file'], 'r') as f:
            qdata = json.load(f)
            for q in qdata:
                key = 'genome' + QID_KEY_SEPARATOR + str(q['id'])
                qdic[key] = {'qstr': q['question'], 'iid': q['image']}
                adic[key] = [{'answer': q['answer']}]

        write_log('parsed ' + str(len(qdic)) + ' questions for genome', 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, batchsize=64, max_length=config.MAX_CHARS_IN_QUESTION, mode='train'):
        self.batchsize = batchsize
        self.d_vocabulary = None
        self.batch_index = None
        self.batch_len = None
        self.rev_adict = None
        self.max_length = max_length
        self.mode = mode
        self.qdic, self.adic = VQADataProvider.load_data(mode)

        with open('./result/cdict.json','r') as f:
            self.cdict = json.load(f)
        with open('./result/adict.json','r') as f:
            self.adict = json.load(f)

        self.n_ans_vocabulary = len(self.adict)
        #self.nlp = spacy.load('en', vectors='en_glove_cc_300_1m_vectors')
        #self.glove_dict = {} # word -> glove vector
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def load_vqa_json(data_split):
        """
        Parses the question and answer json files for the given data split. 
        Returns the question dictionary and the answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS[data_split]['ques_file'], 'r') as f:
            qdata = json.load(f)['questions']
            for q in qdata:
                qdic[data_split + QID_KEY_SEPARATOR + str(q['question_id'])] = \
                    {'qstr': q['question'], 'iid': q['image_id']}

        if 'test' not in data_split:
            with open(config.DATA_PATHS[data_split]['ans_file'], 'r') as f:
                adata = json.load(f)['annotations']
                for a in adata:
                    adic[data_split + QID_KEY_SEPARATOR + str(a['question_id'])] = \
                        a['answers']

        write_log('parsed ' + str(len(qdic)) + ' questions for ' + data_split, 'log.txt')
        return qdic, adic
vqa_data_provider_layer.py 文件源码 项目:vqa-text 作者: divelab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def load_genome_json():
        """
        Parses the genome json file. Returns the question dictionary and the
        answer dictionary.
        """
        qdic, adic = {}, {}

        with open(config.DATA_PATHS['genome']['genome_file'], 'r') as f:
            qdata = json.load(f)
            for q in qdata:
                key = 'genome' + QID_KEY_SEPARATOR + str(q['id'])
                qdic[key] = {'qstr': q['question'], 'iid': q['image']}
                adic[key] = [{'answer': q['answer']}]

        write_log('parsed ' + str(len(qdic)) + ' questions for genome', 'log.txt')
        return qdic, adic


问题


面经


文章

微信
公众号

扫码关注公众号