def get_conf(dataloader, delta, model, T=1, laplace=True): if laplace: py = llla.predict(dataloader, model, M_W, M_b, U, V, B, delta=delta) else: py = predict(dataloader, model, delta=delta, T=T) conf = get_confidence(py.cpu().numpy()) return conf
var0 = torch.tensor(0.2656).float().cuda() print(var0) M_W, M_b, U, V, B = llla.estimate_variance(var0, hessians) np.save(f'./pretrained_models/CIFAR10_{args.type}_llla.npy', [M_W, M_b, U, V, B]) else: time_inf = 0 M_W, M_b, U, V, B = list( np.load(f'./pretrained_models/CIFAR10_{args.type}_llla.npy', allow_pickle=True)) # In-distribution py_in, time_pred = timing( lambda: llla.predict(test_loader, model, M_W, M_b, U, V, B).cpu().numpy()) acc_in = np.mean(np.argmax(py_in, 1) == targets) conf_in = get_confidence(py_in) mmc = conf_in.mean() ece, mce = get_calib(py_in, targets) save_res_ood(tab_ood['CIFAR10 - CIFAR10'], mmc) save_res_cal(tab_cal['LLLA'], ece, mce) print( f'[In, LLLA] Time: {time_inf:.1f}/{time_pred:.1f}s; Accuracy: {acc_in:.3f}; ECE: {ece:.3f}; MCE: {mce:.3f}; MMC: {mmc:.3f}' ) # Out-distribution py_out = llla.predict(test_loader_SVHN, model, M_W, M_b, U, V, B).cpu().numpy() conf_svhn = get_confidence(py_out) mmc = conf_svhn.mean() auroc = get_auroc(py_in, py_out)