def test_normalize_minmse(): rng = np.random.RandomState(42) for _ in range(50): target = rng.uniform(-100,100,size=(32,32,32)) x = rng.uniform(-500,500)*target + rng.uniform(-500,500) assert np.allclose(normalize_minmse(x,target),target) x, target = x.astype(np.float32), target.astype(np.float32) assert np.max(np.abs(normalize_minmse(x,target)-target)) < 1e-3
def _run_multi(y, x, models, d, ix, args): """ Trying an alternative normalization to see if that's causing the incong. with the paper results """ # Prep data axes = 'ZYX' def get_output(name, y, x): # Define comparisons return [name, np.sqrt(mse(x, y)), ssim(x, y)] # Normalize GT dynamic range to enable comparisons w/ numbers yn = normalize(y, pmin=0.1, pmax=99.9) # Get the comparison for normalized input im if args.rescale_x: xn = normalize_minmse(x, yn) else: xn = normalize(x) d['output'].append(get_output('input', yn, xn)) for m in models: model = CARE(config=None, name=m, basedir='models') pred = model.predict(xn, axes, n_tiles=(1, 4, 4), normalizer=None) pred = normalize_minmse(pred, yn) d['output'].append(get_output(m, yn, pred)) # Save the first test volume for each model if args.save_predictions: if ix == 0: save_prediction(pred, m, d['condition']) # Save the first test volume input and GT if args.save_predictions: if ix == 0: save_prediction(xn, 'input', d['condition']) save_prediction(yn, None, d['condition']) return d
def _run_input(y, x, models, d, ix, args): """ Trying an alternative normalization to see if that's causing the incong. with the paper results """ # Prep data axes = 'ZYX' def get_output(name, y, x): # Define comparisons return [name, np.sqrt(mse(x, y)), ssim(x, y)] # Normalize GT dynamic range to enable comparisons w/ numbers yn = normalize(y, pmin=0.1, pmax=99.9) # Get the comparison for normalized input im if args.rescale_x: xn = normalize_minmse(x, yn) else: xn = normalize(x) d['output'].append(get_output('input', yn, xn)) return d
def _run_multi(y, x, models, d): # Prep data axes = 'ZYX' # Define comparisons def get_output(name, y, x): return [name, np.sqrt(mse(x, y)), ssim(x, y)] # Normalize GT dynamic range to enable comparisons w/ numbers yn = normalize(y, pmin=0.1, pmax=99.9) # Get the comparison for normalized input im xn = normalize(x) d['output'].append(get_output('input', yn, xn)) for m in models: model = CARE(config=None, name=m, basedir='models') # None normalizer, already normalizing x, and this way can report the # exact pmin/max params used pred = model.predict(xn, n_tiles=(1, 4, 4), axes=axes, normalizer=None) pred = normalize_minmse(pred, yn) d['output'].append(get_output(m, yn, pred)) return d