(self, mode)
build model like tf.estimator.Estimator
build model like tf.estimator.Estimator
build model like tf . estimator . Estimator
def model_fn(self, mode):
    ''' build model like tf.estimator.Estimator'''
    with tf.device('/cpu:0'):
      self._model = super().model_fn()

    if not self.model.built:
      assert self.batch_input_shape
      # data must be (features, labels), only using features as input
      self.model.build(input_shape=self.batch_input_shape[0])

    assert self._init_epoch in range(0, self._num_epochs)
    model_load_type, model_file_name = solver_utils.get_model_file(
        dir_name=self._model_path,
        file_name_pattern=self._checkpoint_file_pattern,
        mode=mode,
        model_load_type=self._model_load_type,
        specified_model_file_name=self._specified_model_file)

    logging.info("{}-{}: load model from {}".format(mode, model_load_type,
                                                    model_file_name))
    if model_file_name is not None:
      if self.model.built:
        self.model.load_weights(str(model_file_name), by_name=False)
      else:
        self._model = tf.keras.models.load_model(str(model_file_name))

    # parallel and compile model
    self.build(multi_gpu=(mode == utils.TRAIN))
def model_fn ( self , mode ) : with tf . device ( '/cpu:0' ) : self . _model = super ( ) . model_fn ( ) if not self . model . built : assert self . batch_input_shape # data must be (features, labels), only using features as input self . model . build ( input_shape = self . batch_input_shape [ 0 ] ) assert self . _init_epoch in range ( 0 , self . _num_epochs ) model_load_type , model_file_name = solver_utils . get_model_file ( dir_name = self . _model_path , file_name_pattern = self . _checkpoint_file_pattern , mode = mode , model_load_type = self . _model_load_type , specified_model_file_name = self . _specified_model_file ) logging . info ( "{}-{}: load model from {}" . format ( mode , model_load_type , model_file_name ) ) if model_file_name is not None : if self . model . built : self . model . load_weights ( str ( model_file_name ) , by_name = False ) else : self . _model = tf . keras . models . load_model ( str ( model_file_name ) ) # parallel and compile model self . build ( multi_gpu = ( mode == utils . TRAIN ) )