Install Tensorflow with Quantization Support

試著忘記壹切 提交于 2019-11-29 12:29:13

For time-being, I could figure out a method to do this. But still waiting for official method from any TensorFlow developers.

  1. First install the tensorflow ( I tried both source installation as well as PIP installation, both are fine)
  2. Get the tensorflow source from the Github repo and go to the tensorflow root directory (I would call it tensorflow_root.
  3. 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

  1. 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')

Are you using GPU or CPU version of tensorflow.

for example it does not work on CPU, though as Abid has mentioned loading the ops libraries from local working directory.

But what is the point of using bazel build when latest version has these ops integrated and being imported without error.

$ khemant@saturn:~/DeepLearning/TF$ python -c "import tensorflow as tf; print(tf.__version__)"

0.12.0-rc0

$ khemant@saturn:~/DeepLearning/TF$ python

Python 2.7.6 (default, Oct 26 2016, 20:30:19) [GCC 4.8.4] on linux2 Type "help", "copyright", "credits" or "license" for more information.

>>> from tensorflow.contrib.quantization import load_quantized_ops_so

Traceback (most recent call last): File "", line 1, in ImportError: cannot import name load_quantized_ops_so

>>> import tensorflow as tf

>>> from tensorflow.contrib.quantization import load_quantized_ops_so

Traceback (most recent call last): File "", line 1, in ImportError: cannot import name load_quantized_ops_so `

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!