def test_new(tmpdir): new_project('MyProject', tmpdir) code_dir = osp.join(tmpdir, 'myproject.bootstrap.pytorch') # path needed to change import # https://stackoverflow.com/questions/23619595/pythons-os-chdir-function-isnt-working sys.path.insert(0, code_dir) reset_options_instance() sys.argv += [ '--path_opts', osp.join(code_dir, 'myproject/options/myproject.yaml') ] sys.argv += ['--exp.dir', osp.join(code_dir, 'logs/myproject/1_exp')] sys.argv += ['--misc.cuda', 'False'] sys.argv += ['--engine.nb_epochs', '10'] run() fnames = [ 'ckpt_best_accuracy_engine.pth.tar', 'ckpt_best_loss_optimizer.pth.tar', 'logs.txt', 'ckpt_best_accuracy_model.pth.tar', 'ckpt_last_engine.pth.tar', 'options.yaml', 'ckpt_best_accuracy_optimizer.pth.tar', 'ckpt_last_model.pth.tar', 'view.html', 'ckpt_best_loss_engine.pth.tar', 'ckpt_last_optimizer.pth.tar', 'ckpt_best_loss_model.pth.tar', 'logs.json' ] for fname in fnames: file_path = osp.join(code_dir, f'logs/myproject/1_exp/{fname}') assert osp.isfile(file_path)
def test_run_vqa2_options(option_name): reset_options_instance() sys.argv += [ '-o', f'block/options/vqa2/{option_name}.yaml', '--exp.dir', f'/tmp/logs/tests/vqa2/{option_name}', '--engine.nb_epochs', '1', '--engine.debug', 'True', '--misc.cuda', 'False', ] try: run() except: print('Unexpected error:', sys.exc_info()[0]) assert False assert True
def get_engine( path_experiment, weights="best_eval_epoch.accuracy_top1", load_original_annotations=True, options={}, ): reset_options_instance() path_yaml = os.path.join(path_experiment, "options.yaml") opt = Options(path_yaml) opt["exp.resume"] = weights # or "last" opt["exp.dir"] = path_experiment opt["misc.logs_name"] = "notebook" for arg in options: opt[arg] = options[arg] engine = run(train_engine=False, eval_engine=False) engine.dataset["eval"].load_original_annotation = load_original_annotations engine.dataset[ "train"].load_original_annotation = load_original_annotations return engine