예제 #1
0
np.random.seed(args.randseed)
torch.manual_seed(args.randseed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

train_loader = dl.CIFAR10(train=True, augm_flag=False)
val_loader, test_loader = dl.CIFAR10(train=False, val_size=2000)
targets = torch.cat([y for x, y in test_loader], dim=0).numpy()
print(len(train_loader.dataset), len(val_loader.dataset),
      len(test_loader.dataset))

test_loader_SVHN = dl.SVHN(train=False)
test_loader_LSUN = dl.LSUN_CR(train=False)

delta = 10 if args.type == 'OE' else 1
ood_loader = dl.UniformNoise('CIFAR10', delta=delta, size=2000)


def load_model():
    if args.type == 'OE':
        model = resnet_oe.ResNet18(dataset='CIFAR10').gpu()
    else:
        model = resnet.ResNet18().cuda()

    model.load_state_dict(
        torch.load(f'./pretrained_models/CIFAR10_{args.type}.pt'))
    model.eval()

    return model

예제 #2
0
                                            train=False,
                                            augm_flag=False,
                                            val_size=1000)
targets = torch.cat([y for x, y in test_loader], dim=0).numpy()
targets_val = torch.cat([y for x, y in val_loader], dim=0).numpy()
print(len(train_loader.dataset), len(val_loader.dataset),
      len(test_loader.dataset))

test_loader_SVHN, _ = dl.binary_SVHN(3,
                                     9,
                                     train=False,
                                     augm_flag=False,
                                     val_size=1000)
test_loader_LSUN = dl.LSUN_CR(train=False, augm_flag=False)

ood_loader = dl.UniformNoise('CIFAR10', size=1000)
noise_loader = dl.UniformNoise('CIFAR10', size=2000)


def load_model():
    model = resnet.ResNet18(num_classes=2).cuda()
    model.load_state_dict(torch.load(f'./pretrained_models/binary_CIFAR10.pt'))
    model.eval()
    return model


tab_ood = {
    'CIFAR10 - CIFAR10': [],
    'CIFAR10 - SVHN': [],
    'CIFAR10 - LSUN': [],
    'CIFAR10 - FarAway': []
예제 #3
0
train_loader = dl.binary_SVHN(3, 9, train=True, augm_flag=False)
val_loader, test_loader = dl.binary_SVHN(3,
                                         9,
                                         train=False,
                                         augm_flag=False,
                                         val_size=1000)
targets = torch.cat([y for x, y in test_loader], dim=0).numpy()
targets_val = torch.cat([y for x, y in val_loader], dim=0).numpy()
print(len(train_loader.dataset), len(val_loader.dataset),
      len(test_loader.dataset))

test_loader_CIFAR10 = dl.CIFAR10(train=False, augm_flag=False)
test_loader_LSUN = dl.LSUN_CR(train=False, augm_flag=False)

ood_loader = dl.UniformNoise('SVHN', size=1000)
noise_loader = dl.UniformNoise('SVHN', size=2000)


def load_model():
    model = resnet.ResNet18(num_classes=2).cuda()
    model.load_state_dict(torch.load(f'./pretrained_models/binary_SVHN.pt'))
    model.eval()
    return model


tab_ood = {
    'SVHN - SVHN': [],
    'SVHN - CIFAR10': [],
    'SVHN - LSUN': [],
    'SVHN - FarAway': []
예제 #4
0
np.random.seed(args.randseed)
torch.manual_seed(args.randseed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

train_loader = dl.SVHN(train=True, augm_flag=False)
val_loader, test_loader = dl.SVHN(train=False, val_size=2000)
targets = torch.cat([y for x, y in test_loader], dim=0).numpy()
print(len(train_loader.dataset), len(val_loader.dataset),
      len(test_loader.dataset))

test_loader_CIFAR10 = dl.CIFAR10(train=False)
test_loader_LSUN = dl.LSUN_CR(train=False)

delta = 10 if args.type == 'OE' else 1
ood_loader = dl.UniformNoise('SVHN', delta=delta, size=2000)


def load_model():
    if args.type == 'OE':
        model = resnet_oe.ResNet18(dataset='SVHN').gpu()
    else:
        model = resnet.ResNet18().cuda()

    model.load_state_dict(
        torch.load(f'./pretrained_models/SVHN_{args.type}.pt'))
    model.eval()

    return model

예제 #5
0
np.random.seed(args.randseed)
torch.manual_seed(args.randseed)
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

train_loader = dl.MNIST(train=True, augm_flag=False)
val_loader, test_loader = dl.MNIST(train=False, val_size=2000)
targets = torch.cat([y for x, y in test_loader], dim=0).numpy()
print(len(train_loader.dataset), len(val_loader.dataset),
      len(test_loader.dataset))

test_loader_EMNIST = dl.EMNIST(train=False)
test_loader_FMNIST = dl.FMNIST(train=False)

delta = 10 if args.type == 'OE' else 1
ood_loader = dl.UniformNoise('MNIST', delta=delta, size=2000)


def load_model():
    model = MNIST_ConvNet() if args.type == 'OE' else LeNetMadry()
    model = model.cuda()
    model.load_state_dict(
        torch.load(f'./pretrained_models/MNIST_{args.type}.pt'))
    model.eval()

    return model


tab_ood = {
    'MNIST - MNIST': [],
    'MNIST - EMNIST': [],
예제 #6
0
torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False

train_loader = dl.binary_MNIST(3, 8, train=True, augm_flag=False)
val_loader, test_loader = dl.binary_MNIST(3, 8, train=False, val_size=1000)
targets = torch.cat([y for x, y in test_loader], dim=0).numpy()
targets_val = torch.cat([y for x, y in val_loader], dim=0).numpy()
print(len(train_loader.dataset), len(val_loader.dataset),
      len(test_loader.dataset))

test_loader_EMNIST, _ = dl.EMNIST(train=False,
                                  val_size=len(test_loader.dataset))
test_loader_FMNIST, _ = dl.FMNIST(train=False,
                                  val_size=len(test_loader.dataset))

ood_loader = dl.UniformNoise('MNIST', train=False, size=1000)
noise_loader = dl.UniformNoise('MNIST', size=2000)


def load_model():
    model = LeNetMadry(binary=True)
    model = model.cuda()
    model.load_state_dict(torch.load(f'./pretrained_models/binary_MNIST.pt'))
    model.eval()

    return model


tab_ood = {
    'MNIST - MNIST': [],
    'MNIST - EMNIST': [],