# parameters.extend(qBot.parameters()) # aqmBot = nn.DataParallel(aqmBot) # Setup pytorch dataloader dataset.split = 'train' dataloader = DataLoader(dataset, batch_size=params['batchSize'], shuffle=False, num_workers=params['numWorkers'], drop_last=True, collate_fn=dataset.collate_fn, pin_memory=False) # Initializing visdom environment for plotting data viz = VisdomVisualize(enable=bool(params['enableVisdom']), env_name=params['visdomEnv'], server=params['visdomServer'], port=params['visdomServerPort']) pprint.pprint(params) viz.addText(pprint.pformat(params, indent=4)) # Setup optimizer if params['continue']: # Continuing from a loaded checkpoint restores the following startIterID = params['ckpt_iterid'] + 1 # Iteration ID lRate = params['ckpt_lRate'] # Learning rate print("Continuing training from iterId[%d]" % startIterID) else: # Beginning training normally, without any checkpoint lRate = params['learningRate'] startIterID = 0
# Load naming of data splits split_names = json.load(open(params['splitNames'], 'r')) # Load category specification if params['qaCategory'] and params['categoryMap']: category_mapping = json.load(open(params['categoryMap'], 'r')) val_split_name = split_names['val'] test_split_name = split_names['test'] category_mapping_splits = { 'val': category_mapping[val_split_name][params['qaCategory']], 'test': category_mapping[test_split_name][params['qaCategory']] } # Plotting on vizdom viz = VisdomVisualize(enable=bool(params['enableVisdom']), env_name=params['visdomEnv'], server=params['visdomServer'], port=params['visdomServerPort']) pprint.pprint(params) viz.addText(pprint.pformat(params, indent=4)) logging.info("Running evaluation!") numRounds = params['numRounds'] if 'ckpt_iterid' in params: iterId = params['ckpt_iterid'] + 1 else: iterId = -1 for split in splits: if split == 'train': splitName = 'full train - {}'.format(params['evalTitle']) if split == 'val': splitName = 'full Val - {}'.format(params['evalTitle'])
if params["qstartFrom"]: qBot, loadedParams, _ = utils.loadModel(params, "qbot", overwrite=True) assert qBot.encoder.vocabSize == params[ "vocabSize"], "Vocab size mismatch!" for key in loadedParams: params[key] = loadedParams[key] qBot.eval() # Retaining certain dataloder parameters for key in excludeParams: params[key] = dlparams[key] # Plotting on vizdom viz = VisdomVisualize( enable=bool(params["enableVisdom"]), env_name=params["visdomEnv"], server=params["visdomServer"], port=params["visdomServerPort"], ) pprint.pprint(params) viz.addText(pprint.pformat(params, indent=4)) print("Running evaluation!") numRounds = params["numRounds"] if "ckpt_iterid" in params: iterId = params["ckpt_iterid"] + 1 else: iterId = -1 if "test" in splits: split = "test" splitName = "test - {}".format(params["evalTitle"])
print("tot eval batches", batch_idx) all_metrics = {} all_metrics.update(sparse_metrics.retrieve(reset=True)) all_metrics.update(ndcg.retrieve(reset=True)) return all_metrics if __name__ == '__main__': params = options.read_command_line() os.makedirs('checkpoints', exist_ok=True) if not os.path.exists(params['save_path']): os.mkdir(params['save_path']) viz = VisdomVisualize(enable=bool(params['enable_visdom']), env_name=params['visdom_env'], server=params['visdom_server'], port=params['visdom_server_port']) pprint.pprint(params) viz.addText(pprint.pformat(params, indent=4)) dataset = VisdialDataset(params) dataset.split = 'train' dataloader = DataLoader( dataset, batch_size= params['batch_size']//params['sequences_per_image'] if (params['batch_size']//params['sequences_per_image']) \ else 1 if not params['overfit'] else 5, shuffle=True, num_workers=params['num_workers'], drop_last=True, pin_memory=False)
params[key] = loadedParams[key] parameters.extend(aBot.parameters()) # Setup pytorch dataloader dataset.split = 'train' dataloader = DataLoader(dataset, batch_size=params['batchSize'], shuffle=False, num_workers=params['numWorkers'], drop_last=True, collate_fn=dataset.collate_fn, pin_memory=False) # Initializing visdom environment for plotting data viz = VisdomVisualize(enable=bool(params['enableVisdom']), env_name=params['visdomEnv'], server=params['visdomServer'], port=params['visdomServerPort']) pprint.pprint(params) viz.addText(pprint.pformat(params, indent=4)) # Setup optimizer if params['continue']: # Continuing from a loaded checkpoint restores the following startIterID = params['ckpt_iterid'] + 1 # Iteration ID lRate = params['ckpt_lRate'] # Learning rate print("Continuing training from iterId[%d]" % startIterID) else: # Beginning training normally, without any checkpoint lRate = params['learningRate'] startIterID = 0
# dataloader (pytorch) # --------------------------------------------------------------------------- dataset.split = 'train' dataloader = DataLoader(dataset, batch_size=params['batchSize'], shuffle=False, num_workers=params['numWorkers'], drop_last=True, collate_fn=dataset.collate_fn, pin_memory=False) # --------------------------------------------------------------------------- # plotting (visdom) # --------------------------------------------------------------------------- viz = VisdomVisualize(enable=bool(params['enableVisdom']), env_name=params['visdomEnv'], server=params['visdomServer'], port=params['visdomServerPort']) pprint.pprint(params) viz.addText(pprint.pformat(params, indent=4)) # --------------------------------------------------------------------------- # optimizer, loss, numIterPerEpoch, rlRound # --------------------------------------------------------------------------- if params['continue']: # Continuing from a loaded checkpoint restores the following startIterID = params['ckpt_iterid'] + 1 # Iteration ID lRate = params['ckpt_lRate'] # Learning rate print("Continuing training from iterId[%d]" % startIterID) else: # Beginning training normally, without any checkpoint lRate = params['learningRate']