|
20 | 20 | import numpy as np |
21 | 21 | import tensorflow as tf |
22 | 22 |
|
| 23 | +from tensorflow.python.keras import backend |
| 24 | + |
23 | 25 | from tensorflow_model_optimization.python.core.quantization.keras import quantize_aware_activation |
24 | 26 | from tensorflow_model_optimization.python.core.quantization.keras import quantize_layer |
25 | 27 | from tensorflow_model_optimization.python.core.quantization.keras import quantizers |
@@ -258,6 +260,11 @@ class SeparableConv1DQuantize(transforms.Transform): |
258 | 260 | def pattern(self): |
259 | 261 | return LayerPattern('SeparableConv1D') |
260 | 262 |
|
| 263 | + def _get_name(self, prefix): |
| 264 | + # TODO(pulkitb): Move away from `backend.unique_object_name` since it isn't |
| 265 | + # exposed as externally usable. |
| 266 | + return backend.unique_object_name(prefix) |
| 267 | + |
261 | 268 | def replacement(self, match_layer): |
262 | 269 | if _has_custom_quantize_config(match_layer): |
263 | 270 | return match_layer |
@@ -321,16 +328,20 @@ def replacement(self, match_layer): |
321 | 328 | # Needed to ensure these new layers are considered for quantization. |
322 | 329 | sepconv2d_metadata = {'quantize_config': None} |
323 | 330 |
|
| 331 | + # TODO(pulkitb): Consider moving from Lambda to custom ExpandDims/Squeeze. |
| 332 | + |
324 | 333 | # Layer before SeparableConv2D which expands input tensors to match 2D. |
325 | 334 | expand_layer = tf.keras.layers.Lambda( |
326 | | - lambda x: tf.expand_dims(x, spatial_dim), name='sepconv1d_expand') |
| 335 | + lambda x: tf.expand_dims(x, spatial_dim), |
| 336 | + name=self._get_name('sepconv1d_expand')) |
327 | 337 | expand_layer_config = keras.layers.serialize(expand_layer) |
328 | 338 | expand_layer_config['name'] = expand_layer.name |
329 | 339 | expand_layer_metadata = { |
330 | 340 | 'quantize_config': default_8bit_quantize_configs.NoOpQuantizeConfig()} |
331 | 341 |
|
332 | 342 | squeeze_layer = tf.keras.layers.Lambda( |
333 | | - lambda x: tf.squeeze(x, [spatial_dim]), name='sepconv1d_squeeze') |
| 343 | + lambda x: tf.squeeze(x, [spatial_dim]), |
| 344 | + name=self._get_name('sepconv1d_squeeze')) |
334 | 345 | squeeze_layer_config = keras.layers.serialize(squeeze_layer) |
335 | 346 | squeeze_layer_config['name'] = squeeze_layer.name |
336 | 347 | squeeze_layer_metadata = { |
|
0 commit comments