def load_dataset(dataset, hyperparams): datasets = { "canevet-icml2016-jittered": partial(CanevetICML2016, smooth=10), "canevet-icml2016": CanevetICML2016, "canevet-icml2016-smooth": partial(CanevetICML2016, smooth=15000), "cifar-sanity-check": CIFARSanityCheck, "mnist": MNIST, "cifar10": CIFAR10, "cifar100": CIFAR100, "cifar10-augmented": compose( partial(OntheflyAugmentedImages, ___, dict( featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False )), CIFAR10 ), "cifar10-whitened-augmented": compose( partial(OntheflyAugmentedImages, ___, dict( featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=True, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False )), CIFAR10 ), "cifar100-augmented": compose( partial(OntheflyAugmentedImages, ___, dict( featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False )), CIFAR100 ), "ptb": partial(PennTreeBank, 20) } return datasets[dataset]()
def get_samplers_dictionary(model, hyperparams={}, reweighting=None): # Add some base samplers samplers = { "uniform": partial(UniformSampler, ___, reweighting), "model": partial(ModelSampler, ___, reweighting, model, large_batch=hyperparams.get("presample", 1024)), "lstm": partial(LSTMSampler, ___, reweighting, log=hyperparams.get("lstm_log", 0) != 0, warmup=hyperparams.get("lstm_warmup", 100), presample=hyperparams.get("presample", 2048)), "pcg": partial(PerClassGaussian, ___, reweighting, alpha=hyperparams.get("alpha", 0.9), presample=hyperparams.get("presample", 2048)), "obs": partial(OnlineBatchSelectionSampler, ___, reweighting, model, steps_per_epoch=hyperparams.get("steps_per_epoch", 300), recompute=hyperparams.get("obs_recompute", 2), s_e=(hyperparams.get("obs_se0", 1), hyperparams.get("obs_seend", 1)), n_epochs=hyperparams.get("obs_epochs", 1)) } samplers["lstm-comparison"] = lambda x: LSTMComparisonSampler( x, samplers["lstm"](x), samplers["model"](x), subset=hyperparams.get("lstm_comparison", 1024)) # Add some decorated samplers samplers_for_decoration = ["model", "lstm", "pcg"] for sampler in samplers_for_decoration: samplers["smooth-" + sampler] = compose( partial(AdditiveSmoothingSampler, c=hyperparams.get("smooth", 1.0)), samplers[sampler]) samplers["adaptive-smooth-" + sampler] = compose( partial(AdaptiveAdditiveSmoothingSampler, percentage=hyperparams.get("smooth", 0.5)), samplers[sampler]) samplers["power-smooth-" + sampler] = compose( partial(PowerSmoothingSampler, power=hyperparams.get("smooth", 0.5)), samplers[sampler]) return samplers
def test_datasets(self): datasets = [(CIFAR10, 50000, 10000, (32, 32, 3), 10), (CIFARSanityCheck, 40000, 2000, (32, 32, 3), 2), (MNIST, 60000, 10000, (28, 28, 1), 10), (partial(CanevetICML2016, N=256), int(256**2 - 256**2 * 0.33) + 1, int(256**2 * 0.33), (2, ), 2), (compose( partial(OntheflyAugmentedImages, augmentation_params=dict( featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False)), CIFAR10), 500000, 10000, (32, 32, 3), 10), (partial(PennTreeBank, 20), 887521, 70390, (20, ), 10000)] for args in datasets: self._test_dset(*args)
def load_dataset(dataset): datasets = { "mnist": MNIST, "cifar10": CIFAR10, "cifar100": CIFAR100, "cifar10-augmented": compose( partial( OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False)), CIFAR10), "cifar100-augmented": compose( partial( OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False)), CIFAR100), "ptb": partial(PennTreeBank, 20) } return datasets[dataset]()
def get_samplers_dictionary(model, hyperparams={}, reweighting=None): # Add some base samplers samplers = { "uniform": partial(UniformSampler, ___, reweighting), "model": partial(ModelSampler, ___, reweighting, model, large_batch=hyperparams.get("presample", 1024)), "lstm": partial(LSTMSampler, ___, reweighting, log=hyperparams.get("lstm_log", 0) != 0, presample=hyperparams.get("presample", 2048)), "pcg": partial(PerClassGaussian, ___, reweighting, alpha=hyperparams.get("alpha", 0.9), presample=hyperparams.get("presample", 2048)), "obs": partial(OnlineBatchSelectionSampler, ___, reweighting, model, steps_per_epoch=hyperparams.get("steps_per_epoch", 300), recompute=hyperparams.get("obs_recompute", 2), s_e=(hyperparams.get("obs_se0", 1), hyperparams.get("obs_seend", 1)), n_epochs=hyperparams.get("obs_epochs", 1)), "history": partial(HistorySampler, ___, reweighting, model, recompute=hyperparams.get("history_recompute", 600)), "cache": partial(CacheSampler, ___, reweighting, staleness=hyperparams.get("staleness", 3), cache_prob=hyperparams.get("cache_prob", 0.5), smooth=hyperparams.get("smooth", 0.2)) } samplers["lstm-comparison"] = lambda x: LSTMComparisonSampler( x, samplers["lstm"](x), samplers["model"](x), subset=hyperparams.get("lstm_comparison", 1024)) # Add some decorated samplers samplers_for_decoration = ["model", "lstm", "pcg", "history"] for sampler in samplers_for_decoration: samplers["smooth-" + sampler] = compose( partial(AdditiveSmoothingSampler, c=hyperparams.get("smooth", 1.0)), samplers[sampler]) samplers["adaptive-smooth-" + sampler] = compose( partial(AdaptiveAdditiveSmoothingSampler, percentage=hyperparams.get("smooth", 0.5)), samplers[sampler]) samplers["power-smooth-" + sampler] = compose( partial(PowerSmoothingSampler, power=hyperparams.get("smooth", 0.5)), samplers[sampler]) for sampler in samplers.keys(): if "model" in sampler or "lstm" in sampler: samplers["warmup-" + sampler] = compose( partial(ConditionalStartSampler, ___, WarmupCondition(hyperparams.get("warmup", 100))), samplers[sampler]) samplers["exp-" + sampler] = compose( partial(ConditionalStartSampler, ___, ExpCondition(hyperparams.get("exp_th", 2.0))), samplers[sampler]) samplers["tv-" + sampler] = compose( partial(ConditionalStartSampler, ___, TotalVariationCondition(hyperparams.get("tv_th", 0.5))), samplers[sampler]) samplers["vr-" + sampler] = compose( partial( ConditionalStartSampler, ___, VarianceReductionCondition(hyperparams.get("vr_th", 0.5))), samplers[sampler]) return samplers
def load_dataset(dataset, hyperparams): datasets = { "canevet-icml2016-jittered": partial(CanevetICML2016, smooth=10), "canevet-icml2016": CanevetICML2016, "canevet-icml2016-smooth": partial(CanevetICML2016, smooth=15000), "cifar-sanity-check": CIFARSanityCheck, "mnist": MNIST, "cifar10": CIFAR10, "cifar100": CIFAR100, "cifar10-augmented": compose( partial( OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False)), CIFAR10), "cifar10-whitened-augmented": compose( partial(OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False), N=15 * 10**5), ZCAWhitening, CIFAR10), "cifar100-augmented": compose( partial( OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False)), CIFAR100), "cifar100-whitened-augmented": compose( partial(OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False), N=15 * 10**5), ZCAWhitening, CIFAR100), "ptb": partial(PennTreeBank, 20), "imagenet-32x32": partial(ImageNetDownsampled, hyperparams.get("imagenet", os.getenv("IMAGENET")), size=32), "imagenet-64x64": partial(ImageNetDownsampled, hyperparams.get("imagenet", os.getenv("IMAGENET")), size=64), "timit": partial(TIMIT, 20, hyperparams.get("timit", os.getenv("TIMIT"))), "mit-67": partial(MIT67, hyperparams.get("mit67", os.getenv("MIT67"))), "casia": partial(CASIAWebFace, hyperparams.get("casia", os.getenv("CASIA")), alpha=hyperparams.get("triplet_alpha", 0.2), embedding=hyperparams.get("triplet_embedding", 128)), "casia-cls": partial( CASIAWebFace2, hyperparams.get("casia", os.getenv("CASIA")), ), "pixel-mnist": PixelByPixelMNIST } return datasets[dataset]()
def load_dataset(dataset): datasets = { "mnist": MNIST, "cifar10": CIFAR10, "cifar100": CIFAR100, "cifar10-augmented": compose( partial( OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False)), CIFAR10), "cifar10-whitened-augmented": compose( partial(OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False), N=15 * 10**5), ZCAWhitening, CIFAR10), "cifar100-augmented": compose( partial( OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False)), CIFAR100), "cifar100-whitened-augmented": compose( partial(OntheflyAugmentedImages, ___, dict(featurewise_center=False, samplewise_center=False, featurewise_std_normalization=False, samplewise_std_normalization=False, zca_whitening=False, rotation_range=0, width_shift_range=0.1, height_shift_range=0.1, horizontal_flip=True, vertical_flip=False), N=15 * 10**5), ZCAWhitening, CIFAR100), "imagenet-32x32": partial(ImageNetDownsampled, os.getenv("IMAGENET"), size=32), "ptb": partial(PennTreeBank, 20), } return datasets[dataset]()