def __init__(self, X, Y, n_rays, grid, batch_size, patch_size, use_gpu=False, sample_ind_cache=True, maxfilter_patch_size=None, augmenter=None, foreground_prob=0): X = [x.astype(np.float32, copy=False) for x in X] # Y = [y.astype(np.uint16, copy=False) for y in Y] # sanity checks assert len(X) == len(Y) and len(X) > 0 nD = len(patch_size) assert nD in (2, 3) x_ndim = X[0].ndim assert x_ndim in (nD, nD + 1) assert all( y.ndim == nD and x.ndim == x_ndim and x.shape[:nD] == y.shape for x, y in zip(X, Y)) if x_ndim == nD: self.n_channel = None else: self.n_channel = X[0].shape[-1] assert all(x.shape[-1] == self.n_channel for x in X) assert 0 <= foreground_prob <= 1 self.X, self.Y = X, Y self.batch_size = batch_size self.n_rays = n_rays self.patch_size = patch_size self.ss_grid = (slice(None), ) + tuple(slice(0, None, g) for g in grid) self.perm = np.random.permutation(len(self.X)) self.use_gpu = bool(use_gpu) if augmenter is None: augmenter = lambda *args: args callable(augmenter) or _raise( ValueError("augmenter must be None or callable")) self.augmenter = augmenter self.foreground_prob = foreground_prob if self.use_gpu: from gputools import max_filter self.max_filter = lambda y, patch_size: max_filter( y.astype(np.float32), patch_size) else: from scipy.ndimage.filters import maximum_filter self.max_filter = lambda y, patch_size: maximum_filter( y, patch_size, mode='constant') self.maxfilter_patch_size = maxfilter_patch_size if maxfilter_patch_size is not None else self.patch_size self.sample_ind_cache = sample_ind_cache self._ind_cache_fg = {} self._ind_cache_all = {}
def __init__(self, X, Y, n_params, grid, batch_size, patch_size, length, use_gpu=False, sample_ind_cache=True, maxfilter_patch_size=None, augmenter=None, foreground_prob=0): super().__init__(data_size=len(X), batch_size=batch_size, length=length, shuffle=True) if isinstance(X, (np.ndarray, tuple, list)): X = [x.astype(np.float32, copy=False) for x in X] # Y = [y.astype(np.uint16, copy=False) for y in Y] # sanity checks assert len(X)==len(Y) and len(X)>0 nD = len(patch_size) assert nD in (2,3) x_ndim = X[0].ndim assert x_ndim in (nD,nD+1) if isinstance(X, (np.ndarray, tuple, list)) and \ isinstance(Y, (np.ndarray, tuple, list)): all(y.ndim==nD and x.ndim==x_ndim and x.shape[:nD]==y.shape for x,y in zip(X,Y)) or _raise("images and masks should have corresponding shapes/dimensions") #REFACTORED # all(x.shape[:nD]>=patch_size for x in X) or _raise("Some images are too small for given patch_size {patch_size}".format(patch_size=patch_size)) if x_ndim == nD: self.n_channel = None else: self.n_channel = X[0].shape[-1] assert all(x.shape[-1]==self.n_channel for x in X) assert 0 <= foreground_prob <= 1 self.X, self.Y = X, Y # self.batch_size = batch_size self.n_params = n_params self.patch_size = patch_size self.ss_grid = (slice(None),) + tuple(slice(0, None, g) for g in grid) self.use_gpu = bool(use_gpu) if augmenter is None: augmenter = lambda *args: args callable(augmenter) or _raise(ValueError("augmenter must be None or callable")) self.augmenter = augmenter self.foreground_prob = foreground_prob if self.use_gpu: from gputools import max_filter self.max_filter = lambda y, patch_size: max_filter(y.astype(np.float32), patch_size) else: from scipy.ndimage.filters import maximum_filter self.max_filter = lambda y, patch_size: maximum_filter(y, patch_size, mode='constant') self.maxfilter_patch_size = maxfilter_patch_size if maxfilter_patch_size is not None else self.patch_size self.sample_ind_cache = sample_ind_cache self._ind_cache_fg = {} self._ind_cache_all = {}
def __init__(self, X, Y, n_rays, grid, batch_size, patch_size, use_gpu=False, maxfilter_cache=True, maxfilter_patch_size=None, augmenter=None): X = [x.astype(np.float32, copy=False) for x in X] # Y = [y.astype(np.uint16, copy=False) for y in Y] self.X, self.Y = X, Y self.batch_size = batch_size self.n_rays = n_rays self.patch_size = patch_size self.ss_grid = (slice(None), ) + tuple(slice(0, None, g) for g in grid) self.perm = np.random.permutation(len(self.X)) self.use_gpu = bool(use_gpu) if augmenter is None: augmenter = lambda *args: args callable(augmenter) or _raise( ValueError("augmenter must be None or callable")) self.augmenter = augmenter if self.use_gpu: from gputools import max_filter self.max_filter = lambda y, patch_size: max_filter( y.astype(np.float32), patch_size) else: from scipy.ndimage.filters import maximum_filter self.max_filter = lambda y, patch_size: maximum_filter( y, patch_size, mode='constant') self.maxfilter_patch_size = maxfilter_patch_size if maxfilter_patch_size is not None else self.patch_size if maxfilter_cache: self.R = [ self.no_background_patches((x, y)) for x, y in zip(self.X, self.Y) ] else: self.R = None