def create_random_gen(self, *args): # we ignore the args train_chunk_size = int(round(self.chunk_size * self.train_sample_weight)) pseudo_chunk_size = self.chunk_size - train_chunk_size train_gen = data.multiscale_patches_gen_augmented(self.images_train, self.labels_train, self.scale_factors, patch_sizes=self.patch_sizes, chunk_size=train_chunk_size, num_chunks=self.num_chunks_train, augmentation_params=self.augmentation_params) pseudo_gen = data.multiscale_patches_gen_augmented(self.images_pseudo, self.labels_pseudo, self.scale_factors, patch_sizes=self.patch_sizes, chunk_size=pseudo_chunk_size, num_chunks=self.num_chunks_train, augmentation_params=self.augmentation_params) def random_gen(): indices = np.arange(self.chunk_size) for a, b in itertools.izip(train_gen, pseudo_gen): (chunk_x1, chunk_y1, chunk_shape), (chunk_x2, chunk_y2, _) = a, b np.random.shuffle(indices) chunk_y = np.concatenate((chunk_y1, chunk_y2), 0)[indices] chunk_x = [] for k in xrange(len(chunk_x1)): chunk_x += [np.concatenate((chunk_x1[k], chunk_x2[k]), 0)[indices]] chunk_x[k] -= self.zmuv_means[k] chunk_x[k] /= self.zmuv_stds[k] chunk_x[k] = chunk_x[k][:, None, :, :] yield chunk_x, chunk_y return buffering.buffered_gen_threaded(random_gen())
def create_random_gen(self, *args): # we ignore the args train_chunk_size = int( round(self.chunk_size * self.train_sample_weight)) pseudo_chunk_size = self.chunk_size - train_chunk_size train_gen = data.multiscale_patches_gen_augmented( self.images_train, self.labels_train, self.scale_factors, patch_sizes=self.patch_sizes, chunk_size=train_chunk_size, num_chunks=self.num_chunks_train, augmentation_params=self.augmentation_params) pseudo_gen = data.multiscale_patches_gen_augmented( self.images_pseudo, self.labels_pseudo, self.scale_factors, patch_sizes=self.patch_sizes, chunk_size=pseudo_chunk_size, num_chunks=self.num_chunks_train, augmentation_params=self.augmentation_params) def random_gen(): indices = np.arange(self.chunk_size) for a, b in zip(train_gen, pseudo_gen): (chunk_x1, chunk_y1, chunk_shape), (chunk_x2, chunk_y2, _) = a, b np.random.shuffle(indices) chunk_y = np.concatenate((chunk_y1, chunk_y2), 0)[indices] chunk_x = [] for k in range(len(chunk_x1)): chunk_x += [ np.concatenate((chunk_x1[k], chunk_x2[k]), 0)[indices] ] chunk_x[k] -= self.zmuv_means[k] chunk_x[k] /= self.zmuv_stds[k] chunk_x[k] = chunk_x[k][:, None, :, :] yield chunk_x, chunk_y return buffering.buffered_gen_threaded(random_gen())
def estimate_zmuv_params(self): gen = data.multiscale_patches_gen_augmented( self.images_train, self.labels_train, self.scale_factors, patch_sizes=self.patch_sizes, chunk_size=self.chunk_size, num_chunks=1, augmentation_params=self.augmentation_params) chunks_x, _, _ = next(gen) self.zmuv_means = [chunk_x.mean() for chunk_x in chunks_x] self.zmuv_stds = [chunk_x.std() for chunk_x in chunks_x]
def create_random_gen(self, images, labels): gen = data.multiscale_patches_gen_augmented(images, labels, self.scale_factors, patch_sizes=self.patch_sizes, chunk_size=self.chunk_size, num_chunks=self.num_chunks_train, augmentation_params=self.augmentation_params) def random_gen(): for chunks_x, chunk_y, chunk_shape in gen: for k in xrange(len(chunks_x)): chunks_x[k] -= self.zmuv_means[k] chunks_x[k] /= self.zmuv_stds[k] chunks_x[k] = chunks_x[k][:, None, :, :] yield chunks_x, chunk_y return buffering.buffered_gen_threaded(random_gen())
def create_random_gen(self, images, labels): gen = data.multiscale_patches_gen_augmented( images, labels, self.scale_factors, patch_sizes=self.patch_sizes, chunk_size=self.chunk_size, num_chunks=self.num_chunks_train, augmentation_params=self.augmentation_params) def random_gen(): for chunks_x, chunk_y, chunk_shape in gen: for k in range(len(chunks_x)): chunks_x[k] -= self.zmuv_means[k] chunks_x[k] /= self.zmuv_stds[k] chunks_x[k] = chunks_x[k][:, None, :, :] yield chunks_x, chunk_y return buffering.buffered_gen_threaded(random_gen())
def estimate_zmuv_params(self): gen = data.multiscale_patches_gen_augmented(self.images_train, self.labels_train, self.scale_factors, patch_sizes=self.patch_sizes, chunk_size=self.chunk_size, num_chunks=1, augmentation_params=self.augmentation_params) chunks_x, _, _ = gen.next() self.zmuv_means = [chunk_x.mean() for chunk_x in chunks_x] self.zmuv_stds = [chunk_x.std() for chunk_x in chunks_x]