Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _normalize(patches_x,patches_y, x,y,mask,channel):
pmins, pmaxs = zip(*(get_percentiles() for _ in patches_x))
percentile_axes = None if channel is None else tuple((d for d in range(x.ndim) if d != channel))
_perc = lambda a,p: np.percentile(a,p,axis=percentile_axes,keepdims=True)
patches_x_norm = normalize_mi_ma(patches_x, _perc(x,pmins), _perc(x,pmaxs))
if relu_last:
pmins = np.zeros_like(pmins)
patches_y_norm = normalize_mi_ma(patches_y, _perc(y,pmins), _perc(y,pmaxs))
return patches_x_norm, patches_y_norm
def _normalize(patches_x,patches_y, x,y,mask,channel):
pmins, pmaxs = zip(*(get_percentiles() for _ in patches_x))
percentile_axes = None if channel is None else tuple((d for d in range(x.ndim) if d != channel))
_perc = lambda a,p: np.percentile(a,p,axis=percentile_axes,keepdims=True)
patches_x_norm = normalize_mi_ma(patches_x, _perc(x,pmins), _perc(x,pmaxs))
if relu_last:
pmins = np.zeros_like(pmins)
patches_y_norm = normalize_mi_ma(patches_y, _perc(y,pmins), _perc(y,pmaxs))
return patches_x_norm, patches_y_norm
def _normalize(patches_x,patches_y, x,y,mask,channel):
pmins, pmaxs = zip(*(get_percentiles() for _ in patches_x))
percentile_axes = None if channel is None else tuple((d for d in range(x.ndim) if d != channel))
_perc = lambda a,p: np.percentile(a,p,axis=percentile_axes,keepdims=True)
patches_x_norm = normalize_mi_ma(patches_x, _perc(x,pmins), _perc(x,pmaxs))
if relu_last:
pmins = np.zeros_like(pmins)
patches_y_norm = normalize_mi_ma(patches_y, _perc(y,pmins), _perc(y,pmaxs))
return patches_x_norm, patches_y_norm
def _normalize(patches_x,patches_y, x,y,mask,channel):
pmins, pmaxs = zip(*(get_percentiles() for _ in patches_x))
percentile_axes = None if channel is None else tuple((d for d in range(x.ndim) if d != channel))
_perc = lambda a,p: np.percentile(a,p,axis=percentile_axes,keepdims=True)
patches_x_norm = normalize_mi_ma(patches_x, _perc(x,pmins), _perc(x,pmaxs))
if relu_last:
pmins = np.zeros_like(pmins)
patches_y_norm = normalize_mi_ma(patches_y, _perc(y,pmins), _perc(y,pmaxs))
return patches_x_norm, patches_y_norm
def before(self, x, axes):
"""Percentile-based normalization of raw input image.
See :func:`csbdeep.predict.Normalizer.before` for parameter descriptions.
Note that percentiles are computed individually for each channel (if present in `axes`).
"""
self.axes_before = axes_check_and_normalize(axes,x.ndim)
axis = tuple(d for d,a in enumerate(self.axes_before) if a != 'C')
self.mi = np.percentile(x,self.pmin,axis=axis,keepdims=True).astype(self.dtype,copy=False)
self.ma = np.percentile(x,self.pmax,axis=axis,keepdims=True).astype(self.dtype,copy=False)
return normalize_mi_ma(x, self.mi, self.ma, dtype=self.dtype, **self.kwargs)