For time-being, I could figure out a method to do this. But still waiting for official method from any TensorFlow developers.
- First install the tensorflow ( I tried both source installation as well as PIP installation, both are fine)
- Get the tensorflow source from the Github repo and go to the tensorflow root directory (I would call it
tensorflow_root
.
- Now compile the quantization script as given in Pete Warden's blog
bazel build tensorflow/contrib/quantization/tools:quantize_graph
This wil create ops libraries for quantized versions. Go to tensorflow_root/bazel-bin/tensorflow/contrib/quantization and you should see two library files : _quantized_ops.so
and kernels/_quantized_kernels.so
- Now in your script, along with tensorflow, you should import these two library files also, using a dedicated tensorflow function
You can do it using tf.load_op_library() function
import tensorflow as tf
qops = tf.load_op_library('[tensorflow_root]/bazel-bin/tensorflow/contrib/quantization/_quantized_ops.so')
qkernelops = tf.load_op_library('[tensorflow_root]/bazel-bin/tensorflow/contrib/quantization/kernels/_quantized_kernels.so')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…