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 main(self): """ Main. """ train_images_file = paths.celeba_train_images_file() test_images_file = paths.celeba_test_images_file() assert os.path.exists(train_images_file) assert os.path.exists(test_images_file) train_images = utils.read_hdf5(train_images_file) log('read %s' % train_images_file) test_images = utils.read_hdf5(test_images_file) log('read %s' % test_images_file) log('[Data] before train: %g %g' % (numpy.min(train_images), numpy.max(train_images))) log('[Data] before test: %g %g' % (numpy.min(train_images), numpy.max(train_images))) train_images *= 255 test_images *= 255 log('[Data] after train: %g %g' % (numpy.min(train_images), numpy.max(train_images))) log('[Data] after test: %g %g' % (numpy.min(train_images), numpy.max(train_images))) utils.write_hdf5(train_images_file, train_images.astype(numpy.float32)) log('[Data] wrote %s' % train_images_file) utils.write_hdf5(test_images_file, test_images.astype(numpy.float32)) log('[Data] wrote %s' % test_images_file)
def main(self): """ Main. """ filepaths = utils.read_ordered_directory(paths.raw_celeba_images_dir()) log('reading %s' % paths.raw_celeba_images_dir()) images = [] for filepath in filepaths: log('processing %s' % os.path.basename(filepath)) image = imageio.imread(filepath) width = 54 height = int(width*image.shape[0]/float(image.shape[1])) image = skimage.transform.resize(image, (height, width)) image = image[5:image.shape[0] - 5, 3:image.shape[1]-3, :] # Note that images are already scaled to [0, 1] here! #image = image/255. #print(numpy.min(image), numpy.max(image)) assert numpy.min(image) >= 0 and numpy.max(image) <= 1 images.append(image) #print(image.shape) #pyplot.imshow(image) #pyplot.show() images = numpy.array(images) log('%g %g' % (numpy.min(images), numpy.max(images))) N = images.shape[0] N_train = int(0.9 * N) train_images = images[:N_train] test_images = images[N_train:] utils.write_hdf5(paths.celeba_train_images_file(), train_images.astype(numpy.float32)) log('wrote %s' % paths.celeba_train_images_file()) utils.write_hdf5(paths.celeba_test_images_file(), test_images.astype(numpy.float32)) log('wrote %s' % paths.celeba_test_images_file())
def get_parser(self): """ Get parser. :return: parser :rtype: argparse.ArgumentParser """ parser = argparse.ArgumentParser() parser.add_argument('-images_file', default=paths.celeba_train_images_file(), type=str) parser.add_argument('-output_directory', default='/BS/dstutz/work/data/CelebA/_CelebA/', type=str) parser.add_argument('-max_images', default=50, type=str) # return parser
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))))
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()