コード例 #1
0
print("Initializing model...")
top = 70
epss = [
    int(i**2 + 0.5) / 100 for i in np.arange(0,
                                             int(top**0.5 + 1) + 0.5, 0.5)
]
print(epss)
accuracieses = []
for parseval in [False, True]:
    aggregation = 'convex' if parseval else 'sum'
    resnet_ctor = ParsevalResNet if parseval else ResNet
    from standard_resnets import get_wrn
    model = standard_resnets.get_wrn(zaggydepth,
                                     k,
                                     ds_test.image_shape,
                                     ds_test.class_count,
                                     aggregation=aggregation,
                                     resnet_ctor=resnet_ctor)

    saved_path = dirs.SAVED_MODELS
    if parseval:
        saved_path += '/wrn-28-10-p-t--2018-01-24-21-18/ResNet'  # Parseval
    else:
        saved_path += '/wrn-28-10-t--2018-01-23-19-13/ResNet'  # vanilla
    model.load_state(saved_path)

    cost, ev = model.test(ds_test)
    accuracies = [ev['accuracy']]
    for eps in epss[1:]:
        print("Creating adversarial examples...")
        clip_max = (255 - np.max(Cifar10Loader.mean)) / np.max(
コード例 #2
0
import sys
import datetime

from models import ResidualBlockProperties, ResNet
from data_utils import Cifar10Loader
import standard_resnets
from training import train
import dirs

dimargs = sys.argv[1:]
if len(dimargs) not in [0, 2]:
    print("usage: train-wrn.py [<Zagoruyko-depth> <widening-factor>]")
zaggydepth, k = (16, 4) if len(dimargs) == 0 else map(int, dimargs)

print("Loading and preparing data...")
ds_train, ds_val = Cifar10Loader.load_train_val()

print("Initializing model...")
model = standard_resnets.get_wrn(
    zaggydepth, k, ds_train.image_shape, ds_train.class_count)

print("Starting training and validation loop...")
train(model, ds_train, ds_val, epoch_count=200)

print("Saving model...")
model.save_state(dirs.SAVED_MODELS + '/wrn-%d-%d--' % (zaggydepth, k) +
                 datetime.datetime.now().strftime("%Y-%m-%d-%H-%M"))
コード例 #3
0
import datetime

from models import ResidualBlockProperties, ResNetN
from data_utils import Cifar10Loader, Dataset
import standard_resnets
from training import train
import dirs

dimargs = sys.argv[1:]
if len(dimargs) not in [0, 2]:
    print("usage: train-wrn.py [<Zagoruyko-depth> <widening-factor>]")
zaggydepth, k = (16, 4) if len(dimargs) == 0 else map(int, dimargs)

print("Loading and preparing data...")
ds_train, ds_val = Cifar10Loader.load_train_val()

print("Initializing model...")
model = standard_resnets.get_wrn(zaggydepth,
                                 k,
                                 ds_train.image_shape,
                                 ds_train.class_count,
                                 aggregation='convex',
                                 resnet_ctor=ResNetN)

print("Starting training and validation loop...")
train(model, ds_train, ds_val, epoch_count=200)

print("Saving model...")
model.save_state(dirs.SAVED_MODELS + '/wrn-%d-%d-nk--' % (zaggydepth, k) +
                 datetime.datetime.now().strftime("%Y-%m-%d-%H-%M"))