def every_n_step_end(self, step, outputs):
    super(ValidationMonitor, self).every_n_step_end(step, outputs)
    if (self._estimator is None):
        raise ValueError('Missing call to set_estimator.')
    latest_path = saver_lib.latest_checkpoint(self._estimator.model_dir)
    if (latest_path is None):
        logging.debug('Skipping evaluation since model has not been saved yet at step %d.', step)
        return False
    if ((latest_path is not None) and (latest_path == self._latest_path)):
        logging.debug('Skipping evaluation due to same checkpoint %s for step %d as for step %d.', latest_path, step, self._latest_path_step)
        return False
    self._latest_path = latest_path
    self._latest_path_step = step
    validation_outputs = self._estimator.evaluate(x=self.x, y=self.y, input_fn=self.input_fn, batch_size=self.batch_size, steps=self.eval_steps, metrics=self.metrics, name=self.name)
    stats = []
    for name in validation_outputs:
        stats.append(('%s = %s' % (name, str(validation_outputs[name]))))
    logging.info('Validation (step %d): %s', step, ', '.join(stats))
    if (self.early_stopping_rounds is not None):
        if (self.early_stopping_metric not in validation_outputs):
            raise ValueError(('Metric %s missing from outputs %s.' % (self.early_stopping_metric, set(validation_outputs.keys()))))
        current_value = validation_outputs[self.early_stopping_metric]
        if ((self._best_value is None) or (self.early_stopping_metric_minimize and (current_value < self._best_value)) or ((not self.early_stopping_metric_minimize) and (current_value > self._best_value))):
            self._best_value = current_value
            self._best_value_step = step
        stop_now = ((step - self._best_value_step) >= self.early_stopping_rounds)
        if stop_now:
            logging.info('Stopping. Best step: {} with {} = {}.'.format(self._best_value_step, self.early_stopping_metric, self._best_value))
            self._early_stopped = True
            return True
    return False
def every_n_step_end(self, step, outputs):
    super(ValidationMonitor, self).every_n_step_end(step, outputs)
    if (self._estimator is None):
        raise ValueError('Missing call to set_estimator.')
    latest_path = saver_lib.latest_checkpoint(self._estimator.model_dir)
    if (latest_path is None):
        logging.debug('Skipping evaluation since model has not been saved yet at step %d.', step)
        return False
    if ((latest_path is not None) and (latest_path == self._latest_path)):
        logging.debug('Skipping evaluation due to same checkpoint %s for step %d as for step %d.', latest_path, step, self._latest_path_step)
        return False
    self._latest_path = latest_path
    self._latest_path_step = step
    validation_outputs = self._estimator.evaluate(x=self.x, y=self.y, input_fn=self.input_fn, batch_size=self.batch_size, steps=self.eval_steps, metrics=self.metrics, name=self.name)
    stats = []
    for name in validation_outputs:
        stats.append(('%s = %s' % (name, str(validation_outputs[name]))))
    logging.info('Validation (step %d): %s', step, ', '.join(stats))
    if (self.early_stopping_rounds is not None):
        if (self.early_stopping_metric not in validation_outputs):
            raise ValueError(('Metric %s missing from outputs %s.' % (self.early_stopping_metric, set(validation_outputs.keys()))))
        current_value = validation_outputs[self.early_stopping_metric]
        if ((self._best_value is None) or (self.early_stopping_metric_minimize and (current_value < self._best_value)) or ((not self.early_stopping_metric_minimize) and (current_value > self._best_value))):
            self._best_value = current_value
            self._best_value_step = step
        stop_now = ((step - self._best_value_step) >= self.early_stopping_rounds)
        if stop_now:
            logging.info('Stopping. Best step: {} with {} = {}.'.format(self._best_value_step, self.early_stopping_metric, self._best_value))
            self._early_stopped = True
            return True
    return False