docstr: Creates model and load weights from state
code: def _get_model_from_state(self, state, sample_input=None):
      """Creates model and load weights from state"""
      import tensorflow as tf
  
      # keep the same behavior as `set_state` in `load` do
      if self.model_creator is not None:
          model = self.model_creator(self.config)
      else:
          file_name = os.path.basename(self.load_params["filepath"])
          temp_dir = tempfile.mkdtemp()
          temp_path = os.path.join(temp_dir, file_name)
  
          if is_file(self.load_params["filepath"]):
              get_remote_file_to_local(
                  self.load_params["filepath"], temp_path
              )
          else:
              if os.path.exists(temp_path):
                  os.makedirs(temp_path)
              get_remote_dir_to_local(
                  self.load_params["filepath"], temp_path
              )
          try:
              self.load_params["filepath"] = temp_path
              model = tf.keras.models.load_model(**self.load_params)
          finally:
              shutil.rmtree(temp_dir)
  
      if sample_input:
          model(sample_input)
      try:
          model.set_weights(state["weights"])
      except Exception:
          log4Error.invalidInputError(
              False,
              "Failed to set model weights, please provide real tensor "
              "data (of the correct dtype) as sample_input in the "
              "get_model method.",
          )
  
      return model
  
imports: import os
  import types
  from bigdl.orca.common import SafePickle
  import shutil
  import tempfile
  import logging
  import ray
  from bigdl.dllib.utils import log4Error
  from bigdl.dllib.utils.file_utils import is_local_path
  from bigdl.orca.data.file import enable_multi_fs_save, enable_multi_fs_load
  from bigdl.orca.data.ray_xshards import RayXShards
  from bigdl.orca.learn.dl_cluster import RayDLCluster
  from bigdl.orca.learn.tf2.tf_runner import TFRunner
  from bigdl.orca.learn.ray_estimator import Estimator
  from bigdl.orca.learn.utils import maybe_dataframe_to_xshards, dataframe_to_xshards, convert_predict_xshards_to_dataframe, update_predict_xshards, process_xshards_of_pandas_dataframe, make_data_creator, add_predict_to_pd_xshards
  from bigdl.orca.data.file import get_remote_file_to_local, get_remote_dir_to_local, is_file
  from bigdl.orca.data.utils import process_spark_xshards
  from bigdl.dllib.utils.log4Error import invalidInputError
  from bigdl.orca.ray import OrcaRayContext
  from typing import TYPE_CHECKING, Dict, List, Callable, Union, Optional
label_desc: Use image node_id 17 for calling the TensorFlow2Estimator obj's underlying member method code with example usage: obj._get_model_from_state(state, sample_input) and returns: model