Satellite to Map
1

Satellite to Map Dataset

This dataset contains over 1,000 images of Google map images and satellite images 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.

To train with a CycleGAN:

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

Importing

To import this dataset to your project, run:

mantra import RJT1990/data/maps

Usage

Example usage in code:

from data.maps.data import Satellite2Map d = Satellite2Map() print(d.Y.__class__) ## <class 'numpy.ndarray'> contains satellite images print(d.X.__class__) ## <class 'numpy.ndarray'> contains Google maps images

Data processing
import numpy as np import glob import os import inspect from mantraml.data import Dataset, cachedata from mantraml.data import ImageDataset class Satellite2Map(ImageDataset): # core metadata data_name = 'Satellite to Map' data_tags = ['satellite', 'map', 'cycle'] data_image = 'teaser.png' files = ['maps.tar.gz'] image_dataset = 'maps.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
maps / data.py
80 lines | 2817 bytes
import numpy as np import glob import os import inspect from mantraml.data import Dataset, cachedata from mantraml.data import ImageDataset class Satellite2Map(ImageDataset): # core metadata data_name = 'Satellite to Map' data_tags = ['satellite', 'map', 'cycle'] data_image = 'teaser.png' files = ['maps.tar.gz'] image_dataset = 'maps.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)