File tree 3 files changed +23
-7
lines changed
tensorflow_model_optimization/python/core
experimental/default_n_bit
3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 17
17
import collections
18
18
import inspect
19
19
20
- from keras import backend
21
20
import numpy as np
22
21
import tensorflow as tf
23
22
29
28
from tensorflow_model_optimization .python .core .quantization .keras .default_8bit import default_8bit_quantize_registry
30
29
from tensorflow_model_optimization .python .core .quantization .keras .graph_transformations import transforms
31
30
31
+ try :
32
+ from keras .backend import unique_object_name # pylint: disable=g-import-not-at-top
33
+ except ImportError :
34
+ # Path as seen in pip packages as of TF/Keras 2.13.
35
+ from keras .src .backend import unique_object_name # pylint: disable=g-import-not-at-top
36
+
32
37
LayerNode = transforms .LayerNode
33
38
LayerPattern = transforms .LayerPattern
34
39
@@ -364,9 +369,9 @@ def pattern(self):
364
369
return LayerPattern ('SeparableConv1D' )
365
370
366
371
def _get_name (self , prefix ):
367
- # TODO(pulkitb): Move away from `backend. unique_object_name` since it isn't
372
+ # TODO(pulkitb): Move away from `unique_object_name` since it isn't
368
373
# exposed as externally usable.
369
- return backend . unique_object_name (prefix )
374
+ return unique_object_name (prefix )
370
375
371
376
def replacement (self , match_layer ):
372
377
if _has_custom_quantize_config (match_layer ):
Original file line number Diff line number Diff line change 17
17
import collections
18
18
import inspect
19
19
20
- from keras import backend
21
20
import numpy as np
22
21
import tensorflow as tf
23
22
29
28
from tensorflow_model_optimization .python .core .quantization .keras .experimental .default_n_bit import default_n_bit_quantize_registry
30
29
from tensorflow_model_optimization .python .core .quantization .keras .graph_transformations import transforms
31
30
31
+
32
+ try :
33
+ from keras .backend import unique_object_name # pylint: disable=g-import-not-at-top
34
+ except ImportError :
35
+ # Path as seen in pip packages as of TF/Keras 2.13.
36
+ from keras .src .backend import unique_object_name # pylint: disable=g-import-not-at-top
37
+
32
38
LayerNode = transforms .LayerNode
33
39
LayerPattern = transforms .LayerPattern
34
40
@@ -395,9 +401,9 @@ def pattern(self):
395
401
return LayerPattern ('SeparableConv1D' )
396
402
397
403
def _get_name (self , prefix ):
398
- # TODO(pulkitb): Move away from `backend. unique_object_name` since it isn't
404
+ # TODO(pulkitb): Move away from `unique_object_name` since it isn't
399
405
# exposed as externally usable.
400
- return backend . unique_object_name (prefix )
406
+ return unique_object_name (prefix )
401
407
402
408
def replacement (self , match_layer ):
403
409
if _has_custom_quantize_config (match_layer ):
Original file line number Diff line number Diff line change 14
14
# ==============================================================================
15
15
"""Registry responsible for built-in keras classes."""
16
16
17
- from keras .engine import base_layer
18
17
import tensorflow as tf
19
18
20
19
from tensorflow_model_optimization .python .core .sparsity .keras import prunable_layer
21
20
21
+ try :
22
+ from keras .engine import base_layer # pylint: disable=g-import-not-at-top
23
+ except ImportError :
24
+ # Path as seen in pip packages as of TF/Keras 2.13.
25
+ from keras .src .engine import base_layer # pylint: disable=g-import-not-at-top
26
+
22
27
# TODO(b/139939526): move to public API.
23
28
24
29
layers = tf .keras .layers
You can’t perform that action at this time.
0 commit comments