code: def run(self):
      # Forward on represent dataset to collect max and min value of each buffer
      alpha = 0.1
      for input_data in tqdm.tqdm(self.dataset, desc="Calibrating..."):
          input_data = np.array(input_data).astype(np.float32)
          input_data = np.expand_dims(input_data, 0)
          input_shape = self.input_details[0]["shape"]
          if not (input_shape == input_data.shape).all():
              input_data = np.transpose(input_data, (0, 2, 3, 1))
          self.interpreter.set_tensor(
              self.input_details[0]["index"], input_data
          )
          self.interpreter.invoke()
  
          for output_detail in self.output_details:
              output_tensor = self.interpreter.get_tensor(
                  output_detail["index"]
              )
              if not self.quantization_param[output_detail["name"]].get(
                  "max"
              ):
                  self.quantization_param[output_detail["name"]][
                      "max"
                  ] = output_tensor.max()
              # Using exponential moving averages to smooth max value and min value
              # Reference: https://arxiv.org/pdf/1712.05877.pdf
              if (
                  output_tensor.max()
                  > self.quantization_param[output_detail["name"]][
                      "max"
                  ]
              ):
                  self.quantization_param[output_detail["name"]][
                      "max"
                  ] = (
                      alpha * output_tensor.max()
                      + (1 - alpha)
                      * self.quantization_param[output_detail["name"]][
                          "max"
                      ]
                  )
  
              if not self.quantization_param[output_detail["name"]].get(
                  "min"
              ):
                  self.quantization_param[output_detail["name"]][
                      "min"
                  ] = output_tensor.min()
              if (
                  output_tensor.min()
                  < self.quantization_param[output_detail["name"]][
                      "min"
                  ]
              ):
                  self.quantization_param[output_detail["name"]][
                      "min"
                  ] = (
                      alpha * output_tensor.min()
                      + (1 - alpha)
                      * self.quantization_param[output_detail["name"]][
                          "min"
                      ]
                  )
  
      for name in self.quantization_param:
          max_v = self.quantization_param[name]["max"]
          min_v = self.quantization_param[name]["min"]
          scale = (max_v - min_v) / 255
          zero_point = np.round(127 - max_v / scale)
          self.quantization_param[name]["max"] = np.around(
              max_v, 6
          ).tolist()
          self.quantization_param[name]["min"] = np.around(
              min_v, 6
          ).tolist()
          self.quantization_param[name]["scale"] = np.around(
              scale, 6
          ).tolist()
          self.quantization_param[name][
              "zero_point"
          ] = zero_point.tolist()
      return self.quantization_param
  
imports: import numpy
  import tensorflow
  import tqdm
label_desc: Use image node_id 2 for calling the Calibrator obj's underlying member method code with example usage: obj.run() and returns: self