def _california(reduce=False): """ Load California dataset from .mat """ mat = loadmat("data/California/UiT_HCD_California_2017.mat") t1 = np.array(mat["t1_L8_clipped"], dtype=np.float32) t2 = np.array(mat["logt2_clipped"], dtype=np.float32) change_mask = tf.convert_to_tensor(mat["ROI"], dtype=tf.bool) assert t1.shape[:2] == t2.shape[:2] == change_mask.shape[:2] if change_mask.ndim == 2: change_mask = change_mask[..., np.newaxis] if reduce: print("Reducing") reduction_ratios = (4, 4) new_dims = list( map(lambda a, b: a // b, change_mask.shape, reduction_ratios)) t1 = tf.cast(tf.image.resize(t1, new_dims, antialias=True), dtype=tf.float32) t2 = tf.cast(tf.image.resize(t2, new_dims, antialias=True), dtype=tf.float32) change_mask = tf.cast( tf.image.resize(tf.cast(change_mask, tf.uint8), new_dims, antialias=True), tf.bool, ) t1, t2, change_mask = ( remove_borders(t1, 2), remove_borders(t2, 2), remove_borders(change_mask, 2), ) return t1, t2, change_mask
def _france(reduce=True): """ Load France dataset from .mat """ mat = loadmat("data/France/France.mat") t1 = np.array(mat["t1"], dtype=np.single) t2 = np.array(mat["t2"], dtype=np.single) t1, t2 = _clip(t1), _clip(t2) change_mask = tf.convert_to_tensor(mat["ROI"], dtype=tf.bool) assert t1.shape[:2] == t2.shape[:2] == change_mask.shape[:2] if change_mask.ndim == 2: change_mask = change_mask[..., np.newaxis] if reduce: print("Reducing") reduction_ratios = (5, 5) new_dims = list( map(lambda a, b: a // b, change_mask.shape, reduction_ratios)) t1 = tf.cast(tf.image.resize(t1, new_dims, antialias=True), dtype=tf.float32) t2 = tf.cast(tf.image.resize(t2, new_dims, antialias=True), dtype=tf.float32) change_mask = tf.cast( tf.image.resize(tf.cast(change_mask, tf.uint8), new_dims, antialias=True), tf.bool, ) t1, t2, change_mask = ( remove_borders(t1, 2), remove_borders(t2, 2), remove_borders(change_mask, 2), ) return t1, t2, change_mask
def fetch_CGAN(name, **kwargs): """ Input: name - dataset name, should be in DATASETS kwargs - config {key: value} pairs. Key should be in DATASET_DEFAULT_CONFIG Output: training_data - tf.data.Dataset with (x, y, prior) shapes like (inf, patch_size, patch_size, ?) evaluation_data - tf.data.Dataset with (x, y, change_map) shapes (1, h, w, ?) channels - tuple (c_x, c_y), number of channels for domains x and y """ ps = kwargs.get("patch_size") y_im, x_im, target_cm = DATASETS[name](prepare_data[name]) if not tf.config.list_physical_devices("GPU"): dataset = [ tf.image.central_crop(tensor, 0.1) for tensor in [x_im, y_im, target_cm] ] else: dataset = [x_im, y_im, target_cm] chs = [tensor.shape[-1] for tensor in dataset] dataset = [remove_borders(tensor, ps) for tensor in dataset] dataset = [tf.expand_dims(tensor, 0) for tensor in dataset] evaluation_data = tf.data.Dataset.from_tensor_slices(tuple(dataset)) dataset = [image_in_patches(tensor, ps) for tensor in dataset] tot_patches = dataset[0].shape[0] return dataset[0], dataset[1], evaluation_data, (chs[0], chs[1]), tot_patches
def _italy(reduce=False): """ Load Italy dataset from .mat """ mat = loadmat("data/Italy/Italy.mat") t1 = np.array(mat["t1"], dtype=np.single) t2 = np.array(mat["t2"], dtype=np.single) change_mask = np.array(mat["ROI"], dtype=np.bool) if t1.shape[-1] == 3: t1 = t1[..., 0] t1, t2, change_mask = ( remove_borders(t1, 2), remove_borders(t2, 2), remove_borders(change_mask, 2), ) t1, t2 = _clip(t1[..., np.newaxis]), _clip(t2) change_mask = tf.convert_to_tensor(change_mask, dtype=tf.bool) assert t1.shape[:2] == t2.shape[:2] == change_mask.shape[:2] if change_mask.ndim == 2: change_mask = change_mask[..., np.newaxis] change_mask = change_mask[..., :1] return t1, t2, change_mask
def _texas(clip=True): """ Load Texas dataset from .mat """ mat = loadmat("data/Texas/Cross-sensor-Bastrop-data.mat") t1 = np.array(mat["t1_L5"], dtype=np.single) t2 = np.array(mat["t2_ALI"], dtype=np.single) if clip: print("clipping") t1, t2 = _clip(t1), _clip(t2) change_mask = tf.convert_to_tensor(mat["ROI_1"], dtype=tf.bool) assert t1.shape[:2] == t2.shape[:2] == change_mask.shape[:2] if change_mask.ndim == 2: change_mask = change_mask[..., np.newaxis] t1, t2, change_mask = ( remove_borders(t1, 2), remove_borders(t2, 2), remove_borders(change_mask, 2), ) return t1, t2, change_mask