parameters: (data, input_binding_info)
return_statement: return data
docstring: Quantize the float input to (u)int8 ready for inputting to model.
docstring_summary: Quantize the float input to (u)int8 ready for inputting to model.
docstring_tokens: Quantize the float input to ( u ) int8 ready for inputting to model .
function: def quantize_input(data, input_binding_info):
      """Quantize the float input to (u)int8 ready for inputting to model."""
      if data.ndim != 2:
          raise RuntimeError("Audio data must have 2 dimensions for quantization")
  
      quant_scale = input_binding_info[1].GetQuantizationScale()
      quant_offset = input_binding_info[1].GetQuantizationOffset()
      data_type = input_binding_info[1].GetDataType()
  
      if data_type == ann.DataType_QAsymmS8:
          data_type = np.int8
      elif data_type == ann.DataType_QAsymmU8:
          data_type = np.uint8
      else:
          raise ValueError("Could not quantize data to required data type")
  
      d_min = np.iinfo(data_type).min
      d_max = np.iinfo(data_type).max
  
      for row in range(data.shape[0]):
          for col in range(data.shape[1]):
              data[row, col] = (data[row, col] / quant_scale) + quant_offset
              data[row, col] = np.clip(data[row, col], d_min, d_max)
      data = data.astype(data_type)
      return data
function_tokens: def quantize_input ( data , input_binding_info ) : if data . ndim != 2 : raise RuntimeError ( "Audio data must have 2 dimensions for quantization" ) quant_scale = input_binding_info [ 1 ] . GetQuantizationScale ( ) quant_offset = input_binding_info [ 1 ] . GetQuantizationOffset ( ) data_type = input_binding_info [ 1 ] . GetDataType ( ) if data_type == ann . DataType_QAsymmS8 : data_type = np . int8 elif data_type == ann . DataType_QAsymmU8 : data_type = np . uint8 else : raise ValueError ( "Could not quantize data to required data type" ) d_min = np . iinfo ( data_type ) . min d_max = np . iinfo ( data_type ) . max for row in range ( data . shape [ 0 ] ) : for col in range ( data . shape [ 1 ] ) : data [ row , col ] = ( data [ row , col ] / quant_scale ) + quant_offset data [ row , col ] = np . clip ( data [ row , col ] , d_min , d_max ) data = data . astype ( data_type ) return data