Beispiel #1
0
def main(args):
    config = Config(args)
    logger = logging.getLogger(__name__)

    def setup_logger(level=logging.DEBUG, filename=None):
        logger.setLevel(level)
        stream_handler = logging.StreamHandler()
        stream_handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('[%(asctime)s] %(message)s')
        stream_handler.setFormatter(formatter)
        logger.addHandler(stream_handler)

        if filename is not None:
            file_handler = logging.FileHandler(filename=filename, mode='a')
            file_handler.setLevel(logging.INFO)
            file_handler.setFormatter(formatter)
            logger.addHandler(file_handler)

        logger.debug("logger '%s' has been setup.", __name__)

    setup_logger(level=logging.DEBUG, filename=config.log_path)

    if config.dataset == 'fm':
        trainset = dataset.FashionMnist(train=True)
        testset = dataset.FashionMnist(train=False)
    elif config.dataset == 'c10':
        trainset = dataset.Cifar10(train=True)
        testset = dataset.Cifar10(train=False)
    elif config.dataset == 'svhn':
        trainset = dataset.SVHN(train=True)
        testset = dataset.SVHN(train=False)
    elif config.dataset == 'cinic':
        trainset = dataset.Cinic(train=True)
        testset = dataset.Cinic(train=False)
    else:
        raise ValueError("Dataset '{}' not found.".format(config.dataset))

    logger.info(
        "****************************************************************")
    logger.info("%s", config)
    logger.info("trainset size: %d", len(trainset))
    logger.info("testset size: %d", len(testset))

    start_time = time.time()

    if config.type == 'stream':
        stream(config=config, trainset=trainset, streamset=testset)

    logger.info(
        "-------------------------------- %.3fs --------------------------------",
        time.time() - start_time)
Beispiel #2
0
    config = json.loads(args.config.replace("'", '"'))

if args.dataset == 'fmnist':
    d = dataset.fMNIST()
elif args.dataset == 'binary_fmnist':
    d = dataset.fMNIST(binary=True)
elif args.dataset == 'binary_mnist':
    d = dataset.MNIST(binary=True)
elif args.dataset == 'mnist':
    d = dataset.MNIST()
elif args.dataset in ['omniglot', 'omni']:
    d = dataset.Omniglot()
elif args.dataset == 'dsprites':
    d = dataset.DSprites()
elif args.dataset == "cifar10" or args.dataset == 'cifar':
    d = dataset.Cifar10()

if args.per_label is not None:
    d.shrink_supervised(args.per_label)

m = model.NoiseModel(d,
                     config=config,
                     filename=args.filename,
                     verbose=args.verbose)
m.lagrangian_fit = args.fit_tf

if args.noise is not None:
    if args.noise == 'multiplicative':
        m.layers[0]['layer_kwargs']['multiplicative'] = True
    if args.noise == 'additive':
        m.layers[0]['layer_kwargs']['multiplicative'] = False