Я пытаюсь выполнить квантование после обучения, которое представляет собой метод преобразования, который может уменьшить размер модели, а также улучшить задержку ЦП и аппаратного ускорителя с небольшим ухудшением точности модели. Я пытаюсь квантовать уже обученную модель TensorFlow с плавающей запятой, когда вы конвертируете ее в формат TensorFlow Lite с помощью конвертера TensorFlow Lite.
num_calibration_steps = 3
def representative_dataset_gen():
for _ in range(num_calibration_steps):
# Get sample input data as a numpy array in a method of your choosing.
a= train_dataset.from_tensor_slices([1,2,3])
b = np.array(a))
return b
converter = tf.lite.TFLiteConverter.from_saved_model('TensorFlow/save_model')
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = representative_dataset_gen
tflite_quant_model = converter.convert()
open("FullINT_Quantized_model.tflite", "wb").write(tflite_quant_model)
Error
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-124-28f61e00341a> in <module>
5 #converter.inference_input_type = tf.int8 # or tf.uint8
6 #converter.inference_output_type = tf.int8 # or tf.uint8
----> 7 tflite_quant_model = converter.convert()
8 open("FullINT_Quantized_model.tflite", "wb").write(tflite_quant_model)
~\AppData\Roaming\Python\Python37\site-packages\tensorflow\lite\python\lite.py in convert(self)
520 if self._is_calibration_quantize():
521 result = self._calibrate_quantize_model(
--> 522 result, constants.FLOAT, constants.FLOAT)
523
524 return result
~\AppData\Roaming\Python\Python37\site-packages\tensorflow\lite\python\lite.py in _calibrate_quantize_model(self, result, inference_input_type, inference_output_type)
265 return calibrate_quantize.calibrate_and_quantize(
266 self.representative_dataset.input_gen, inference_input_type,
--> 267 inference_output_type, allow_float, self._experimental_new_quantizer)
268
269 def _is_unknown_shapes_allowed(self):
~\AppData\Roaming\Python\Python37\site-packages\tensorflow\lite\python\optimize\calibrator.py in calibrate_and_quantize(self, dataset_gen, input_type, output_type, allow_float, enable_mlir_quantizer)
74 """
75 self._calibrator.Prepare()
---> 76 for calibration_sample in dataset_gen():
77 self._calibrator.FeedTensor(calibration_sample)
78 return self._calibrator.QuantizeModel(
TypeError: iteration over a 0-d array
Я пытался использовать np.array (list (b)), но не повезло
Пожалуйста, помогите. Заранее спасибо !!