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())
Exemple #2
0
    def main(self):
        """
        Main.
        """

        with open(paths.raw_celeba_labels_file(), 'r') as f:
            lines = f.read().split('\n')
            lines = [line for line in lines if line]
            lines = lines[1:]

            attributes = [str(attribute) for attribute in lines[0].split(' ') if attribute]
            lines = lines[1:]

            labels = []
            for line in lines:
                values = [int(value) for value in line.split(' ')[1:] if value]
                assert len(values) == len(attributes)
                labels.append(values)

            labels = numpy.array(labels)
            labels[labels == -1] = 0

            def statistics(labels):
                """
                Label statistics.
                """

                for i in range(len(attributes)):
                    positive = numpy.sum(labels[:, i] == 1)
                    negative = numpy.sum(labels[:, i] == 0)
                    log('%d. attribute %s: %d %d' % (i, attributes[i], positive, negative))

            N = labels.shape[0]
            N_train = int(0.9*N)

            train_labels = labels[:N_train]
            test_labels = labels[N_train:]

            statistics(labels)
            statistics(train_labels)
            statistics(test_labels)

            utils.write_hdf5(paths.celeba_train_labels_file(), train_labels.reshape(-1, 1).astype(numpy.int))
            log('wrote %s' % paths.celeba_train_labels_file())
            utils.write_hdf5(paths.celeba_test_labels_file(), test_labels.reshape(-1, 1).astype(numpy.int))
            log('wrote %s' % paths.celeba_test_labels_file())
Exemple #3
0
    def __init__(self, args=None):
        """
        Constructor.
        """

        paths.set_globals(experiment=self.experiment())
        self.train_images_file = paths.celeba_train_images_file()
        self.train_codes_file = paths.celeba_train_labels_file()
        self.test_images_file = paths.celeba_test_images_file()
        self.test_codes_file = paths.celeba_test_labels_file()
        self.label_index = 20
        self.results = dict()

        self.args = None
        """ Arguments of program. """

        parser = self.get_parser()
        if args is not None:
            self.args = parser.parse_args(args)
        else:
            self.args = parser.parse_args()

        # self.betas = [
        #     3,
        #     3,
        #     3
        # ]
        #
        # self.gammas = [
        #     1,
        #     1,
        #     1
        # ]

        # self.classifier_channels = 32
        # self.network_channels = 128

        self.classifier_channels = 64
        self.network_channels = 64

        self.training_parameters = [
            '-base_lr=0.005',
            '-weight_decay=0.0001',
            '-base_lr_decay=0.9',
            '-batch_size=100',
            '-absolute_error',
        ]

        self.classifier_parameters = [
            '-classifier_architecture=standard', '-classifier_activation=relu',
            '-classifier_channels=%d' % self.classifier_channels,
            '-classifier_units=1024,1024,1024,1024'
        ]

        self.network_parameters = [
            '-network_architecture=standard',
            '-network_activation=relu',
            '-network_channels=%d' % self.network_channels,
            '-network_units=1024,1024,1024,1024',
        ]

        log('-- ' + self.__class__.__name__)
        for key in vars(self.args):
            log('[Experiment] %s=%s' % (key, str(getattr(self.args, key))))
Exemple #4
0
    def main(self):
        """
        Main.
        """

        train_images_file = paths.celeba_train_images_file()
        test_images_file = paths.celeba_test_images_file()
        train_labels_file = paths.celeba_train_labels_file()
        test_labels_file = paths.celeba_test_labels_file()

        assert os.path.exists(train_images_file)
        assert os.path.exists(test_images_file)
        assert os.path.exists(train_labels_file)
        assert os.path.exists(test_labels_file)

        train_images = utils.read_hdf5(train_images_file)
        test_images = utils.read_hdf5(test_images_file)
        train_labels = utils.read_hdf5(train_labels_file)
        test_labels = utils.read_hdf5(test_labels_file)

        print('train_images: %s' %
              'x'.join([str(dim) for dim in train_images.shape]))
        print('test_images: %s' %
              'x'.join([str(dim) for dim in test_images.shape]))
        print('train_labels: %s' %
              'x'.join([str(dim) for dim in train_labels.shape]))
        print('test_labels: %s' %
              'x'.join([str(dim) for dim in test_labels.shape]))

        attributes = [
            '5_o_Clock_Shadow',
            'Arched_Eyebrows',
            'Attractive',
            'Bags_Under_Eyes',
            'Bald',
            'Bangs',
            'Big_Lips',
            'Big_Nose',
            'Black_Hair',
            'Blond_Hair',
            'Blurry',
            'Brown_Hair',
            'Bushy_Eyebrows',
            'Chubby',
            'Double_Chin',
            'Eyeglasses',
            'Goatee',
            'Gray_Hair',
            'Heavy_Makeup',
            'High_Cheekbones',
            'Male',
            'Mouth_Slightly_Open',
            'Mustache',
            'Narrow_Eyes',
            'No_Beard',
            'Oval_Face',
            'Pale_Skin',
            'Pointy_Nose',
            'Receding_Hairline',
            'Rosy_Cheeks',
            'Sideburns',
            'Smiling',
            'Straight_Hair',
            'Wavy_Hair',
            'Wearing_Earrings',
            'Wearing_Hat',
            'Wearing_Lipstick',
            'Wearing_Necklace',
            'Wearing_Necktie',
            'Young',
        ]

        for i in range(min(10, train_labels.shape[0])):
            log('%i: ', LogLevel.INFO, '')
            for j in range(len(attributes)):
                if train_labels[i, j] > 0:
                    log('%s ' % attributes[j])
            pyplot.imshow(train_images[i])
            pyplot.show()