tensorflow - Tensorflow Lite 和代表性数据集
问题描述
有人看到我的代码有什么问题吗?我真的不明白异常的原因。
def repr_data_gen():
for e, _ in train_gen_base.take(8):
for i in range(e.shape[0]):
img = e[i, :]
yield [img.numpy()]
pt_model.trainable = False
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
converter.representative_dataset = repr_data_gen,
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.int8 # or tf.uint8
converter.inference_output_type = tf.int8 # or tf.uint8
tflite_quant_model = converter.convert()
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~/Dev/sandbox/intception_v4/convert.py in
153 converter.inference_input_type = tf.int8 # or tf.uint8
154 converter.inference_output_type = tf.int8 # or tf.uint8
---> 155 tflite_quant_model = converter.convert()
156
~/.conda/envs/tflitemicro_v2/lib/python3.8/site-packages/tensorflow/lite/python/lite.py in convert(self)
1055 graph=frozen_func.graph)
1056
-> 1057 result = super(TFLiteKerasModelConverterV2,
1058 self).convert(graph_def, input_tensors, output_tensors)
1059 self._increase_conversion_success_metric(result)
~/.conda/envs/tflitemicro_v2/lib/python3.8/site-packages/tensorflow/lite/python/lite.py in convert(self, graph_def, input_tensors, output_tensors)
793
794 if calibrate_and_quantize:
--> 795 result = self._calibrate_quantize_model(result, **flags)
796
797 flags_modify_model_io_type = quant_mode.flags_modify_model_io_type(
~/.conda/envs/tflitemicro_v2/lib/python3.8/site-packages/tensorflow/lite/python/lite.py in _calibrate_quantize_model(self, result, inference_input_type, inference_output_type, activations_type, allow_float)
519 custom_op_registerers_by_func)
520 if self._experimental_calibrate_only or self.experimental_new_quantizer:
--> 521 calibrated = calibrate_quantize.calibrate(
522 self.representative_dataset.input_gen)
523
~/.conda/envs/tflitemicro_v2/lib/python3.8/site-packages/tensorflow/lite/python/optimize/calibrator.py in calibrate(self, dataset_gen)
167 """
168 initialized = False
--> 169 for sample in dataset_gen():
170 if not initialized:
171 initialized = True
TypeError: 'tuple' object is not callable
我开始调试 tensorflow lite 包,但我仍然不知道问题出在哪里。train_gen_base 是一个 tensorflow.dataset 包含形状的张量 (batchsize, img_dim1, img_dim2, 3)
解决方案
推荐阅读
- swift - 获取 UserDefault 字典值时启用 App SandBox 会导致崩溃
- ios - Crashlytics 中没有出现最新版本(以前是“HTTP 错误 403...”)
- linux - Python 3.7 altinstall 和安装 PIP:PyCharm:unix 系统
- mysql - 无法在 Ubuntu 16.04 上安装 MySQL 5.7
- python - Python,无法使用带有 anytree 包的 graphviz 绘制树
- c# - C# 实体框架和存储过程
- excel - 在日期范围内计算 Excel 中的单元格,但仅当大于其上方的单元格时
- css - 如何在 inline-block 之后删除这个空间?
- vivado - 将 axi timer 连接到 vivado 中的 microBlaze
- dictionary - 在 Swift 4 中使用 JSONEncoder 将 [String: Encodable] 字典编码为 JSON