def check_files():
    import os
    from common import paths

    def check_file(filepath):
        if not os.path.exists(filepath):
            print('File %s not found.' % filepath)

    check_file(paths.database_file())
    check_file(paths.images_file())
    check_file(paths.theta_file())
    check_file(paths.codes_file())

    check_file(paths.test_images_file())
    check_file(paths.train_images_file())
    check_file(paths.test_theta_file())
    check_file(paths.train_theta_file())
    check_file(paths.test_codes_file())
    check_file(paths.train_codes_file())

    check_file(paths.emnist_test_images_file())
    check_file(paths.emnist_train_images_file())
    check_file(paths.emnist_test_labels_file())
    check_file(paths.emnist_train_labels_file())

    check_file(paths.fashion_test_images_file())
    check_file(paths.fashion_train_images_file())
    check_file(paths.fashion_test_labels_file())
    check_file(paths.fashion_train_labels_file())

    check_file(paths.celeba_test_images_file())
    check_file(paths.celeba_train_images_file())
    check_file(paths.celeba_test_labels_file())
    check_file(paths.celeba_train_labels_file())
    def get_parser(self):
        """
        Get parser.

        :return: parser
        :rtype: argparse.ArgumentParser
        """

        parser = argparse.ArgumentParser(
            description='Split generated dataset into training and test sets.')
        parser.add_argument('-codes_file',
                            default=paths.codes_file(),
                            help='HDF5 file containing codes.',
                            type=str)
        parser.add_argument('-theta_file',
                            default=paths.theta_file(),
                            help='HDF5 file containing transformations.',
                            type=str)
        parser.add_argument('-images_file',
                            default=paths.images_file(),
                            help='HDF5 file containing transformed images.',
                            type=str)
        parser.add_argument('-train_codes_file',
                            default=paths.train_codes_file(),
                            help='HDF5 file containing transformed images.',
                            type=str)
        parser.add_argument('-test_codes_file',
                            default=paths.test_codes_file(),
                            help='HDF5 file containing transformed images.',
                            type=str)
        parser.add_argument('-train_theta_file',
                            default=paths.train_theta_file(),
                            help='HDF5 file containing transformed images.',
                            type=str)
        parser.add_argument('-test_theta_file',
                            default=paths.test_theta_file(),
                            help='HDF5 file containing transformed images.',
                            type=str)
        parser.add_argument('-train_images_file',
                            default=paths.train_images_file(),
                            help='HDF5 file containing transformed images.',
                            type=str)
        parser.add_argument('-test_images_file',
                            default=paths.test_images_file(),
                            help='HDF5 file containing transformed images.',
                            type=str)
        parser.add_argument('-N_train',
                            default=960000,
                            help='Train/test split.',
                            type=int)
        return parser
    def get_parser(self):
        """
        Get parser.

        :return: parser
        :rtype: argparse.ArgumentParser
        """

        parser = argparse.ArgumentParser(
            description='Inspect transformed images.')
        parser.add_argument('-database_file',
                            default=paths.database_file(),
                            type=str)
        parser.add_argument('-codes_file',
                            default=paths.codes_file(),
                            type=str)
        parser.add_argument('-theta_file',
                            default=paths.theta_file(),
                            type=str)
        parser.add_argument('-images_file',
                            default=paths.images_file(),
                            type=str)
        parser.add_argument('-train_codes_file',
                            default=paths.train_codes_file(),
                            type=str)
        parser.add_argument('-test_codes_file',
                            default=paths.test_codes_file(),
                            type=str)
        parser.add_argument('-train_theta_file',
                            default=paths.train_theta_file(),
                            type=str)
        parser.add_argument('-test_theta_file',
                            default=paths.test_theta_file(),
                            type=str)
        parser.add_argument('-train_images_file',
                            default=paths.train_images_file(),
                            type=str)
        parser.add_argument('-test_images_file',
                            default=paths.test_images_file(),
                            type=str)

        return parser
Exemplo n.º 4
0
    def get_parser(self):
        """
        Get parser.

        :return: parser
        :rtype: argparse.ArgumentParser
        """

        parser = argparse.ArgumentParser(
            description='Test attacks on classifier.')
        parser.add_argument('-test_images_file',
                            default=paths.test_images_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-train_images_file',
                            default=paths.train_images_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-test_theta_file',
                            default=paths.test_theta_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-train_theta_file',
                            default=paths.train_theta_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-test_codes_file',
                            default=paths.test_codes_file(),
                            help='HDF5 file containing labels.',
                            type=str)
        parser.add_argument('-label_index',
                            default=2,
                            help='Column index in label file.',
                            type=int)
        parser.add_argument(
            '-accuracy_file',
            default=paths.results_file('classifier/accuracy'),
            help='Correctly classified test samples of classifier.',
            type=str)
        parser.add_argument(
            '-perturbations_file',
            default=paths.results_file('classifier/perturbations'),
            help='HDF5 file containing perturbations.',
            type=str)
        parser.add_argument('-success_file',
                            default=paths.results_file('classifier/success'),
                            help='HDF5 file indicating attack success.',
                            type=str)
        parser.add_argument('-results_file',
                            default='',
                            help='Path to pickled results file.',
                            type=str)
        parser.add_argument('-plot_directory',
                            default=paths.experiment_dir('classifier'),
                            help='Path to PNG plot file for success rate.',
                            type=str)
        parser.add_argument('-plot_manifolds',
                            default=False,
                            action='store_true',
                            help='Whether to plot manifolds.')
        parser.add_argument('-latent',
                            default=False,
                            action='store_true',
                            help='Latent statistics.')

        return parser
Exemplo n.º 5
0
    def get_parser(self):
        """
        Get parser.

        :return: parser
        :rtype: argparse.ArgumentParser
        """

        parser = argparse.ArgumentParser(
            description='Test attacks on classifier.')
        parser.add_argument('-database_file',
                            default=paths.database_file(),
                            help='HDF5 file containing font prototype images.',
                            type=str)
        parser.add_argument('-test_images_file',
                            default=paths.test_images_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-train_images_file',
                            default=paths.train_images_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-test_theta_file',
                            default=paths.test_theta_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-train_theta_file',
                            default=paths.train_theta_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-test_codes_file',
                            default=paths.test_codes_file(),
                            help='HDF5 file containing labels.',
                            type=str)
        parser.add_argument(
            '-accuracy_file',
            default=paths.results_file('classifier/accuracy'),
            help='Correctly classified test samples of classifier.',
            type=str)
        parser.add_argument(
            '-perturbations_file',
            default=paths.results_file('decoder/perturbations'),
            help='HDF5 file containing perturbations.',
            type=str)
        parser.add_argument('-success_file',
                            default=paths.results_file('decoder/success'),
                            help='HDF5 file indicating attack success.',
                            type=str)
        parser.add_argument('-plot_directory',
                            default=paths.experiment_dir('decoder'),
                            help='Path to PNG plot file for success rate.',
                            type=str)
        parser.add_argument('-results_file',
                            default='',
                            help='Path to pickled results file.',
                            type=str)
        parser.add_argument('-batch_size',
                            default=128,
                            help='Batch size of attack.',
                            type=int)
        parser.add_argument('-plot_manifolds',
                            default=False,
                            action='store_true',
                            help='Whether to plot manifolds.')
        parser.add_argument('-no_gpu', dest='use_gpu', action='store_false')

        return parser
    def get_parser(self):
        """
        Get parser.

        :return: parser
        :rtype: argparse.ArgumentParser
        """

        parser = argparse.ArgumentParser(description='Train classifier.')
        parser.add_argument('-database_file',
                            default=paths.database_file(),
                            help='HDF5 file containing font prototype images.',
                            type=str)
        parser.add_argument('-train_images_file',
                            default=paths.train_images_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-train_codes_file',
                            default=paths.train_codes_file(),
                            help='HDF5 file containing codes.',
                            type=str)
        parser.add_argument('-train_theta_file',
                            default=paths.train_theta_file(),
                            help='HDF5 file containing transformations.',
                            type=str)
        parser.add_argument('-test_images_file',
                            default=paths.test_images_file(),
                            help='HDF5 file containing dataset.',
                            type=str)
        parser.add_argument('-test_codes_file',
                            default=paths.test_codes_file(),
                            help='HDF5 file containing codes.',
                            type=str)
        parser.add_argument('-label_index',
                            default=2,
                            help='Column index in label file.',
                            type=int)
        parser.add_argument('-test_theta_file',
                            default=paths.test_theta_file(),
                            help='HDF5 file containing transformations.',
                            type=str)
        parser.add_argument(
            '-state_file',
            default=paths.state_file('robust_manifold_classifier'),
            help='Snapshot state file.',
            type=str)
        parser.add_argument(
            '-log_file',
            default=paths.log_file('robust_manifold_classifier'),
            help='Log file.',
            type=str)
        parser.add_argument(
            '-training_file',
            default=paths.results_file('robust_manifold_training'),
            help='Training statistics file.',
            type=str)
        parser.add_argument(
            '-testing_file',
            default=paths.results_file('robust_manifold_testing'),
            help='Testing statistics file.',
            type=str)
        parser.add_argument('-loss_file',
                            default=paths.image_file('loss'),
                            help='Loss plot file.',
                            type=str)
        parser.add_argument('-error_file',
                            default=paths.image_file('error'),
                            help='Error plot file.',
                            type=str)
        parser.add_argument(
            '-success_file',
            default=paths.image_file('robust_manifold_success'),
            help='Success rate plot file.',
            type=str)
        parser.add_argument('-gradient_file',
                            default='',
                            help='Gradient plot file.',
                            type=str)
        parser.add_argument(
            '-random_samples',
            default=False,
            action='store_true',
            help='Randomize the subsampling of the training set.')
        parser.add_argument('-training_samples',
                            default=-1,
                            help='Number of samples used for training.',
                            type=int)
        parser.add_argument('-test_samples',
                            default=-1,
                            help='Number of samples for validation.',
                            type=int)
        parser.add_argument('-validation_samples',
                            default=0,
                            help='Number of samples for validation.',
                            type=int)
        parser.add_argument('-early_stopping',
                            default=False,
                            action='store_true',
                            help='Use early stopping.')
        parser.add_argument('-attack_samples',
                            default=1000,
                            help='Samples to attack.',
                            type=int)
        parser.add_argument('-batch_size',
                            default=64,
                            help='Batch size.',
                            type=int)
        parser.add_argument('-epochs',
                            default=10,
                            help='Number of epochs.',
                            type=int)
        parser.add_argument('-weight_decay',
                            default=0.0001,
                            help='Weight decay importance.',
                            type=float)
        parser.add_argument('-logit_decay',
                            default=0,
                            help='Logit decay importance.',
                            type=float)
        parser.add_argument('-no_gpu', dest='use_gpu', action='store_false')
        parser.add_argument('-skip',
                            default=5,
                            help='Verbosity in iterations.',
                            type=int)
        parser.add_argument('-lr',
                            default=0.005,
                            type=float,
                            help='Base learning rate.')
        parser.add_argument('-lr_decay',
                            default=0.9,
                            type=float,
                            help='Learning rate decay.')
        parser.add_argument('-results_file',
                            default='',
                            help='Results file for evaluation.',
                            type=str)
        parser.add_argument('-debug_directory',
                            default='',
                            help='Debug directory.',
                            type=str)

        # Some network parameters.
        parser.add_argument('-network_architecture',
                            default='standard',
                            help='Classifier architecture to use.',
                            type=str)
        parser.add_argument('-network_activation',
                            default='relu',
                            help='Activation function to use.',
                            type=str)
        parser.add_argument('-network_no_batch_normalization',
                            default=False,
                            help='Do not use batch normalization.',
                            action='store_true')
        parser.add_argument(
            '-network_channels',
            default=16,
            help=
            'Channels of first convolutional layer, afterwards channels are doubled.',
            type=int)
        parser.add_argument('-network_dropout',
                            default=False,
                            action='store_true',
                            help='Whether to use dropout.')
        parser.add_argument('-network_units',
                            default='1024,1024,1024,1024',
                            help='Units for MLP.')

        # Attack parameters.
        parser.add_argument('-attack',
                            default='UntargetedBatchL2ClippedGradientDescent',
                            help='Attack to try.',
                            type=str)
        parser.add_argument('-objective',
                            default='UntargetedF6',
                            help='Objective to use.',
                            type=str)
        parser.add_argument('-epsilon',
                            default=1,
                            help='Epsilon allowed for attacks.',
                            type=float)
        parser.add_argument('-c_0',
                            default=0.,
                            help='Weight of norm.',
                            type=float)
        parser.add_argument(
            '-c_1',
            default=0.1,
            help=
            'Weight of bound, if not enforced through clipping or reparameterization.',
            type=float)
        parser.add_argument('-c_2',
                            default=0.5,
                            help='Weight of objective.',
                            type=float)
        parser.add_argument('-max_iterations',
                            default=10,
                            help='Number of iterations for attack.',
                            type=int)
        parser.add_argument(
            '-max_projections',
            default=5,
            help='Number of projections for alternating projection.',
            type=int)
        parser.add_argument('-base_lr',
                            default=0.005,
                            help='Learning rate for attack.',
                            type=float)
        parser.add_argument('-verbose',
                            action='store_true',
                            default=False,
                            help='Verbose attacks.')
        parser.add_argument('-anneal_epochs',
                            default=0,
                            help='Anneal iterations in the first epochs.',
                            type=int)

        # Variants.
        parser.add_argument('-full_variant',
                            default=False,
                            action='store_true',
                            help='100% variant.')
        parser.add_argument('-training_mode',
                            default=False,
                            action='store_true',
                            help='Training mode variant for attack.')

        return parser