简体   繁体   English

Python中如何进行定点量化

[英]How to perform fixed-point quantization in Python

I wish to quantize the weights and biases of an existing Neural Network model.我希望量化现有神经网络 model 的权重和偏差。 As per my understanding, the fixed-point representation ensures a fixed bit-width of the weights, biases and activations, with pre-determined fixed number of integer and fraction bits.根据我的理解,定点表示确保了权重、偏差和激活的固定位宽,具有预先确定的固定数量的 integer 和分数位。

Essentially I want to perform Post Training Quantization.本质上我想执行训练后量化。 I checked out this article https://www.tensorflow.org/model_optimization/guide/quantization/post_training .我查看了这篇文章https://www.tensorflow.org/model_optimization/guide/quantization/post_training

However I couldn't find any support for what I want to do ie be able to specify the number of the integer and fraction bits within the fixed-point representation scheme for the weights, biases and activations.但是,我找不到任何对我想要做的事情的支持,即能够在权重、偏差和激活的定点表示方案中指定 integer 和分数位的数量。

I did find the QKeras library which seemed to support this functionality.我确实找到了似乎支持此功能的 QKeras 库。 However, it does not seem to have an built-in quantized sigmoid layer.但是,它似乎没有内置的量化 sigmoid 层。

Any pointers or library/article recommendations that could aid me in doing what I want to do, would be immensely helpful and greatly appreciated.任何可以帮助我做我想做的事情的指针或图书馆/文章推荐,都会非常有帮助并非常感激。

A way to quantize weights and bias using an arbitrary fixed-point fractional (base 2) type is using fxpmath python package.使用任意定点小数(基数 2)类型量化权重和偏差的方法是使用fxpmath python package。

A simple example of what you're trying to do is this jupyter notebook: Fixed-Point Precision Neural Network for MNIST dataset .您尝试做的一个简单示例是这个 jupyter notebook: Fixed-Point Precision Neural Network for MNIST dataset Take into account that it only shows conversion of weights and bias to evaluate inference performance, but not of activations.考虑到它只显示权重和偏差的转换来评估推理性能,而不是激活。 This can also implemented manually using same package (it supports Numpy).这也可以使用相同的 package 手动实现(它支持 Numpy)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM