Is it possible to quantize a Keras NN model in this way or am I missing something basic?A possible solution that crossed my mind could be using low level TF API instead of Keras (needing to do quite a bit of work to construct the model), or maybe trying to extract some of the lower level methods from the Keras models.推荐答案如其他答案所述,TensorFlow Lite可以帮助您进行网络量化.As mentioned in other answers, TensorFlow Lite can help you with network quantization. TensorFlow Lite提供了多个级别的量化支持. TensorFlow Lite provides several levels of support for quantization. Tensorflow Lite训练后量化量化权重, 激活后易于训练.量化意识训练可以 用于训练可以以最小的精度量化的网络 降低;这仅适用于卷积神经的子集 网络体系结构.Tensorflow Lite post-training quantization quantizes weights and activations post training easily. Quantization-aware training allows for training of networks that can be quantized with minimal accuracy drop; this is only available for a subset of convolutional neural network architectures.因此,首先,您需要确定是否需要训练后量化还是了解量化的培训.例如,如果您已经将模型另存为* .h5文件,则可能要遵循@Mitiku的说明并进行训练后量化.So first, you need to decide whether you need post-training quantization or quantization-aware training. For example, if you already saved the model as *.h5 files, you would probably want to follow @Mitiku's instruction and do the post-training quantization.如果您希望通过模拟训练中的量化效果(使用问题中引用的方法)来获得更高的性能,并且您的模型位于受量化支持的CNN体​​系结构子集中,有意识的培训,此示例可以在Keras和TensorFlow之间的交互方面为您提供帮助.基本上,您只需要在模型定义及其拟合之间添加以下代码:If you prefer to achieve higher performance by simulating the effect of quantization in training (using the method you quoted in the question), and your model is in the subset of CNN architecture supported by quantization-aware training, this example may help you in terms of interaction between Keras and TensorFlow. Basically, you only need to add this code between model definition and its fitting:sess = tf.keras.backend.get_session()tf.contrib.quantize.create_training_graph(sess.graph)sess.run(tf.global_variables_initializer()) 这篇关于量化Keras神经网络模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
06-07 00:41