From 4b61fa40dc15d161b720d6534fa27ae2b2f64bf2 Mon Sep 17 00:00:00 2001 From: ianjjohnson <3072903+ianstenbit@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:47:33 -0600 Subject: [PATCH 1/3] Remove direct imports of keras --- keras_cv/callbacks/pycoco_callback.py | 2 +- keras_cv/callbacks/waymo_evaluation_callback.py | 7 +++---- .../preprocessing/base_image_augmentation_layer.py | 7 +++---- keras_cv/layers/preprocessing/random_zoom.py | 2 +- .../vectorized_base_image_augmentation_layer.py | 7 +++---- keras_cv/models/legacy/utils.py | 2 +- keras_cv/models/legacy/utils_test.py | 2 +- keras_cv/models/legacy/weights.py | 2 +- keras_cv/models/object_detection/predict_utils.py | 12 ++++++------ keras_cv/models/utils_test.py | 2 +- 10 files changed, 21 insertions(+), 24 deletions(-) diff --git a/keras_cv/callbacks/pycoco_callback.py b/keras_cv/callbacks/pycoco_callback.py index 889fa361e1..0de03fe799 100644 --- a/keras_cv/callbacks/pycoco_callback.py +++ b/keras_cv/callbacks/pycoco_callback.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -from keras.callbacks import Callback +from tensorflow.keras.callbacks import Callback from keras_cv import bounding_box from keras_cv.api_export import keras_cv_export diff --git a/keras_cv/callbacks/waymo_evaluation_callback.py b/keras_cv/callbacks/waymo_evaluation_callback.py index 458b3796f3..cc73eb9ae8 100644 --- a/keras_cv/callbacks/waymo_evaluation_callback.py +++ b/keras_cv/callbacks/waymo_evaluation_callback.py @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. import tensorflow as tf -from keras.callbacks import Callback +from tensorflow.keras.callbacks import Callback +from keras_cv.api_export import keras_cv_export +from keras_cv.bounding_box_3d import CENTER_XYZ_DXDYDZ_PHI from keras_cv.utils import assert_waymo_open_dataset_installed try: @@ -26,9 +28,6 @@ except ImportError: WODDetectionEvaluator = None -from keras_cv.api_export import keras_cv_export -from keras_cv.bounding_box_3d import CENTER_XYZ_DXDYDZ_PHI - @keras_cv_export("keras_cv.callbacks.WaymoEvaluationCallback") class WaymoEvaluationCallback(Callback): diff --git a/keras_cv/layers/preprocessing/base_image_augmentation_layer.py b/keras_cv/layers/preprocessing/base_image_augmentation_layer.py index 322dc5d92a..36a8d00a4a 100644 --- a/keras_cv/layers/preprocessing/base_image_augmentation_layer.py +++ b/keras_cv/layers/preprocessing/base_image_augmentation_layer.py @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import keras import tensorflow as tf -if hasattr(keras, "src"): - keras_backend = keras.src.backend +if hasattr(tf.keras, "src"): + keras_backend = tf.keras.src.backend else: - keras_backend = keras.backend + keras_backend = tf.keras.backend from keras_cv import bounding_box from keras_cv.api_export import keras_cv_export diff --git a/keras_cv/layers/preprocessing/random_zoom.py b/keras_cv/layers/preprocessing/random_zoom.py index 2e860da649..7af69a2bbf 100644 --- a/keras_cv/layers/preprocessing/random_zoom.py +++ b/keras_cv/layers/preprocessing/random_zoom.py @@ -14,7 +14,7 @@ import tensorflow as tf -from keras import backend +from tensorflow.keras import backend from keras_cv.api_export import keras_cv_export from keras_cv.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501 diff --git a/keras_cv/layers/preprocessing/vectorized_base_image_augmentation_layer.py b/keras_cv/layers/preprocessing/vectorized_base_image_augmentation_layer.py index b327ab9785..7c0f174831 100644 --- a/keras_cv/layers/preprocessing/vectorized_base_image_augmentation_layer.py +++ b/keras_cv/layers/preprocessing/vectorized_base_image_augmentation_layer.py @@ -12,13 +12,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -import keras import tensorflow as tf -if hasattr(keras, "src"): - keras_backend = keras.src.backend +if hasattr(tf.keras, "src"): + keras_backend = tf.keras.src.backend else: - keras_backend = keras.backend + keras_backend = tf.keras.backend from keras_cv import bounding_box from keras_cv.api_export import keras_cv_export diff --git a/keras_cv/models/legacy/utils.py b/keras_cv/models/legacy/utils.py index ba3e852b52..df11081a95 100644 --- a/keras_cv/models/legacy/utils.py +++ b/keras_cv/models/legacy/utils.py @@ -14,8 +14,8 @@ # ============================================================================== """Utility functions for models""" -from keras import layers from tensorflow import keras +from tensorflow.keras import layers def parse_model_inputs(input_shape, input_tensor): diff --git a/keras_cv/models/legacy/utils_test.py b/keras_cv/models/legacy/utils_test.py index df9e15fc2e..497d573fce 100644 --- a/keras_cv/models/legacy/utils_test.py +++ b/keras_cv/models/legacy/utils_test.py @@ -13,8 +13,8 @@ # limitations under the License. """Tests for KerasCV model utils.""" -from keras import layers from tensorflow import keras +from tensorflow.keras import layers from keras_cv.models.legacy import utils from keras_cv.tests.test_case import TestCase diff --git a/keras_cv/models/legacy/weights.py b/keras_cv/models/legacy/weights.py index fc99606000..5f93d1ba97 100644 --- a/keras_cv/models/legacy/weights.py +++ b/keras_cv/models/legacy/weights.py @@ -11,7 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and import tensorflow as tf -from keras import utils +from tensorflow.keras import utils def parse_weights(weights, include_top, model_type): diff --git a/keras_cv/models/object_detection/predict_utils.py b/keras_cv/models/object_detection/predict_utils.py index 8eb6e10e62..6c5b5aefef 100644 --- a/keras_cv/models/object_detection/predict_utils.py +++ b/keras_cv/models/object_detection/predict_utils.py @@ -15,13 +15,13 @@ import tensorflow as tf try: - from keras.src.engine.training import _minimum_control_deps - from keras.src.engine.training import reduce_per_replica - from keras.src.utils import tf_utils + from tf.keras.src.engine.training import _minimum_control_deps + from tf.keras.src.engine.training import reduce_per_replica + from tf.keras.src.utils import tf_utils except ImportError: - from keras.engine.training import _minimum_control_deps - from keras.engine.training import reduce_per_replica - from keras.utils import tf_utils + from tf.keras.engine.training import _minimum_control_deps + from tf.keras.engine.training import reduce_per_replica + from tf.keras.utils import tf_utils def make_predict_function(model, force=False): diff --git a/keras_cv/models/utils_test.py b/keras_cv/models/utils_test.py index 712bd702b1..cc6c1ac596 100644 --- a/keras_cv/models/utils_test.py +++ b/keras_cv/models/utils_test.py @@ -13,7 +13,7 @@ # limitations under the License. """Tests for KerasCV model utils.""" -from keras import layers +from tensorflow.keras import layers from keras_cv.models import utils from keras_cv.tests.test_case import TestCase From a175ddb1b867dd6f957890c34eaa175e9a6337ed Mon Sep 17 00:00:00 2001 From: ianjjohnson <3072903+ianstenbit@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:06:15 -0600 Subject: [PATCH 2/3] Undo change in predict_utils --- keras_cv/models/object_detection/predict_utils.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/keras_cv/models/object_detection/predict_utils.py b/keras_cv/models/object_detection/predict_utils.py index 6c5b5aefef..8eb6e10e62 100644 --- a/keras_cv/models/object_detection/predict_utils.py +++ b/keras_cv/models/object_detection/predict_utils.py @@ -15,13 +15,13 @@ import tensorflow as tf try: - from tf.keras.src.engine.training import _minimum_control_deps - from tf.keras.src.engine.training import reduce_per_replica - from tf.keras.src.utils import tf_utils + from keras.src.engine.training import _minimum_control_deps + from keras.src.engine.training import reduce_per_replica + from keras.src.utils import tf_utils except ImportError: - from tf.keras.engine.training import _minimum_control_deps - from tf.keras.engine.training import reduce_per_replica - from tf.keras.utils import tf_utils + from keras.engine.training import _minimum_control_deps + from keras.engine.training import reduce_per_replica + from keras.utils import tf_utils def make_predict_function(model, force=False): From 8afd230d43d19c486331934c52f171d14ce0252a Mon Sep 17 00:00:00 2001 From: ianjjohnson <3072903+ianstenbit@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:43:59 -0600 Subject: [PATCH 3/3] Undo augmentation layer changes --- .../layers/preprocessing/base_image_augmentation_layer.py | 7 ++++--- .../vectorized_base_image_augmentation_layer.py | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/keras_cv/layers/preprocessing/base_image_augmentation_layer.py b/keras_cv/layers/preprocessing/base_image_augmentation_layer.py index 36a8d00a4a..322dc5d92a 100644 --- a/keras_cv/layers/preprocessing/base_image_augmentation_layer.py +++ b/keras_cv/layers/preprocessing/base_image_augmentation_layer.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import keras import tensorflow as tf -if hasattr(tf.keras, "src"): - keras_backend = tf.keras.src.backend +if hasattr(keras, "src"): + keras_backend = keras.src.backend else: - keras_backend = tf.keras.backend + keras_backend = keras.backend from keras_cv import bounding_box from keras_cv.api_export import keras_cv_export diff --git a/keras_cv/layers/preprocessing/vectorized_base_image_augmentation_layer.py b/keras_cv/layers/preprocessing/vectorized_base_image_augmentation_layer.py index 7c0f174831..b327ab9785 100644 --- a/keras_cv/layers/preprocessing/vectorized_base_image_augmentation_layer.py +++ b/keras_cv/layers/preprocessing/vectorized_base_image_augmentation_layer.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. +import keras import tensorflow as tf -if hasattr(tf.keras, "src"): - keras_backend = tf.keras.src.backend +if hasattr(keras, "src"): + keras_backend = keras.src.backend else: - keras_backend = tf.keras.backend + keras_backend = keras.backend from keras_cv import bounding_box from keras_cv.api_export import keras_cv_export