aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/contrib/quantize
diff options
context:
space:
mode:
authorGravatar Raghuraman Krishnamoorthi <raghuramank@google.com>2018-08-06 15:40:19 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-08-06 15:50:11 -0700
commit2e7ae3406f0715de9e23d7657827048ed81e57cb (patch)
tree915f470452a2db927191f3ba61dd8313e0d1037a /tensorflow/contrib/quantize
parentb87a8a60f2f1648e97fe0f03c10a32ddff8d6a55 (diff)
Support quantization of layers with a conv/matmul followed by an activation, with no bias or batch norm between the conv/matmul and the activation.
PiperOrigin-RevId: 207621304
Diffstat (limited to 'tensorflow/contrib/quantize')
-rw-r--r--tensorflow/contrib/quantize/python/quantize.py3
-rw-r--r--tensorflow/contrib/quantize/python/quantize_test.py27
2 files changed, 29 insertions, 1 deletions
diff --git a/tensorflow/contrib/quantize/python/quantize.py b/tensorflow/contrib/quantize/python/quantize.py
index 903faeff11..cb66fd1f76 100644
--- a/tensorflow/contrib/quantize/python/quantize.py
+++ b/tensorflow/contrib/quantize/python/quantize.py
@@ -198,7 +198,7 @@ def _FindLayersToQuantize(graph):
|
[post_conv_correction]
|
- biasadd|folded_bias
+ [biasadd|folded_bias]
|
[bypass]
|
@@ -320,6 +320,7 @@ def _FindLayersToQuantize(graph):
folded_bias_add_pattern,
batch_norm_identity,
bypass_pattern,
+ layer_pattern,
])
])
diff --git a/tensorflow/contrib/quantize/python/quantize_test.py b/tensorflow/contrib/quantize/python/quantize_test.py
index 98209fffb9..06ebcdfee1 100644
--- a/tensorflow/contrib/quantize/python/quantize_test.py
+++ b/tensorflow/contrib/quantize/python/quantize_test.py
@@ -194,6 +194,33 @@ class QuantizeTest(test_util.TensorFlowTestCase):
self.assertNotIn('test/relu6', [c.name for c in consumers])
+ def testLayerActivationQuantized(self):
+ self._RunTestOverParameters(self._TestLayerActivationQuantized)
+
+ def _TestLayerActivationQuantized(self, is_training):
+ graph = ops.Graph()
+ with graph.as_default():
+ batch_size, height, width, depth = 5, 128, 128, 3
+ input1 = array_ops.zeros((batch_size, height, width, depth))
+ _ = conv2d(
+ input1,
+ 32, [5, 5],
+ stride=2,
+ padding='SAME',
+ weights_initializer=self._WeightInit(0.09),
+ activation_fn=nn_ops.relu6,
+ biases_initializer=None,
+ scope='test')
+ # Ensure that both weights and output of activations are quantized
+ # when we have a conv->relu6 with no bias add
+ quantize.Quantize(graph, is_training, weight_bits=8, activation_bits=8)
+ activation_op = graph.get_operation_by_name('test/Relu6')
+ conv_op = graph.get_operation_by_name('test/Conv2D')
+ self.assertTrue('test/weights_quant/FakeQuantWithMinMaxVars:0' in
+ [tensor_in.name for tensor_in in conv_op.inputs])
+ self.assertTrue('FakeQuantWithMinMaxVars' in
+ [op.type for op in activation_op.outputs[0].consumers()])
+
def testFinalLayerQuantized(self):
self._RunTestOverParameters(self._TestFinalLayerQuantized)