Horse to Zebra
2

Horse to Zebra Dataset

This dataset contains over 1,000 images of horses and zebras respectively. This is intended to be used with image translation models, such as CycleGANs, although you can also use it with regular GANs as well. This dataset was ported from a CycleGAN implementation by the authors Zhu et al. You can obtain the original code here.

The default image size is 256x256, but you can also specify different size during training, e.g.

mantra train cyclegan --dataset horse2zebra --image-dim 128 128

Importing

To import this dataset to your project, run:

mantra import RJT1990/data/horse2zebra

Usage

Example usage in code:

from data.horse2zebra.data import Horse2Zebra d = Horse2Zebra() print(d.Y.__class__) ## <class 'numpy.ndarray'> contains zebras print(d.X.__class__) ## <class 'numpy.ndarray'> contains horses

Data processing
import numpy as np import glob import os import inspect from mantraml.data import Dataset, cachedata from mantraml.data import ImageDataset class Horse2Zebra(ImageDataset): # core metadata data_name = 'Horse to Zebra' data_tags = ['horses', 'zebras', 'cycle'] data_image = 'horsezebra.jpg' files = ['horse2zebra.tar.gz'] image_dataset = 'horse2zebra.tar.gz' # referring to the file that contains the images # additional default data has_labels = False image_dim = (256, 256) normalize = True @cachedata def Y(self): """ This method extracts inputs from the data. The output should be an np.ndarray that can be processed by the model. Returns -------- np.ndarray - of data inputs (X vector) """ images = glob.glob(os.path.join(self.extracted_data_path, 'trainA/*%s' % self.file_format)) training_data = [] self.unprocessed_images = [] self.image_file_names = [] for image_name in images: image_data = self.get_image(image_name, resize_height=self.image_shape[0], resize_width=self.image_shape[1], crop=True, normalize=self.normalize) if image_data.shape == self.image_shape: training_data.append(image_data) self.image_file_names.append(image_name.split(self.extracted_data_path +'/')[-1]) else: self.unprocessed_images.append((image_name, 'Image shape of extracted image differed from self.image_shape : %s' % image_name)) np.random.shuffle(training_data) return np.array(training_data) @cachedata def X(self): """ This method extracts inputs from the data. The output should be an np.ndarray that can be processed by the model. Returns -------- np.ndarray - of data inputs (X vector) """ images = glob.glob(os.path.join(self.extracted_data_path, 'trainB/*%s' % self.file_format)) training_data = [] self.unprocessed_images = [] self.image_file_names = [] for image_name in images: image_data = self.get_image(image_name, resize_height=self.image_shape[0], resize_width=self.image_shape[1], crop=True, normalize=self.normalize) if image_data.shape == self.image_shape: training_data.append(image_data) self.image_file_names.append(image_name.split(self.extracted_data_path +'/')[-1]) else: self.unprocessed_images.append((image_name, 'Image shape of extracted image differed from self.image_shape : %s' % image_name)) np.random.shuffle(training_data) return np.array(training_data)
All files
Last Modified
horse2zebra.tar.gz
17 September 2018 1:51 PM
sample.jpg
17 September 2018 1:51 PM