else: # create new folder. t = datetime.datetime.now() cur_time = '%s-%s-%s' %(t.day, t.month, t.hour) save_path = os.path.join(opt.outf, opt.decoder + '.' + cur_time) try: os.makedirs(save_path) except OSError: pass #################################################################################### # Data Loader #################################################################################### dataset = dl.train(input_img_h5=opt.input_img_h5, input_ques_h5=opt.input_ques_h5, input_json=opt.input_json, negative_sample = opt.negative_sample, num_val = opt.num_val, data_split = 'train') dataset_val = dl.validate(input_img_h5=opt.input_img_h5, input_ques_h5=opt.input_ques_h5, input_json=opt.input_json, negative_sample = opt.negative_sample, num_val = opt.num_val, data_split = 'test') dataloader = torch.utils.data.DataLoader(dataset, batch_size=opt.batchSize, shuffle=True, num_workers=int(opt.workers)) dataloader_val = torch.utils.data.DataLoader(dataset_val, batch_size=1, shuffle=False, num_workers=int(opt.workers)) #################################################################################### # Build the Model ####################################################################################
if __name__ == '__main__': args = parse_args() os.environ["CUDA_VISIBLE_DEVICES"] = str(args.gpuid) args.seed = random.randint(1, 10000) torch.manual_seed(args.seed) torch.cuda.manual_seed(args.seed) torch.backends.cudnn.benchmark = True batch_size = args.batch_size train_dataset = dl.train(input_img_h5=args.input_img_h5, input_imgid=args.input_imgid, input_ques_h5=args.input_ques_h5, input_json=args.input_json, negative_sample=args.negative_sample, num_val=args.num_val, data_split='train') eval_dateset = dl.validate(input_img_h5=args.input_img_h5, input_imgid=args.input_imgid, input_ques_h5=args.input_ques_h5, input_json=args.input_json, negative_sample=args.negative_sample, num_val=args.num_val, data_split='val') train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=args.batch_size, shuffle=True,