docstr: Load a model from local.
  
  :param path: Path to model to be loaded. Path should be a directory.
  :param model: Required FP32 model to load pytorch model, it is needed if:
         1. you accelerate the model with accelerator=None by
         InferenceOptimizer.trace()/InferenceOptimizer.quantize().
         2. you accelerate the model with InferenceOptimizer.optimize() and
         get_model()/get_best_model(), and the best method or the method you
         specify don't contain accelerator 'onnxruntime'/'openvino'/'jit'.
         If you are not sure what optimization method is used, we recommend that
         you always pass in the original model for this case.
         3. you want to the loaded model contains the attributes of original model.
  :param device: A string represents the device of the inference. Default to None.
         Only valid for openvino model, otherwise will be ignored.
  :param custom_objects: Same to `custom_objects` parameter of `tf.keras.models.load_model`,
         only may be required when loading bf16 model.
  :return: Model with different acceleration(None/OpenVINO/ONNX Runtime) or
           precision(FP32/FP16/BF16/INT8).
docstr_tok: ["Load","a","model","from","local",".",":","param","path",":","Path","to","model","to","be","loaded",".","Path","should","be","a","directory",".",":","param","model",":","Required","FP32","model","to","load","pytorch","model",",","it","is","needed","if",":","1.","you","accelerate","the","model","with","accelerator=None","by","InferenceOptimizer.trace","(",")","\/InferenceOptimizer.quantize","(",")",".","2.","you","accelerate","the","model","with","InferenceOptimizer.optimize","(",")","and","get_model","(",")","\/get_best_model","(",")",",","and","the","best","method","or","the","method","you","specify","do","n't","contain","accelerator","'onnxruntime'\/'openvino'\/'jit","'",".","If","you","are","not","sure","what","optimization","method","is","used",",","we","recommend","that","you","always","pass","in","the","original","model","for","this","case",".","3.","you","want","to","the","loaded","model","contains","the","attributes","of","original","model",".",":","param","device",":","A","string","represents","the","device","of","the","inference",".","Default","to","None",".","Only","valid","for","openvino","model",",","otherwise","will","be","ignored",".",":","param","custom_objects",":","Same","to","`","custom_objects","`","parameter","of","`","tf.keras.models.load_model","`",",","only","may","be","required","when","loading","bf16","model",".",":","return",":","Model","with","different","acceleration","(","None\/OpenVINO\/ONNX","Runtime",")","or","precision","(","FP32\/FP16\/BF16\/INT8",")","."]
code: def load(
      path,
      model: Optional[Model] = None,
      device=None,
      custom_objects=None,
  ):
      """
      Load a model from local.
  
      :param path: Path to model to be loaded. Path should be a directory.
      :param model: Required FP32 model to load pytorch model, it is needed if:
             1. you accelerate the model with accelerator=None by
             InferenceOptimizer.trace()/InferenceOptimizer.quantize().
             2. you accelerate the model with InferenceOptimizer.optimize() and
             get_model()/get_best_model(), and the best method or the method you
             specify don't contain accelerator 'onnxruntime'/'openvino'/'jit'.
             If you are not sure what optimization method is used, we recommend that
             you always pass in the original model for this case.
             3. you want to the loaded model contains the attributes of original model.
      :param device: A string represents the device of the inference. Default to None.
             Only valid for openvino model, otherwise will be ignored.
      :param custom_objects: Same to `custom_objects` parameter of `tf.keras.models.load_model`,
             only may be required when loading bf16 model.
      :return: Model with different acceleration(None/OpenVINO/ONNX Runtime) or
               precision(FP32/FP16/BF16/INT8).
      """
      import yaml
  
      path = Path(path)
      invalidInputError(path.exists(), "{} doesn't exist.".format(path))
      meta_path = path / "nano_model_meta.yml"
      invalidInputError(
          meta_path.exists(),
          "File {} is required to load model.".format(str(meta_path)),
      )
      with open(meta_path, "r") as f:
          metadata = yaml.safe_load(f)
      model_type = metadata.get("ModelType", None)
      if model_type == "KerasOpenVINOModel":
          result = load_openvino_model(
              path, framework="tensorflow", device=device
          )
          return patch_attrs(result, model)
      if model_type == "KerasONNXRuntimeModel":
          result = load_onnxruntime_model(path, framework="tensorflow")
          return patch_attrs(result, model)
      if model_type == "KerasQuantizedModel":
          result = load_inc_model(path, model, framework="tensorflow")
          return patch_attrs(result, model)
      # Arriving here means we are loading a bf16 model or normal keras model
      checkpoint_path = metadata.get("checkpoint", None)
      invalidInputError(
          checkpoint_path is not None,
          "Key 'checkpoint' must be specified.",
      )
      checkpoint_path = path / metadata["checkpoint"]
      model = keras.models.load_model(
          checkpoint_path, custom_objects=custom_objects
      )
      return model
  
imports: import os
  import subprocess
  import tempfile
  import cloudpickle
  import copy
  import time
  import operator
  from pathlib import Path
  import numpy
  import traceback
  import inspect
  import sigfig
  import tensorflow
  import keras
  from typing import Dict, Optional, List, Union, Callable
  from bigdl.nano.utils.common import BaseInferenceOptimizer, available_acceleration_combination, AccelerationOption, latency_calculate_helper, format_optimize_result
  from bigdl.nano.utils.common import invalidInputError
  from bigdl.nano.utils.tf import _ModuleWrapper
  from bigdl.nano.utils.tf import patch_compiled_and_attrs, patch_attrs
  from tensorflow.keras import Model
  from tensorflow.data import Dataset
  from tensorflow.keras.metrics import Metric
  from bigdl.nano.deps.neural_compressor.inc_api import quantize
  from bigdl.nano.deps.openvino.openvino_api import KerasOpenVINOModel
  from bigdl.nano.deps.onnxruntime.onnxruntime_api import KerasONNXRuntimeModel
  from bigdl.nano.deps.openvino.openvino_api import load_openvino_model
  from bigdl.nano.deps.onnxruntime.onnxruntime_api import load_onnxruntime_model
  from bigdl.nano.deps.neural_compressor.inc_api import load_inc_model
  from bigdl.nano.tf.keras.amp import BF16Model, load_bf16_model
  from bigdl.nano.utils.common import compare_version
  from bigdl.nano.utils.tf import try_fake_inference
label_desc: Use image node_id 5 for calling the InferenceOptimizer obj's underlying member method code with example usage: obj.load(path, model, device, custom_objects) and returns: model, patch_attrs, patch_attrs, patch_attrs