oracle = Oracle( no_words = oracle_args['vocab_size'], no_words_feat = oracle_args['embeddings']['no_words_feat'], no_categories = oracle_args['embeddings']['no_categories'], no_category_feat = oracle_args['embeddings']['no_category_feat'], no_hidden_encoder = oracle_args['lstm']['no_hidden_encoder'], mlp_layer_sizes = oracle_args['mlp']['layer_sizes'], no_visual_feat = oracle_args['inputs']['no_visual_feat'], no_crop_feat = oracle_args['inputs']['no_crop_feat'], dropout = oracle_args['lstm']['dropout'], inputs_config = oracle_args['inputs'], scale_visual_to = oracle_args['inputs']['scale_visual_to'] ) oracle = load_model(oracle, oracle_args['bin_file'], use_dataparallel=use_dataparallel) oracle.eval() print(model) print(oracle) if args.resnet: cnn = ResNet() if use_cuda: cnn.cuda() cnn = DataParallel(cnn) cnn.eval() softmax = nn.Softmax(dim=-1) if args.resnet:
for split, dataset in zip(exp_config['splits'], [dataset_train, dataset_validation]): accuracy = [] dataloader = DataLoader( dataset=dataset, batch_size=optimizer_config['batch_size'], shuffle=True, num_workers=multiprocessing.cpu_count(), pin_memory=exp_config['use_cuda'] ) if split == 'train': model.train() else: model.eval() for i_batch, sample in enumerate(dataloader): # Get Batch questions, answers, crop_features, visual_features, spatials, obj_categories, lengths = \ sample['question'], sample['answer'], sample['crop_features'], sample['img_features'], sample['spatial'], sample['obj_cat'], sample['length'] # Forward pass pred_answer = model(Variable(questions), Variable(obj_categories), Variable(spatials), Variable(crop_features), Variable(visual_features), Variable(lengths) )