def resample(self, shape): from diffeo2c import diffeo_resample d2 = diffeo_resample(self.d, shape) # this might give negative values v2 = scipy_image_resample(self.variance, shape) np.clip(v2, 0, 1, out=v2) return Diffeomorphism2D(d2, v2)
def update(self, y0, y1): # init structures if not already if not self.initialized(): self.init_structures(y0.shape) warnings.warn('remove') self.stop_at_convergence = True if self.reached_end and self.stop_at_convergence: if self.total_obs % 100 == 1: self.info('Not integrating anymore (%s)' % self.total_obs) self.total_obs += 1 msg = 'Reached convergence and stop_at_converged=True.' raise Diffeo2dEstimatorInterface.LearningConverged(msg) phase = self.phases[self.current_phase] estimator = self.estimators[self.current_phase] target_shape = phase.shape y0 = scipy_image_resample(y0, target_shape) y1 = scipy_image_resample(y1, target_shape) estimator.update(y0, y1) self.phase_obs += 1 warnings.warn('remove this') self.check_every = 50 if self.phase_obs % self.check_every == 0: if self.should_switch(): if self.current_phase < len(self.phases) - 1: self.info('Switching to next phase.') self.next_phase() else: self.info('Reached end of phases.') self.reached_end = True self.total_obs += 1