Van Gogh to Photo
1

Van Gogh To Photo Dataset

This dataset contains around 401 Van Gogh images and 6853 photographs. 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.

To train with an example CycleGAN model:

mantra train cyclegan --dataset vangogh2photo --image-dim 256 256

Importing

To import this dataset to your project, run:

mantra import RJT1990/data/vangogh2photo

Usage

Example usage in code:

from data.vangogh2photo.data import VanGogh2Photo d = VanGogh2Photo() print(d.X.__class__) ## <class 'numpy.ndarray'> contains Van Gogh art print(d.Y.__class__) ## <class 'numpy.ndarray'> contains photos

Data processing
import numpy as np import glob import os import inspect from mantraml.data import Dataset, cachedata from mantraml.data import ImageDataset class VanGogh2Photo(ImageDataset): # core metadata data_name = 'Van Gogh to Photo' data_tags = ['Van Gogh', 'cycle'] data_image = 'vangogh.jpg' files = ['vangogh2photo.tar.gz'] image_dataset = 'vangogh2photo.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
vangogh2photo / __init__.py
1 lines | 49 bytes