Exemplo n.º 1
0
def main(args):
    #设定图像路径、答案路径、问题路径
    image_dir = args.input_dir + '/Resized_Images/%s/'
    annotation_file = args.input_dir + '/Annotations/v2_mscoco_%s_annotations.json'
    question_file = args.input_dir + '/Questions/v2_OpenEnded_mscoco_%s_questions.json'

    vocab_answer_file = args.output_dir + '/vocab_answers.txt'
    answer_dict = text_processing.VocabDict(vocab_answer_file)  #建立类
    valid_answer_set = set(answer_dict.word_list)  #载入文件得到单词列表并将其作为有效的回答集合

    #分别对4类文件夹做处理
    train = vqa_processing(image_dir, annotation_file, question_file,
                           valid_answer_set, 'train2014')
    valid = vqa_processing(image_dir, annotation_file, question_file,
                           valid_answer_set, 'val2014')
    test = vqa_processing(image_dir, annotation_file, question_file,
                          valid_answer_set, 'test2015')
    test_dev = vqa_processing(image_dir, annotation_file, question_file,
                              valid_answer_set, 'test-dev2015')

    #保存整合后的数据集到npy文件
    np.save(args.output_dir + '/train.npy', np.array(train))
    np.save(args.output_dir + '/valid.npy', np.array(valid))
    np.save(args.output_dir + '/train_valid.npy', np.array(train + valid))
    np.save(args.output_dir + '/test.npy', np.array(test))
    np.save(args.output_dir + '/test-dev.npy', np.array(test_dev))
Exemplo n.º 2
0
 def __init__(self,
              input_dir,
              input_vqa,
              max_qst_length=30,
              max_num_ans=10,
              transform=None):
     self.input_dir = input_dir
     self.vqa = np.load(input_dir + '/' + input_vqa)
     self.qst_vocab = text_helper.VocabDict(input_dir +
                                            '/vocab_questions.txt')
     self.ans_vocab = text_helper.VocabDict(input_dir +
                                            '/vocab_answers.txt')
     self.max_qst_length = max_qst_length
     self.max_num_ans = max_num_ans
     self.load_ans = ('valid_answers'
                      in self.vqa[0]) and (self.vqa[0]['valid_answers']
                                           is not None)
     self.transform = transform
Exemplo n.º 3
0
def main(args):
    
    image_dir = args.input_dir+'/Resized_Images/%s/'
    annotation_file = args.input_dir+'/Annotations/v2_mscoco_%s_annotations.json'
    question_file = args.input_dir+'/Questions/v2_OpenEnded_mscoco_%s_questions.json'

    vocab_answer_file = args.output_dir+'/vocab_answers.txt'
    answer_dict = text_processing.VocabDict(vocab_answer_file)
    valid_answer_set = set(answer_dict.word_list)    
    
    train = vqa_processing(image_dir, annotation_file, question_file, valid_answer_set, 'train2014')
    valid = vqa_processing(image_dir, annotation_file, question_file, valid_answer_set, 'val2014')
    test = vqa_processing(image_dir, annotation_file, question_file, valid_answer_set, 'test2015')
    test_dev = vqa_processing(image_dir, annotation_file, question_file, valid_answer_set, 'test-dev2015')
    
    np.save(args.output_dir+'/train.npy', np.array(train))
    np.save(args.output_dir+'/valid.npy', np.array(valid))
    np.save(args.output_dir+'/train_valid.npy', np.array(train+valid))
    np.save(args.output_dir+'/test.npy', np.array(test))
    np.save(args.output_dir+'/test-dev.npy', np.array(test_dev))