docstr: Create an Estimator for tensorflow 2.
  
  :param model_creator: (dict -> Model) This function takes in the `config`
         dict and returns a compiled TF model.
  :param config: (dict) configuration passed to 'model_creator',
         'data_creator'. Also contains `fit_config`, which is passed
         into `model.fit(data, **fit_config)` and
         `evaluate_config` which is passed into `model.evaluate`.
  :param verbose: (bool) Prints output of one model if true.
  :param workers_per_node: (Int) worker number on each node. default: 1.
  :param compile_args_creator: (dict -> dict of loss, optimizer and metrics) Only used when
         the backend="horovod". This function takes in the `config` dict and returns a
         dictionary like {"optimizer": tf.keras.optimizers.SGD(lr), "loss":
         "mean_squared_error", "metrics": ["mean_squared_error"]}
  :param backend: (string) You can choose "horovod", "ray" or "spark" as backend.
   Default: `ray`.
  :param cpu_binding: (bool) Whether to binds threads to specific CPUs. Default: False
  :param log_to_driver: (bool) Whether display executor log on driver in cluster mode.
   Default: True. This option is only for "spark" backend.
  :param model_dir: (str) The directory to save model states. It is required for "spark"
  backend. For cluster mode, it should be a share filesystem path which can be accessed
  by executors.
docstr_tok: ["Create","an","Estimator","for","tensorflow","2.",":","param","model_creator",":","(","dict","-",">","Model",")","This","function","takes","in","the","`","config","`","dict","and","returns","a","compiled","TF","model",".",":","param","config",":","(","dict",")","configuration","passed","to","'model_creator","'",",","'data_creator","'",".","Also","contains","`","fit_config","`",",","which","is","passed","into","`","model.fit","(","data",",","*","*","fit_config",")","`","and","`","evaluate_config","`","which","is","passed","into","`","model.evaluate","`",".",":","param","verbose",":","(","bool",")","Prints","output","of","one","model","if","true",".",":","param","workers_per_node",":","(","Int",")","worker","number","on","each","node",".","default",":","1.",":","param","compile_args_creator",":","(","dict","-",">","dict","of","loss",",","optimizer","and","metrics",")","Only","used","when","the","backend=","''","horovod","''",".","This","function","takes","in","the","`","config","`","dict","and","returns","a","dictionary","like","{","``","optimizer","''",":","tf.keras.optimizers.SGD","(","lr",")",",","``","loss","''",":","``","mean_squared_error","''",",","``","metrics","''",":","[","``","mean_squared_error","''","]","}",":","param","backend",":","(","string",")","You","can","choose","``","horovod","''",",","``","ray","''","or","``","spark","''","as","backend",".","Default",":","`","ray","`",".",":","param","cpu_binding",":","(","bool",")","Whether","to","binds","threads","to","specific","CPUs",".","Default",":","False",":","param","log_to_driver",":","(","bool",")","Whether","display","executor","log","on","driver","in","cluster","mode",".","Default",":","True",".","This","option","is","only","for","``","spark","''","backend",".",":","param","model_dir",":","(","str",")","The","directory","to","save","model","states",".","It","is","required","for","``","spark","''","backend",".","For","cluster","mode",",","it","should","be","a","share","filesystem","path","which","can","be","accessed","by","executors","."]
code: def from_keras(
      *,
      model_creator: Optional[Callable] = None,
      config: Optional[Dict] = None,
      verbose: bool = False,
      workers_per_node: int = 1,
      compile_args_creator: Optional[Callable] = None,
      backend: str = "ray",
      cpu_binding: bool = False,
      log_to_driver: bool = True,
      model_dir: Optional[str] = None,
      **kwargs,
  ) -> Union["TensorFlow2Estimator", "SparkTFEstimator", None]:
      """
      Create an Estimator for tensorflow 2.
  
      :param model_creator: (dict -> Model) This function takes in the `config`
             dict and returns a compiled TF model.
      :param config: (dict) configuration passed to 'model_creator',
             'data_creator'. Also contains `fit_config`, which is passed
             into `model.fit(data, **fit_config)` and
             `evaluate_config` which is passed into `model.evaluate`.
      :param verbose: (bool) Prints output of one model if true.
      :param workers_per_node: (Int) worker number on each node. default: 1.
      :param compile_args_creator: (dict -> dict of loss, optimizer and metrics) Only used when
             the backend="horovod". This function takes in the `config` dict and returns a
             dictionary like {"optimizer": tf.keras.optimizers.SGD(lr), "loss":
             "mean_squared_error", "metrics": ["mean_squared_error"]}
      :param backend: (string) You can choose "horovod", "ray" or "spark" as backend.
       Default: `ray`.
      :param cpu_binding: (bool) Whether to binds threads to specific CPUs. Default: False
      :param log_to_driver: (bool) Whether display executor log on driver in cluster mode.
       Default: True. This option is only for "spark" backend.
      :param model_dir: (str) The directory to save model states. It is required for "spark"
      backend. For cluster mode, it should be a share filesystem path which can be accessed
      by executors.
      """
      if backend in {"ray", "horovod"}:
          from bigdl.orca.learn.tf2.ray_estimator import (
              TensorFlow2Estimator,
          )
  
          return TensorFlow2Estimator(
              model_creator=model_creator,
              config=config,
              verbose=verbose,
              workers_per_node=workers_per_node,
              backend=backend,
              compile_args_creator=compile_args_creator,
              cpu_binding=cpu_binding,
          )
      elif backend == "spark":
          if cpu_binding:
              invalidInputError(
                  False,
                  "cpu_binding should not be True when using spark backend",
              )
          from bigdl.orca.learn.tf2.pyspark_estimator import (
              SparkTFEstimator,
          )
  
          return SparkTFEstimator(
              model_creator=model_creator,
              config=config,
              verbose=verbose,
              compile_args_creator=compile_args_creator,
              workers_per_node=workers_per_node,
              log_to_driver=log_to_driver,
              model_dir=model_dir,
              **kwargs,
          )
      else:
          invalidInputError(
              False,
              "Only horovod, ray and spark backends are supported"
              f" for now, got backend: {backend}",
          )
          return None
  
file_path: BigDL/python/orca/src/bigdl/orca/learn/tf2/estimator.py
imports: import logging
  import numpy
  from bigdl.orca.learn.utils import get_latest_checkpoint
  from bigdl.dllib.utils.log4Error import invalidInputError
  from typing import TYPE_CHECKING, Dict, Union, Callable, Optional, Any
label_desc: Use image node_id 1 for calling the Estimator obj's underlying member method code with example usage: obj.from_keras() and returns: TensorFlow2Estimator, SparkTFEstimator, None