assert cfg.EXP_NAME == os.path.basename(args.cfg).replace('.yaml', '') if args.opts: merge_cfg_from_list(args.opts) # Start session os.environ["CUDA_VISIBLE_DEVICES"] = str(cfg.GPU_ID) sess = tf.Session(config=tf.ConfigProto( gpu_options=tf.GPUOptions(allow_growth=cfg.GPU_MEM_GROWTH))) # Data files imdb_file = cfg.IMDB_FILE % cfg.TRAIN.SPLIT_VQA data_reader = DataReader( imdb_file, shuffle=True, one_pass=False, batch_size=cfg.TRAIN.BATCH_SIZE, vocab_question_file=cfg.VOCAB_QUESTION_FILE, T_encoder=cfg.MODEL.T_ENCODER, vocab_answer_file=cfg.VOCAB_ANSWER_FILE, load_gt_layout=cfg.TRAIN.USE_GT_LAYOUT, vocab_layout_file=cfg.VOCAB_LAYOUT_FILE, T_decoder=cfg.MODEL.T_CTRL, load_soft_score=cfg.TRAIN.VQA_USE_SOFT_SCORE) num_vocab = data_reader.batch_loader.vocab_dict.num_vocab num_choices = data_reader.batch_loader.answer_dict.num_vocab module_names = data_reader.batch_loader.layout_dict.word_list # Inputs and model input_seq_batch = tf.placeholder(tf.int32, [None, None]) seq_length_batch = tf.placeholder(tf.int32, [None]) image_feat_batch = tf.placeholder( tf.float32, [None, cfg.MODEL.H_FEAT, cfg.MODEL.W_FEAT, cfg.MODEL.FEAT_DIM]) model = Model( input_seq_batch, seq_length_batch, image_feat_batch, num_vocab=num_vocab, num_choices=num_choices, module_names=module_names, is_training=True)
save_file = './exp_vqa/results/%s/%s.%s.txt' % (exp_name, snapshot_name, tst_image_set) os.makedirs(os.path.dirname(save_file), exist_ok=True) eval_output_name = 'vqa_OpenEnded_mscoco_%s_%s_%s_results.json' % ( tst_image_set, exp_name, snapshot_name) eval_output_file = './exp_vqa/eval_outputs/%s/%s' % (exp_name, eval_output_name) os.makedirs(os.path.dirname(eval_output_file), exist_ok=True) assembler = Assembler(vocab_layout_file) data_reader_tst = DataReader(imdb_file_tst, shuffle=False, one_pass=True, batch_size=N, T_encoder=T_encoder, T_decoder=T_decoder, assembler=assembler, vocab_question_file=vocab_question_file, vocab_answer_file=vocab_answer_file) num_vocab_txt = data_reader_tst.batch_loader.vocab_dict.num_vocab num_vocab_nmn = len(assembler.module_names) num_choices = data_reader_tst.batch_loader.answer_dict.num_vocab # Network inputs input_seq_batch = tf.placeholder(tf.int32, [None, None]) seq_length_batch = tf.placeholder(tf.int32, [None]) image_feat_batch = tf.placeholder(tf.float32, [None, H_feat, W_feat, D_feat]) expr_validity_batch = tf.placeholder(tf.bool, [None])
assert cfg.EXP_NAME == os.path.basename(args.cfg).replace('.yaml', '') if args.opts: merge_cfg_from_list(args.opts) # Start session os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" ### edit_vedika os.environ["CUDA_VISIBLE_DEVICES"] = str(cfg.GPU_ID) sess = tf.Session(config=tf.ConfigProto( gpu_options=tf.GPUOptions(allow_growth=cfg.GPU_MEM_GROWTH))) # Data files imdb_file = cfg.IMDB_FILE % cfg.TEST.SPLIT_VQA #print(imdb_file) data_reader = DataReader( imdb_file, shuffle=False, one_pass=True, batch_size=cfg.TRAIN.BATCH_SIZE, ## cfg.TRAIN.BATCH_SIZE =128 (vqa_v2_scratch.yaml) vocab_question_file=cfg.VOCAB_QUESTION_FILE, T_encoder=cfg.MODEL.T_ENCODER, vocab_answer_file=cfg.VOCAB_ANSWER_FILE, load_gt_layout=True, vocab_layout_file=cfg.VOCAB_LAYOUT_FILE, T_decoder=cfg.MODEL.T_CTRL) num_vocab = data_reader.batch_loader.vocab_dict.num_vocab num_choices = data_reader.batch_loader.answer_dict.num_vocab module_names = data_reader.batch_loader.layout_dict.word_list # Eval files if cfg.TEST.GEN_EVAL_FILE: eval_file_pkl = cfg.TEST.EVAL_FILE_pkl % ( cfg.EXP_NAME, cfg.TEST.SPLIT_VQA, cfg.EXP_NAME, cfg.TEST.ITER) # print('evaluation outputs will be saved to %s' % eval_file_pkl) os.makedirs(os.path.dirname(eval_file_pkl), exist_ok=True) answer_word_list = data_reader.batch_loader.answer_dict.word_list ##aanswer_word_list is here assert(answer_word_list[0] == '<unk>') ### here asserting unk to position 0