def main(): # logging configuration logging.basicConfig(level=logging.INFO, format="[%(asctime)s]: %(levelname)s: %(message)s") # command line paser opt = parse.parse_arg() # GPU opt.cuda = opt.gpuid >= 0 if opt.gpuid >= 0: torch.cuda.set_device(opt.gpuid) else: logging.info("WARNING: RUN WITHOUT GPU") # prepare dataset opt.dataset = 'mnist' db = dataset.prepare_db(opt) #add wavelets: opt.wavelets = True opt.cutoff = 20 # initalize neural decision forest NDF = model.prepare_model(opt) # prepare optimizer optim, sche = optimizer.prepare_optim(NDF, opt) # train the neural decision forest5 best_acc = trainer.train(NDF, optim, sche, db, opt) logging.info('The best evaluation accuracy is %f' % best_acc)
# For now only GPU version is supported torch.cuda.set_device(opt.gpuid) # please place the downloaded pre-trained models in the following directory if opt.dataset == 'mnist': model_path = "../pre-trained/mnist_depth_9_tree_1_acc_0.993.pth" elif opt.dataset == 'cifar10': model_path = "../pre-trained/cifar10_depth_9_tree_1_ResNet50_acc_0.9341.pth" else: raise NotImplementedError # load model model = torch.load(model_path).cuda() # prepare dataset db = prepare_db(opt) # use only the evaluation subset. use db['train'] for fetching the training subset dataset = db['eval'] # ================================================================================== # compute saliency maps for different inputs for one splitting node # pick a tree index and splitting node index # tree_idx = 0 # node_idx = 0 # 0 - 510 for the 511 splitting nodes in a tree of depth 9 # get saliency maps for a specified node for different input tensors # utils.get_node_saliency_map(dataset, model, tree_idx, node_idx, name=opt.dataset) # ================================================================================== # get the computational paths for the some random inputs sample, paths, class_pred = utils.get_paths(dataset, model,