python - 如何量化一个训练感知量化模型?
问题描述
我有一个 Keras 模型,我将其应用在 Training Aware Quantization 上,所以我有一个训练感知量化模型。我想要一个完全量化的 int8 模型(我有一个只接受整数运算的硬件)。
所以我在这个量化模型上应用了训练后量化。
我使用这部分代码来做到这一点:
converter = tf.lite.TFLiteConverter.from_keras_model(TAQ_model)
converter.optimizations = [tf.lite.Optimize.DEFAULT]
tflite_quant_model = converter.convert()
但我在 float32 中得到了输入和输出:
== Input details ==
name: dense_input
shape: [ 1 36]
type: <class 'numpy.float32'>
== Output details ==
name: Identity
shape: [ 1 108]
type: <class 'numpy.float32'>
为了解决这个问题,我添加了一些选项并使用了如下的代表数据集:
converter.representative_dataset = representative_dataset
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS_INT8]
converter.inference_input_type = tf.int8
converter.inference_output_type = tf.int8
但我得到了这个错误:
Traceback (most recent call last):
File "D:/PhD_Thessaloniki/Codes/5G_Model/retrained_quantized_pb/PTQ.py", line 123, in <module>
tflite_quant_model = converter.convert()
File "C:\ProgramData\Anaconda3\envs\tensorflow_env\lib\site-packages\tensorflow\lite\python\lite.py", line 830, in convert
return super(TFLiteKerasModelConverterV2,
File "C:\ProgramData\Anaconda3\envs\tensorflow_env\lib\site-packages\tensorflow\lite\python\lite.py", line 638, in convert
result = self._calibrate_quantize_model(result, **flags)
File "C:\ProgramData\Anaconda3\envs\tensorflow_env\lib\site-packages\tensorflow\lite\python\lite.py", line 450, in _calibrate_quantize_model
return calibrate_quantize.calibrate_and_quantize(
File "C:\ProgramData\Anaconda3\envs\tensorflow_env\lib\site-packages\tensorflow\lite\python\optimize\calibrator.py", line 95, in calibrate_and_quantize
return self._calibrator.QuantizeModel(
RuntimeError: Quantization not yet supported for op:
如何使用训练感知量化完全量化模型?
如果每个人都可以帮助我,我将不胜感激。
解决方案
推荐阅读
- vue.js - Vuex Vue如何打印子组件而不在父组件上渲染
- jquery - 为什么单击一个标签标签,选择了两个标签标签?
- python - 如何知道 virtualenv 是否需要同步以避免为部署在 Jenkins 上的每个作业运行 pipenv 同步
- rest - Codeigniter Rest Api 使用参数 ID 删除
- uwp - 在 UWP 中以编程方式设置 Telerik RadAutoCompleteBox 的 SelectedItem 的推荐方法是什么
- python - Carla 模拟器示例效果不佳
- flutter - 如何使用带有颤振的firebase使用电话号码登录?
- git - 在分支上压缩多个提交
- azure - 如何从 Angular 7 调用图形 AD api
- python - 如何将 CSV 文件作为参数传递给 python 文件