docstr: :param model_fn: Model function. Follows the signature:
  
      * Args:
  
          * `features`: This is the first item returned from the `input_fn`
              passed to `train`, `evaluate`, and `predict`. This should be a
              single `tf.Tensor` or `dict` of same.
          * `labels`: This is the second item returned from the `input_fn`
              passed to `train`, `evaluate`, and `predict`. This should be a
              single `tf.Tensor` or `dict` of same (for multi-head models).
              If mode is `tf.estimator.ModeKeys.PREDICT`, `labels=None` will
              be passed. If the `model_fn`'s signature does not accept
              `mode`, the `model_fn` must still be able to handle
              `labels=None`.
          * `mode`: Optional. Specifies if this training, evaluation or
              prediction. See `tf.estimator.ModeKeys`.
          * `params`: Optional `dict` of hyperparameters.  Will receive what
              is passed to Estimator in `params` parameter. This allows
              to configure Estimators from hyper parameter tuning.
          * `config`: Optional `estimator.RunConfig` object. Will receive what
              is passed to Estimator as its `config` parameter, or a default
              value. Allows setting up things in your `model_fn` based on
              configuration such as `num_ps_replicas`, or `model_dir`.
  
      * Returns:
          `tf.estimator.EstimatorSpec`
  
      For the train_op in tf.estimator.EstimatorSpec, it derive from and only from
      `zoo.tfpark.zoo_optimizer.ZooOptimizer`
  :param model_dir: Directory to save model parameters, graph and etc. This can
      also be used to load checkpoints from the directory into an estimator to
      continue training a previously saved model. If `PathLike` object, the
      path will be resolved. If `None`, the model_dir in `config` will be used
      if set. If both are set, they must be same. If both are `None`, a
      temporary directory will be used.
  :param config: `estimator.RunConfig` configuration object.
  :param params: `dict` of hyper parameters that will be passed into `model_fn`.
        Keys are names of parameters, values are basic python types.
  :param warm_start_from: Optional string filepath to a checkpoint or SavedModel to
                 warm-start from, or a `tf.estimator.WarmStartSettings`
                 object to fully configure warm-starting.  If the string
                 filepath is provided instead of a
                 `tf.estimator.WarmStartSettings`, then all variables are
                 warm-started, and it is assumed that vocabularies
                 and `tf.Tensor` names are unchanged.
docstr_tok: [":","param","model_fn",":","Model","function",".","Follows","the","signature",":","*","Args",":","*","`","features","`",":","This","is","the","first","item","returned","from","the","`","input_fn","`","passed","to","`","train","`",",","`","evaluate","`",",","and","`","predict","`",".","This","should","be","a","single","`","tf.Tensor","`","or","`","dict","`","of","same",".","*","`","labels","`",":","This","is","the","second","item","returned","from","the","`","input_fn","`","passed","to","`","train","`",",","`","evaluate","`",",","and","`","predict","`",".","This","should","be","a","single","`","tf.Tensor","`","or","`","dict","`","of","same","(","for","multi-head","models",")",".","If","mode","is","`","tf.estimator.ModeKeys.PREDICT","`",",","`","labels=None","`","will","be","passed",".","If","the","`","model_fn","`","'s","signature","does","not","accept","`","mode","`",",","the","`","model_fn","`","must","still","be","able","to","handle","`","labels=None","`",".","*","`","mode","`",":","Optional",".","Specifies","if","this","training",",","evaluation","or","prediction",".","See","`","tf.estimator.ModeKeys","`",".","*","`","params","`",":","Optional","`","dict","`","of","hyperparameters",".","Will","receive","what","is","passed","to","Estimator","in","`","params","`","parameter",".","This","allows","to","configure","Estimators","from","hyper","parameter","tuning",".","*","`","config","`",":","Optional","`","estimator.RunConfig","`","object",".","Will","receive","what","is","passed","to","Estimator","as","its","`","config","`","parameter",",","or","a","default","value",".","Allows","setting","up","things","in","your","`","model_fn","`","based","on","configuration","such","as","`","num_ps_replicas","`",",","or","`","model_dir","`",".","*","Returns",":","`","tf.estimator.EstimatorSpec","`","For","the","train_op","in","tf.estimator.EstimatorSpec",",","it","derive","from","and","only","from","`","zoo.tfpark.zoo_optimizer.ZooOptimizer","`",":","param","model_dir",":","Directory","to","save","model","parameters",",","graph","and","etc",".","This","can","also","be","used","to","load","checkpoints","from","the","directory","into","an","estimator","to","continue","training","a","previously","saved","model",".","If","`","PathLike","`","object",",","the","path","will","be","resolved",".","If","`","None","`",",","the","model_dir","in","`","config","`","will","be","used","if","set",".","If","both","are","set",",","they","must","be","same",".","If","both","are","`","None","`",",","a","temporary","directory","will","be","used",".",":","param","config",":","`","estimator.RunConfig","`","configuration","object",".",":","param","params",":","`","dict","`","of","hyper","parameters","that","will","be","passed","into","`","model_fn","`",".","Keys","are","names","of","parameters",",","values","are","basic","python","types",".",":","param","warm_start_from",":","Optional","string","filepath","to","a","checkpoint","or","SavedModel","to","warm-start","from",",","or","a","`","tf.estimator.WarmStartSettings","`","object","to","fully","configure","warm-starting",".","If","the","string","filepath","is","provided","instead","of","a","`","tf.estimator.WarmStartSettings","`",",","then","all","variables","are","warm-started",",","and","it","is","assumed","that","vocabularies","and","`","tf.Tensor","`","names","are","unchanged","."]
code: def from_model_fn(
      cls,
      model_fn,
      model_dir=None,
      config=None,
      params=None,
      warm_start_from=None,
  ):
      """
      :param model_fn: Model function. Follows the signature:
  
          * Args:
  
              * `features`: This is the first item returned from the `input_fn`
                  passed to `train`, `evaluate`, and `predict`. This should be a
                  single `tf.Tensor` or `dict` of same.
              * `labels`: This is the second item returned from the `input_fn`
                  passed to `train`, `evaluate`, and `predict`. This should be a
                  single `tf.Tensor` or `dict` of same (for multi-head models).
                  If mode is `tf.estimator.ModeKeys.PREDICT`, `labels=None` will
                  be passed. If the `model_fn`'s signature does not accept
                  `mode`, the `model_fn` must still be able to handle
                  `labels=None`.
              * `mode`: Optional. Specifies if this training, evaluation or
                  prediction. See `tf.estimator.ModeKeys`.
              * `params`: Optional `dict` of hyperparameters.  Will receive what
                  is passed to Estimator in `params` parameter. This allows
                  to configure Estimators from hyper parameter tuning.
              * `config`: Optional `estimator.RunConfig` object. Will receive what
                  is passed to Estimator as its `config` parameter, or a default
                  value. Allows setting up things in your `model_fn` based on
                  configuration such as `num_ps_replicas`, or `model_dir`.
  
          * Returns:
              `tf.estimator.EstimatorSpec`
  
          For the train_op in tf.estimator.EstimatorSpec, it derive from and only from
          `zoo.tfpark.zoo_optimizer.ZooOptimizer`
      :param model_dir: Directory to save model parameters, graph and etc. This can
          also be used to load checkpoints from the directory into an estimator to
          continue training a previously saved model. If `PathLike` object, the
          path will be resolved. If `None`, the model_dir in `config` will be used
          if set. If both are set, they must be same. If both are `None`, a
          temporary directory will be used.
      :param config: `estimator.RunConfig` configuration object.
      :param params: `dict` of hyper parameters that will be passed into `model_fn`.
            Keys are names of parameters, values are basic python types.
      :param warm_start_from: Optional string filepath to a checkpoint or SavedModel to
                     warm-start from, or a `tf.estimator.WarmStartSettings`
                     object to fully configure warm-starting.  If the string
                     filepath is provided instead of a
                     `tf.estimator.WarmStartSettings`, then all variables are
                     warm-started, and it is assumed that vocabularies
                     and `tf.Tensor` names are unchanged.
      """
      import tensorflow as tf
  
      estimator = tf.estimator.Estimator(
          model_fn,
          model_dir=model_dir,
          config=config,
          params=params,
          warm_start_from=warm_start_from,
      )
      return cls(estimator)
  
file_path: analytics-zoo/pyzoo/zoo/tfpark/estimator.py
imports: from bigdl.optim.optimizer import MaxIteration, Loss, TreeNNAccuracy
  from zoo.tfpark.utils import evaluate_string_metrics
  from zoo.pipeline.api.keras import metrics
  from zoo.tfpark.tfnet import TFNet
  from zoo.tfpark.tf_optimizer import TFOptimizer
  from zoo.tfpark.tf_dataset import TFDataset
  from zoo.util import nest
  import six
  import os
label_desc: Use image node_id 2 for calling the TFEstimator obj's underlying member method code with example usage: obj.from_model_fn(cls, model_fn, model_dir, config, params, warm_start_from) and returns: cls