(self)
train and eval
train and eval
train and eval
def train_and_eval(self):
    ''' train and eval '''
    nn = self.create_estimator()  #pylint: disable=invalid-name
    #logging.info("Vars: {}".format(nn.get_variable_names()))

    #pylint: disable=no-member
    train_spec = tf.estimator.TrainSpec(
        input_fn=self.input_fn(utils.TRAIN), max_steps=None, hooks=None)

    #pylint: disable=no-member
    nclass = self.config['data']['task']['classes']['num']
    # https://github.com/tensorflow/estimator/blob/master/tensorflow_estimator/python/estimator/canned/metric_keys.py
    if nclass == 2:
      default_key = metric_keys.MetricKeys.AUC
    else:
      default_key = metric_keys.MetricKeys.ACCURACY
    compare_fn = functools.partial(
        utils.metric_smaller, default_key=default_key)
    logging.info(f"Using {default_key} metric for best exporter")

    eval_spec = tf.estimator.EvalSpec(
        input_fn=self.input_fn(utils.EVAL),
        steps=None,
        name='dev',
        hooks=None,
        exporters=[
            tf.estimator.FinalExporter(
                name='final_export',
                serving_input_receiver_fn=self.create_serving_input_receiver_fn(
                ),
                assets_extra=None,
                as_text=False),
            tf.estimator.BestExporter(
                name='best_exporter',
                serving_input_receiver_fn=self.create_serving_input_receiver_fn(
                ),
                event_file_pattern='eval/*.tfevents.*',
                compare_fn=compare_fn,
                assets_extra=None,
                as_text=False,
                exports_to_keep=1,
            ),
        ],
        start_delay_secs=60,
        throttle_secs=600)

    num_epochs = self.config['solver']['optimizer']['epochs']
    for epoch in range(num_epochs):
      logging.info("epoch: {}".format(epoch + 1))
      try:
        self.train_and_eval_one_epoch(nn, train_spec, eval_spec)
      except tf.errors.OutOfRangeError as err:
        logging.info(epoch, err)
        raise err
def train_and_eval ( self ) : nn = self . create_estimator ( ) #pylint: disable=invalid-name #logging.info("Vars: {}".format(nn.get_variable_names())) #pylint: disable=no-member train_spec = tf . estimator . TrainSpec ( input_fn = self . input_fn ( utils . TRAIN ) , max_steps = None , hooks = None ) #pylint: disable=no-member nclass = self . config [ 'data' ] [ 'task' ] [ 'classes' ] [ 'num' ] # https://github.com/tensorflow/estimator/blob/master/tensorflow_estimator/python/estimator/canned/metric_keys.py if nclass == 2 : default_key = metric_keys . MetricKeys . AUC else : default_key = metric_keys . MetricKeys . ACCURACY compare_fn = functools . partial ( utils . metric_smaller , default_key = default_key ) logging . info ( f"Using {default_key} metric for best exporter" ) eval_spec = tf . estimator . EvalSpec ( input_fn = self . input_fn ( utils . EVAL ) , steps = None , name = 'dev' , hooks = None , exporters = [ tf . estimator . FinalExporter ( name = 'final_export' , serving_input_receiver_fn = self . create_serving_input_receiver_fn ( ) , assets_extra = None , as_text = False ) , tf . estimator . BestExporter ( name = 'best_exporter' , serving_input_receiver_fn = self . create_serving_input_receiver_fn ( ) , event_file_pattern = 'eval/*.tfevents.*' , compare_fn = compare_fn , assets_extra = None , as_text = False , exports_to_keep = 1 , ) , ] , start_delay_secs = 60 , throttle_secs = 600 ) num_epochs = self . config [ 'solver' ] [ 'optimizer' ] [ 'epochs' ] for epoch in range ( num_epochs ) : logging . info ( "epoch: {}" . format ( epoch + 1 ) ) try : self . train_and_eval_one_epoch ( nn , train_spec , eval_spec ) except tf . errors . OutOfRangeError as err : logging . info ( epoch , err ) raise err