tensorflow 模型量化问答

1. 量化的作用是什么?

   1)减小模型大小  2)加快推理

tensorflow 模型量化问答_第1张图片

https://medium.com/tensorflow/tensorflow-model-optimization-toolkit-post-training-integer-quantization-b4964a1ea9ba

2.量化的原理是什么?

   把浮点表示权值,等比例变换到 int8, 类型表示范围

3.量化有哪些方式?

   

第一种,混合量化--仅量化权重

第二种,全整型量化--权重和激活值都进行量化

第三种,半精度float16量化--仅量化权重

https://zhuanlan.zhihu.com/p/79744430

4.量化时候,tensorflow的具体操作有哪些?

import tensorflow as tf
from tensorflow.keras import backend as K
K.set_learning_phase(0)
converter = tf.lite.TFLiteConverter.from_frozen_graph('xq.pb' \
        , ['input_1'], ['filtered_detections/map/TensorArrayStack/TensorArrayGatherV3',
            'filtered_detections/map/TensorArrayStack_1/TensorArrayGatherV3',
            'filtered_detections/map/TensorArrayStack_2/TensorArrayGatherV3'])
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_quant_model = converter.convert()

 但是遇到了错误:

2020-07-14 22:50:14.123388: F ./tensorflow/lite/toco/toco_tooling.h:38] Check failed: s.ok() Found Identity as non-selected output from Switch, but only Merge supported. Control flow ops like Switch and Merge are not generally supported. We are working on fixing this, please see the Github issue at https://github.com/tensorflow/tensorflow/issues/28485.
Fatal Python error: Aborted

5. tensorflow saved_model 和 frozen graph有什么区别?

https://zhuanlan.zhihu.com/p/60069860

  saved_model:  tf serving时候用到,含有变量文件和pb文件

  frozen graph, *.pb: 包含计算图,但是变量都成为了常量

你可能感兴趣的:(tensorflow 模型量化问答)