options = vars(parser.parse_args()) sys.path.append(os.path.dirname(os.path.dirname(__file__))) from dataloader import CustomDataloader, FlexibleCustomDataloader from training import train_classifier from networks import build_networks, save_networks, get_optimizers from options import load_options, get_current_epoch from comparison import evaluate_with_comparison from evaluation import save_evaluation options = load_options(options) dataloader = FlexibleCustomDataloader(fold='train', **options) networks = build_networks(dataloader.num_classes, **options) optimizers = get_optimizers(networks, finetune=True, **options) eval_dataloader = CustomDataloader(last_batch=True, shuffle=False, fold='test', **options) start_epoch = get_current_epoch(options['result_dir']) + 1 for epoch in range(start_epoch, start_epoch + options['epochs']): train_classifier(networks, optimizers, dataloader, epoch=epoch, **options) #print(networks['classifier_kplusone']) #weights = networks['classifier_kplusone'].fc1.weight eval_results = evaluate_with_comparison(networks, eval_dataloader, **options) pprint(eval_results) save_evaluation(eval_results, options['result_dir'], epoch) save_networks(networks, epoch, options['result_dir'])
help='Save Z in .npy format for later visualization') parser.add_argument('--comparison_dataset', type=str, help='Dataset for off-manifold comparison') options = vars(parser.parse_args()) # Import the rest of the project sys.path.append(os.path.dirname(os.path.dirname(__file__))) from dataloader import CustomDataloader from networks import build_networks from options import load_options, get_current_epoch from evaluation import evaluate_classifier, evaluate_openset, save_evaluation options = load_options(options) if not options.get('epoch'): options['epoch'] = get_current_epoch(options['result_dir']) options['random_horizontal_flip'] = False dataloader = CustomDataloader(last_batch=True, shuffle=False, **options) networks = build_networks(dataloader.num_classes, **options) comparison_dataloader = None if options['comparison_dataset']: comparison_options = options.copy() comparison_options['dataset'] = options['comparison_dataset'] comparison_dataloader = CustomDataloader(last_batch=True, shuffle=False, **comparison_options) comparison_name = options['comparison_dataset'].split('/')[-1].split( '.')[0]