def get_downsampled_imagenet_augmented_data(subset, options, do_multiprocess=True, do_validation=False, shuffle=None): isTrain = subset == 'train' and do_multiprocess shuffle = shuffle if shuffle is not None else isTrain reret = re.search(r'^imagenet([0-9]*)$', options.ds_name) input_size = int(reret.group(1)) ds = DownsampledImageNet(_data_batch_dir(options.data_dir, input_size),\ subset, shuffle, input_size, do_validation=do_validation) pp_mean = ds.mean_img paste_size = ds.input_size * 5 // 4 crop_size = ds.input_size if isTrain: augmentors = [ imgaug.CenterPaste((paste_size, paste_size)), imgaug.RandomCrop((crop_size, crop_size)), imgaug.Flip(horiz=True), imgaug.MapImage(lambda x: (x - pp_mean)/128.0), ] else: augmentors = [ imgaug.MapImage(lambda x: (x - pp_mean)/128.0) ] ds = AugmentImageComponent(ds, augmentors) ds = BatchData(ds, options.batch_size // options.nr_gpu, remainder=not isTrain) if do_multiprocess: ds = PrefetchData(ds, 4, 2) return ds
def get_data(train_or_test): isTrain = train_or_test == 'train' pp_mean = dataset.SVHNDigit.get_per_pixel_mean() if isTrain: d1 = dataset.SVHNDigit('train') d2 = dataset.SVHNDigit('extra') ds = RandomMixData([d1, d2]) else: ds = dataset.SVHNDigit('test') if isTrain: augmentors = [ imgaug.CenterPaste((40, 40)), imgaug.RandomCrop((32, 32)), #imgaug.Flip(horiz=True), imgaug.BrightnessAdd(10), imgaug.Contrast((0.8, 1.2)), imgaug.GaussianDeform( # this is slow [(0.2, 0.2), (0.2, 0.8), (0.8, 0.8), (0.8, 0.2)], (32, 32), 0.2, 3), imgaug.MapImage(lambda x: x - pp_mean), ] else: augmentors = [imgaug.MapImage(lambda x: x - pp_mean)] ds = AugmentImageComponent(ds, augmentors) ds = BatchData(ds, 128, remainder=not isTrain) if isTrain: ds = PrefetchData(ds, 5, 5) return ds
def get_cifar_augmented_data(subset, options, do_multiprocess=True, do_validation=False, shuffle=None): isTrain = subset == 'train' and do_multiprocess shuffle = shuffle if shuffle is not None else isTrain if options.num_classes == 10 and options.ds_name == 'cifar10': ds = dataset.Cifar10(subset, shuffle=shuffle, do_validation=do_validation) cutout_length = 16 n_holes = 1 elif options.num_classes == 100 and options.ds_name == 'cifar100': ds = dataset.Cifar100(subset, shuffle=shuffle, do_validation=do_validation) cutout_length = 8 n_holes = 1 else: raise ValueError( 'Number of classes must be set to 10(default) or 100 for CIFAR') logger.info('{} set has n_samples: {}'.format(subset, len(ds.data))) pp_mean = ds.get_per_pixel_mean() if isTrain: logger.info('Will do cut-out with length={} n_holes={}'.format( cutout_length, n_holes)) augmentors = [ imgaug.CenterPaste((40, 40)), imgaug.RandomCrop((32, 32)), imgaug.Flip(horiz=True), imgaug.MapImage(lambda x: (x - pp_mean) / 128.0), Cutout(length=cutout_length, n_holes=n_holes), ] else: augmentors = [imgaug.MapImage(lambda x: (x - pp_mean) / 128.0)] ds = AugmentImageComponent(ds, augmentors) ds = BatchData(ds, options.batch_size // options.nr_gpu, remainder=not isTrain) if do_multiprocess: ds = PrefetchData(ds, 3, 2) return ds
def get_data(name, batch): isTrain = name == 'train' if isTrain: augmentors = [ imgaug.ResizeShortestEdge(256, cv2.INTER_CUBIC), imgaug.RandomCrop(224), imgaug.Lighting(0.1, eigval=np.asarray( [0.2175, 0.0188, 0.0045][::-1]) * 255.0, eigvec=np.array( [[-0.5675, 0.7192, 0.4009], [-0.5808, -0.0045, -0.8140], [-0.5836, -0.6948, 0.4203]], dtype='float32')[::-1, ::-1]), imgaug.Flip(horiz=True)] else: augmentors = [ imgaug.ResizeShortestEdge(256, cv2.INTER_CUBIC), imgaug.CenterCrop((224, 224))] return get_imagenet_dataflow(args.data, name, batch, augmentors)
def get_data(self, train_or_test): isTrain = train_or_test == 'train' ds = dataset.Cifar10(train_or_test, dir='.') pp_mean = ds.get_per_pixel_mean() if isTrain: augmentors = [ imgaug.CenterPaste((40, 40)), imgaug.RandomCrop((32, 32)), imgaug.Flip(horiz=True), # imgaug.Brightness(20), # imgaug.Contrast((0.6,1.4)), imgaug.MapImage(lambda x: x - pp_mean), ] else: augmentors = [imgaug.MapImage(lambda x: x - pp_mean)] ds = AugmentImageComponent(ds, augmentors) ds = BatchData(ds, self.batch_size, remainder=not isTrain) if isTrain: ds = PrefetchData(ds, 3, 2) return ds