class_docstr: A mixedin class for nano keras Sequential and Model, adding more functions for Inference.
docstr: Post-training quantization on a keras model.
  
  :param x: Input data which is used for training. It could be:
  
            | 1. a Numpy array (or array-like), or a list of arrays (in case the model
            | has multiple inputs).
            |
            | 2. a TensorFlow tensor, or a list of tensors (in case the model has
            | multiple inputs).
            |
            | 3. an unbatched tf.data.Dataset. Should return a tuple of (inputs, targets).
  
            X will be used as calibration dataset for Post-Training Static Quantization (PTQ),
            as well as be used for generating input_sample to calculate latency.
            To avoid data leak during calibration, please use training dataset.
  :param y: Target data. Like the input data x, it could be either Numpy array(s) or
            TensorFlow tensor(s). Its length should be consistent with x.
            If x is a dataset, y will be ignored (since targets will be obtained from x).
  :param precision:       Global precision of quantized model,
                          supported type: 'int8', defaults to 'int8'.
  :param accelerator:     Use accelerator 'None', 'onnxruntime', 'openvino', defaults to None.
                          None means staying in tensorflow.
  :param input_spec: (optional) A (tuple or list of) ``tf.TensorSpec``
                     defining the shape/dtype of the input. If ``accelerator='onnxruntime'``,
                     ``input_spec`` is required. If ``accelerator='openvino'``, or
                     ``accelerator=None`` and ``precision='int8'``, ``input_spec``
                     is required when you have a custom Keras model.
  :param metric:          A tensorflow.keras.metrics.Metric object for evaluation.
  :param accuracy_criterion:  Tolerable accuracy drop.
                              accuracy_criterion = {'relative': 0.1, 'higher_is_better': True}
                              allows relative accuracy loss: 1%. accuracy_criterion =
                              {'absolute': 0.99, 'higher_is_better':False} means accuracy
                              must be smaller than 0.99.
  :param approach:        'static' or 'dynamic'.
                          'static': post_training_static_quant,
                          'dynamic': post_training_dynamic_quant.
                          Default: 'static'. Only 'static' approach is supported now.
  :param method:      Method to do quantization. When accelerator=None, supported methods:
          None. When accelerator='onnxruntime', supported methods: 'qlinear', 'integer',
          defaults to 'qlinear'. Suggest 'qlinear' for lower accuracy drop if using
          static quantization.
          More details in https://onnxruntime.ai/docs/performance/quantization.html.
          This argument doesn't take effect for OpenVINO, don't change it for OpenVINO.
  :param conf:        A path to conf yaml file for quantization.
                          Default: None, using default config.
  :param tuning_strategy:    'bayesian', 'basic', 'mse', 'sigopt'. Default: 'bayesian'.
  :param timeout:     Tuning timeout (seconds). Default: None,  which means early stop.
                      Combine with max_trials field to decide when to exit.
  :param max_trials:  Max tune times. Default: None, which means no tuning.
                      Combine with timeout field to decide when to exit.
                      "timeout=0, max_trials=1" means it will try quantization only once and
                      return satisfying best model.
  :param batch:       Batch size of dataloader for calib_dataset. Defaults to None, if the
                      dataset is not a BatchDataset, batchsize equals to 1. Otherwise,
                      batchsize complies with the dataset._batch_size.
  :param thread_num:  (optional) a int represents how many threads(cores) is needed for
                      inference, only valid for accelerator='onnxruntime'
                      or accelerator='openvino'.
  :param inputs:      A list of input names.
                      Default: None, automatically get names from graph.
  :param outputs:     A list of output names.
                      Default: None, automatically get names from graph.
  :param sample_size: (optional) a int represents how many samples will be used for
                      Post-training Optimization Tools (POT) from OpenVINO toolkit,
                      only valid for accelerator='openvino'. Default to 100.
                      The larger the value, the more accurate the conversion,
                      the lower the performance degradation, but the longer the time.
  :param onnxruntime_session_options: The session option for onnxruntime, only valid when
                                      accelerator='onnxruntime', otherwise will be ignored.
  :param openvino_config: The config to be inputted in core.compile_model. Only valid when
                          accelerator='openvino', otherwise will be ignored.
  :param logging: whether to log detailed information of model conversion, only valid when
                  accelerator='openvino', otherwise will be ignored. Default: ``True``.
  :return:            A TensorflowBaseModel for INC. If there is no model found, return None.
  
  .. warning::
     This function will be deprecated in future release.
  
     Please use ``bigdl.nano.tf.keras.InferenceOptimizer.quantize`` instead.
docstr_tok: ["Post-training","quantization","on","a","keras","model",".",":","param","x",":","Input","data","which","is","used","for","training",".","It","could","be",":","|","1.","a","Numpy","array","(","or","array-like",")",",","or","a","list","of","arrays","(","in","case","the","model","|","has","multiple","inputs",")",".","|","|","2.","a","TensorFlow","tensor",",","or","a","list","of","tensors","(","in","case","the","model","has","|","multiple","inputs",")",".","|","|","3.","an","unbatched","tf.data.Dataset",".","Should","return","a","tuple","of","(","inputs",",","targets",")",".","X","will","be","used","as","calibration","dataset","for","Post-Training","Static","Quantization","(","PTQ",")",",","as","well","as","be","used","for","generating","input_sample","to","calculate","latency",".","To","avoid","data","leak","during","calibration",",","please","use","training","dataset",".",":","param","y",":","Target","data",".","Like","the","input","data","x",",","it","could","be","either","Numpy","array","(","s",")","or","TensorFlow","tensor","(","s",")",".","Its","length","should","be","consistent","with","x",".","If","x","is","a","dataset",",","y","will","be","ignored","(","since","targets","will","be","obtained","from","x",")",".",":","param","precision",":","Global","precision","of","quantized","model",",","supported","type",":","'int8","'",",","defaults","to","'int8","'",".",":","param","accelerator",":","Use","accelerator","'None","'",",","'onnxruntime","'",",","'openvino","'",",","defaults","to","None",".","None","means","staying","in","tensorflow",".",":","param","input_spec",":","(","optional",")","A","(","tuple","or","list","of",")","``","tf.TensorSpec","``","defining","the","shape\/dtype","of","the","input",".","If","``","accelerator='onnxruntime","'","``",",","``","input_spec","``","is","required",".","If","``","accelerator='openvino","'","``",",","or","``","accelerator=None","``","and","``","precision='int8","'","``",",","``","input_spec","``","is","required","when","you","have","a","custom","Keras","model",".",":","param","metric",":","A","tensorflow.keras.metrics.Metric","object","for","evaluation",".",":","param","accuracy_criterion",":","Tolerable","accuracy","drop",".","accuracy_criterion","=","{","'relative","'",":","0.1",",","'higher_is_better","'",":","True","}","allows","relative","accuracy","loss",":","1","%",".","accuracy_criterion","=","{","'absolute","'",":","0.99",",","'higher_is_better","'",":","False","}","means","accuracy","must","be","smaller","than","0.99.",":","param","approach",":","'static","'","or","'dynamic","'",".","'static","'",":","post_training_static_quant",",","'dynamic","'",":","post_training_dynamic_quant",".","Default",":","'static","'",".","Only","'static","'","approach","is","supported","now",".",":","param","method",":","Method","to","do","quantization",".","When","accelerator=None",",","supported","methods",":","None",".","When","accelerator='onnxruntime","'",",","supported","methods",":","'qlinear","'",",","'integer","'",",","defaults","to","'qlinear","'",".","Suggest","'qlinear","'","for","lower","accuracy","drop","if","using","static","quantization",".","More","details","in","https",":","\/\/onnxruntime.ai\/docs\/performance\/quantization.html",".","This","argument","does","n't","take","effect","for","OpenVINO",",","do","n't","change","it","for","OpenVINO",".",":","param","conf",":","A","path","to","conf","yaml","file","for","quantization",".","Default",":","None",",","using","default","config",".",":","param","tuning_strategy",":","'bayesian","'",",","'basic","'",",","'mse","'",",","'sigopt","'",".","Default",":","'bayesian","'",".",":","param","timeout",":","Tuning","timeout","(","seconds",")",".","Default",":","None",",","which","means","early","stop",".","Combine","with","max_trials","field","to","decide","when","to","exit",".",":","param","max_trials",":","Max","tune","times",".","Default",":","None",",","which","means","no","tuning",".","Combine","with","timeout","field","to","decide","when","to","exit",".","``","timeout=0",",","max_trials=1","''","means","it","will","try","quantization","only","once","and","return","satisfying","best","model",".",":","param","batch",":","Batch","size","of","dataloader","for","calib_dataset",".","Defaults","to","None",",","if","the","dataset","is","not","a","BatchDataset",",","batchsize","equals","to","1",".","Otherwise",",","batchsize","complies","with","the","dataset._batch_size",".",":","param","thread_num",":","(","optional",")","a","int","represents","how","many","threads","(","cores",")","is","needed","for","inference",",","only","valid","for","accelerator='onnxruntime'","or","accelerator='openvino","'",".",":","param","inputs",":","A","list","of","input","names",".","Default",":","None",",","automatically","get","names","from","graph",".",":","param","outputs",":","A","list","of","output","names",".","Default",":","None",",","automatically","get","names","from","graph",".",":","param","sample_size",":","(","optional",")","a","int","represents","how","many","samples","will","be","used","for","Post-training","Optimization","Tools","(","POT",")","from","OpenVINO","toolkit",",","only","valid","for","accelerator='openvino","'",".","Default","to","100",".","The","larger","the","value",",","the","more","accurate","the","conversion",",","the","lower","the","performance","degradation",",","but","the","longer","the","time",".",":","param","onnxruntime_session_options",":","The","session","option","for","onnxruntime",",","only","valid","when","accelerator='onnxruntime","'",",","otherwise","will","be","ignored",".",":","param","openvino_config",":","The","config","to","be","inputted","in","core.compile_model",".","Only","valid","when","accelerator='openvino","'",",","otherwise","will","be","ignored",".",":","param","logging",":","whether","to","log","detailed","information","of","model","conversion",",","only","valid","when","accelerator='openvino","'",",","otherwise","will","be","ignored",".","Default",":","``","True","``",".",":","return",":","A","TensorflowBaseModel","for","INC",".","If","there","is","no","model","found",",","return","None",".","..","warning",":",":","This","function","will","be","deprecated","in","future","release",".","Please","use","``","bigdl.nano.tf.keras.InferenceOptimizer.quantize","``","instead","."]
code: def quantize(
      self,
      x: Union[tf.Tensor, np.ndarray, tf.data.Dataset],
      y: Union[tf.Tensor, np.ndarray] = None,
      precision: str = "int8",
      accelerator: Optional[str] = None,
      input_spec=None,
      metric: Optional[Metric] = None,
      accuracy_criterion: Optional[dict] = None,
      approach: str = "static",
      method: Optional[str] = None,
      conf: Optional[str] = None,
      tuning_strategy: Optional[str] = None,
      timeout: Optional[int] = None,
      max_trials: Optional[int] = None,
      batch: Optional[int] = None,
      thread_num: Optional[int] = None,
      inputs: List[str] = None,
      outputs: List[str] = None,
      sample_size: int = 100,
      onnxruntime_session_options=None,
      openvino_config=None,
      logging: bool = True,
  ):
      """
      Post-training quantization on a keras model.
  
      :param x: Input data which is used for training. It could be:
  
                | 1. a Numpy array (or array-like), or a list of arrays (in case the model
                | has multiple inputs).
                |
                | 2. a TensorFlow tensor, or a list of tensors (in case the model has
                | multiple inputs).
                |
                | 3. an unbatched tf.data.Dataset. Should return a tuple of (inputs, targets).
  
                X will be used as calibration dataset for Post-Training Static Quantization (PTQ),
                as well as be used for generating input_sample to calculate latency.
                To avoid data leak during calibration, please use training dataset.
      :param y: Target data. Like the input data x, it could be either Numpy array(s) or
                TensorFlow tensor(s). Its length should be consistent with x.
                If x is a dataset, y will be ignored (since targets will be obtained from x).
      :param precision:       Global precision of quantized model,
                              supported type: 'int8', defaults to 'int8'.
      :param accelerator:     Use accelerator 'None', 'onnxruntime', 'openvino', defaults to None.
                              None means staying in tensorflow.
      :param input_spec: (optional) A (tuple or list of) ``tf.TensorSpec``
                         defining the shape/dtype of the input. If ``accelerator='onnxruntime'``,
                         ``input_spec`` is required. If ``accelerator='openvino'``, or
                         ``accelerator=None`` and ``precision='int8'``, ``input_spec``
                         is required when you have a custom Keras model.
      :param metric:          A tensorflow.keras.metrics.Metric object for evaluation.
      :param accuracy_criterion:  Tolerable accuracy drop.
                                  accuracy_criterion = {'relative': 0.1, 'higher_is_better': True}
                                  allows relative accuracy loss: 1%. accuracy_criterion =
                                  {'absolute': 0.99, 'higher_is_better':False} means accuracy
                                  must be smaller than 0.99.
      :param approach:        'static' or 'dynamic'.
                              'static': post_training_static_quant,
                              'dynamic': post_training_dynamic_quant.
                              Default: 'static'. Only 'static' approach is supported now.
      :param method:      Method to do quantization. When accelerator=None, supported methods:
              None. When accelerator='onnxruntime', supported methods: 'qlinear', 'integer',
              defaults to 'qlinear'. Suggest 'qlinear' for lower accuracy drop if using
              static quantization.
              More details in https://onnxruntime.ai/docs/performance/quantization.html.
              This argument doesn't take effect for OpenVINO, don't change it for OpenVINO.
      :param conf:        A path to conf yaml file for quantization.
                              Default: None, using default config.
      :param tuning_strategy:    'bayesian', 'basic', 'mse', 'sigopt'. Default: 'bayesian'.
      :param timeout:     Tuning timeout (seconds). Default: None,  which means early stop.
                          Combine with max_trials field to decide when to exit.
      :param max_trials:  Max tune times. Default: None, which means no tuning.
                          Combine with timeout field to decide when to exit.
                          "timeout=0, max_trials=1" means it will try quantization only once and
                          return satisfying best model.
      :param batch:       Batch size of dataloader for calib_dataset. Defaults to None, if the
                          dataset is not a BatchDataset, batchsize equals to 1. Otherwise,
                          batchsize complies with the dataset._batch_size.
      :param thread_num:  (optional) a int represents how many threads(cores) is needed for
                          inference, only valid for accelerator='onnxruntime'
                          or accelerator='openvino'.
      :param inputs:      A list of input names.
                          Default: None, automatically get names from graph.
      :param outputs:     A list of output names.
                          Default: None, automatically get names from graph.
      :param sample_size: (optional) a int represents how many samples will be used for
                          Post-training Optimization Tools (POT) from OpenVINO toolkit,
                          only valid for accelerator='openvino'. Default to 100.
                          The larger the value, the more accurate the conversion,
                          the lower the performance degradation, but the longer the time.
      :param onnxruntime_session_options: The session option for onnxruntime, only valid when
                                          accelerator='onnxruntime', otherwise will be ignored.
      :param openvino_config: The config to be inputted in core.compile_model. Only valid when
                              accelerator='openvino', otherwise will be ignored.
      :param logging: whether to log detailed information of model conversion, only valid when
                      accelerator='openvino', otherwise will be ignored. Default: ``True``.
      :return:            A TensorflowBaseModel for INC. If there is no model found, return None.
  
      .. warning::
         This function will be deprecated in future release.
  
         Please use ``bigdl.nano.tf.keras.InferenceOptimizer.quantize`` instead.
      """
      from bigdl.nano.tf.keras import InferenceOptimizer
  
      return InferenceOptimizer.quantize(
          model=self,
          x=x,
          y=y,
          precision=precision,
          accelerator=accelerator,
          input_spec=input_spec,
          metric=metric,
          accuracy_criterion=accuracy_criterion,
          approach=approach,
          method=method,
          conf=conf,
          tuning_strategy=tuning_strategy,
          timeout=timeout,
          max_trials=max_trials,
          batch=batch,
          thread_num=thread_num,
          inputs=inputs,
          outputs=outputs,
          sample_size=sample_size,
          onnxruntime_session_options=onnxruntime_session_options,
          openvino_config=openvino_config,
          logging=logging,
      )
  
file_path: BigDL/python/nano/src/bigdl/nano/tf/keras/inference_utils.py
imports: from typing import Optional, List, Union
  import numpy
  import tensorflow
  from tensorflow.keras.metrics import Metric
  from bigdl.nano.utils.common import deprecated
label_desc: Use image node_id 1 for calling the InferenceUtils obj's underlying member method code with example usage: obj.quantize(x, y, precision, accelerator, input_spec, metric, accuracy_criterion, approach, method, conf, tuning_strategy, timeout, max_trials, batch, thread_num, inputs, outputs, sample_size, onnxruntime_session_options, openvino_config, logging) and returns: InferenceOptimizer