diff --git a/keras_cv/src/backend/tf_ops.py b/keras_cv/src/backend/tf_ops.py index aaf7ec7dfc..4ef359e917 100644 --- a/keras_cv/src/backend/tf_ops.py +++ b/keras_cv/src/backend/tf_ops.py @@ -46,7 +46,14 @@ from tensorflow import split # noqa: F403, F401 import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) def smart_resize(x, size, interpolation="bilinear"): diff --git a/keras_cv/src/bounding_box/converters.py b/keras_cv/src/bounding_box/converters.py index 689995644e..e55e4b9c51 100644 --- a/keras_cv/src/bounding_box/converters.py +++ b/keras_cv/src/bounding_box/converters.py @@ -14,7 +14,13 @@ """Converter functions for working with bounding box formats.""" -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/bounding_box/converters_test.py b/keras_cv/src/bounding_box/converters_test.py index e8f1b949e3..23c47f82c6 100644 --- a/keras_cv/src/bounding_box/converters_test.py +++ b/keras_cv/src/bounding_box/converters_test.py @@ -16,7 +16,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import bounding_box diff --git a/keras_cv/src/bounding_box/mask_invalid_detections_test.py b/keras_cv/src/bounding_box/mask_invalid_detections_test.py index a8c4fc9a66..15d6b519c5 100644 --- a/keras_cv/src/bounding_box/mask_invalid_detections_test.py +++ b/keras_cv/src/bounding_box/mask_invalid_detections_test.py @@ -14,7 +14,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.backend import ops diff --git a/keras_cv/src/bounding_box/to_dense.py b/keras_cv/src/bounding_box/to_dense.py index cd75261287..145d331fb3 100644 --- a/keras_cv/src/bounding_box/to_dense.py +++ b/keras_cv/src/bounding_box/to_dense.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import keras_cv.src.bounding_box.validate_format as validate_format from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/bounding_box/to_dense_test.py b/keras_cv/src/bounding_box/to_dense_test.py index 9d098c43a3..01e2c63d5c 100644 --- a/keras_cv/src/bounding_box/to_dense_test.py +++ b/keras_cv/src/bounding_box/to_dense_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/bounding_box/to_ragged.py b/keras_cv/src/bounding_box/to_ragged.py index 113367b82d..1f87cd384e 100644 --- a/keras_cv/src/bounding_box/to_ragged.py +++ b/keras_cv/src/bounding_box/to_ragged.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import keras_cv.src.bounding_box.validate_format as validate_format from keras_cv.src import backend diff --git a/keras_cv/src/bounding_box/validate_format.py b/keras_cv/src/bounding_box/validate_format.py index ec42a00e50..4541a5deab 100644 --- a/keras_cv/src/bounding_box/validate_format.py +++ b/keras_cv/src/bounding_box/validate_format.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/callbacks/waymo_evaluation_callback.py b/keras_cv/src/callbacks/waymo_evaluation_callback.py index c678ddb3c3..f2b261782a 100644 --- a/keras_cv/src/callbacks/waymo_evaluation_callback.py +++ b/keras_cv/src/callbacks/waymo_evaluation_callback.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow.keras.callbacks import Callback from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/callbacks/waymo_evaluation_callback_test.py b/keras_cv/src/callbacks/waymo_evaluation_callback_test.py index 3a496000e0..92489b913b 100644 --- a/keras_cv/src/callbacks/waymo_evaluation_callback_test.py +++ b/keras_cv/src/callbacks/waymo_evaluation_callback_test.py @@ -14,7 +14,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from keras_cv.src.callbacks import WaymoEvaluationCallback diff --git a/keras_cv/src/core/factor_sampler/constant_factor_sampler.py b/keras_cv/src/core/factor_sampler/constant_factor_sampler.py index 7faff0dab1..c5ed578dc5 100644 --- a/keras_cv/src/core/factor_sampler/constant_factor_sampler.py +++ b/keras_cv/src/core/factor_sampler/constant_factor_sampler.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.core.factor_sampler.factor_sampler import FactorSampler diff --git a/keras_cv/src/core/factor_sampler/normal_factor_sampler.py b/keras_cv/src/core/factor_sampler/normal_factor_sampler.py index 8a0250fdb6..5d2aee7f1b 100644 --- a/keras_cv/src/core/factor_sampler/normal_factor_sampler.py +++ b/keras_cv/src/core/factor_sampler/normal_factor_sampler.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.core.factor_sampler.factor_sampler import FactorSampler diff --git a/keras_cv/src/core/factor_sampler/uniform_factor_sampler.py b/keras_cv/src/core/factor_sampler/uniform_factor_sampler.py index e17d87de68..632d20eab8 100644 --- a/keras_cv/src/core/factor_sampler/uniform_factor_sampler.py +++ b/keras_cv/src/core/factor_sampler/uniform_factor_sampler.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.core.factor_sampler.factor_sampler import FactorSampler diff --git a/keras_cv/src/datasets/imagenet/load.py b/keras_cv/src/datasets/imagenet/load.py index 86101ba59d..6b62bd5657 100644 --- a/keras_cv/src/datasets/imagenet/load.py +++ b/keras_cv/src/datasets/imagenet/load.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow.keras import layers from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/datasets/pascal_voc/load.py b/keras_cv/src/datasets/pascal_voc/load.py index d5592fd7b8..68924a68d2 100644 --- a/keras_cv/src/datasets/pascal_voc/load.py +++ b/keras_cv/src/datasets/pascal_voc/load.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import tensorflow_datasets as tfds from keras_cv.src import bounding_box diff --git a/keras_cv/src/datasets/pascal_voc/segmentation.py b/keras_cv/src/datasets/pascal_voc/segmentation.py index 678acb6926..b5f17df338 100644 --- a/keras_cv/src/datasets/pascal_voc/segmentation.py +++ b/keras_cv/src/datasets/pascal_voc/segmentation.py @@ -43,7 +43,14 @@ class and instance segmentation masks. import xml import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import tensorflow_datasets as tfds from tensorflow import keras diff --git a/keras_cv/src/datasets/pascal_voc/segmentation_test.py b/keras_cv/src/datasets/pascal_voc/segmentation_test.py index 3695a31c04..76f1d1e576 100644 --- a/keras_cv/src/datasets/pascal_voc/segmentation_test.py +++ b/keras_cv/src/datasets/pascal_voc/segmentation_test.py @@ -15,7 +15,13 @@ import pathlib import sys -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl import flags from keras_cv.src.datasets.pascal_voc import segmentation diff --git a/keras_cv/src/datasets/waymo/load.py b/keras_cv/src/datasets/waymo/load.py index a7bf6ed0b4..a84791399d 100644 --- a/keras_cv/src/datasets/waymo/load.py +++ b/keras_cv/src/datasets/waymo/load.py @@ -14,7 +14,13 @@ """Data loader for the Waymo Open Dataset.""" import os -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.datasets.waymo import transformer from keras_cv.src.utils import assert_waymo_open_dataset_installed diff --git a/keras_cv/src/datasets/waymo/struct.py b/keras_cv/src/datasets/waymo/struct.py index 87e7179072..6d90261335 100644 --- a/keras_cv/src/datasets/waymo/struct.py +++ b/keras_cv/src/datasets/waymo/struct.py @@ -16,7 +16,13 @@ import dataclasses from typing import Optional -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) @dataclasses.dataclass diff --git a/keras_cv/src/datasets/waymo/transformer.py b/keras_cv/src/datasets/waymo/transformer.py index 94dc93dcab..cba7d4bfa3 100644 --- a/keras_cv/src/datasets/waymo/transformer.py +++ b/keras_cv/src/datasets/waymo/transformer.py @@ -20,7 +20,14 @@ from typing import Tuple import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.utils import assert_waymo_open_dataset_installed diff --git a/keras_cv/src/datasets/waymo/transformer_test.py b/keras_cv/src/datasets/waymo/transformer_test.py index 04941553d4..86ce34d35c 100644 --- a/keras_cv/src/datasets/waymo/transformer_test.py +++ b/keras_cv/src/datasets/waymo/transformer_test.py @@ -15,7 +15,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/keypoint/converters.py b/keras_cv/src/keypoint/converters.py index 60e6b9b046..11991de98b 100644 --- a/keras_cv/src/keypoint/converters.py +++ b/keras_cv/src/keypoint/converters.py @@ -13,7 +13,13 @@ # limitations under the License. """Converter functions for working with keypoints formats.""" -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/keypoint/converters_test.py b/keras_cv/src/keypoint/converters_test.py index 185ca50648..6665906e2f 100644 --- a/keras_cv/src/keypoint/converters_test.py +++ b/keras_cv/src/keypoint/converters_test.py @@ -15,7 +15,14 @@ import itertools import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import keypoint diff --git a/keras_cv/src/keypoint/utils.py b/keras_cv/src/keypoint/utils.py index de776cf217..f067df7462 100644 --- a/keras_cv/src/keypoint/utils.py +++ b/keras_cv/src/keypoint/utils.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. """Utility functions for keypoint transformation.""" -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/keypoint/utils_test.py b/keras_cv/src/keypoint/utils_test.py index 636c595deb..48bf92884f 100644 --- a/keras_cv/src/keypoint/utils_test.py +++ b/keras_cv/src/keypoint/utils_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.keypoint.utils import filter_out_of_image diff --git a/keras_cv/src/layers/fusedmbconv_test.py b/keras_cv/src/layers/fusedmbconv_test.py index 1e33a821d5..bd47bced5d 100644 --- a/keras_cv/src/layers/fusedmbconv_test.py +++ b/keras_cv/src/layers/fusedmbconv_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from keras_cv.src.layers.fusedmbconv import FusedMBConvBlock diff --git a/keras_cv/src/layers/mbconv_test.py b/keras_cv/src/layers/mbconv_test.py index 8ac36764f6..b8335779a4 100644 --- a/keras_cv/src/layers/mbconv_test.py +++ b/keras_cv/src/layers/mbconv_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from keras_cv.src.layers.mbconv import MBConvBlock diff --git a/keras_cv/src/layers/object_detection/multi_class_non_max_suppression.py b/keras_cv/src/layers/object_detection/multi_class_non_max_suppression.py index fe22491626..292d3dc1bf 100644 --- a/keras_cv/src/layers/object_detection/multi_class_non_max_suppression.py +++ b/keras_cv/src/layers/object_detection/multi_class_non_max_suppression.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/object_detection/multi_class_non_max_suppression_test.py b/keras_cv/src/layers/object_detection/multi_class_non_max_suppression_test.py index 7d689159b0..32427e0292 100644 --- a/keras_cv/src/layers/object_detection/multi_class_non_max_suppression_test.py +++ b/keras_cv/src/layers/object_detection/multi_class_non_max_suppression_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import layers as cv_layers from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/object_detection/non_max_suppression.py b/keras_cv/src/layers/object_detection/non_max_suppression.py index 45993258e4..5fb8c506c7 100644 --- a/keras_cv/src/layers/object_detection/non_max_suppression.py +++ b/keras_cv/src/layers/object_detection/non_max_suppression.py @@ -14,7 +14,13 @@ import math -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/object_detection_3d/centernet_label_encoder.py b/keras_cv/src/layers/object_detection_3d/centernet_label_encoder.py index d6d61d2fb8..51bef33c98 100644 --- a/keras_cv/src/layers/object_detection_3d/centernet_label_encoder.py +++ b/keras_cv/src/layers/object_detection_3d/centernet_label_encoder.py @@ -18,7 +18,14 @@ from typing import Union import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/object_detection_3d/centernet_label_encoder_test.py b/keras_cv/src/layers/object_detection_3d/centernet_label_encoder_test.py index 928a944351..57190978ee 100644 --- a/keras_cv/src/layers/object_detection_3d/centernet_label_encoder_test.py +++ b/keras_cv/src/layers/object_detection_3d/centernet_label_encoder_test.py @@ -13,7 +13,13 @@ # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.object_detection_3d.centernet_label_encoder import ( CenterNetLabelEncoder, diff --git a/keras_cv/src/layers/object_detection_3d/voxel_utils.py b/keras_cv/src/layers/object_detection_3d/voxel_utils.py index 94a0bda60b..d5787d40a2 100644 --- a/keras_cv/src/layers/object_detection_3d/voxel_utils.py +++ b/keras_cv/src/layers/object_detection_3d/voxel_utils.py @@ -15,7 +15,14 @@ import math import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops diff --git a/keras_cv/src/layers/object_detection_3d/voxel_utils_test.py b/keras_cv/src/layers/object_detection_3d/voxel_utils_test.py index e3c1115bab..98775860de 100644 --- a/keras_cv/src/layers/object_detection_3d/voxel_utils_test.py +++ b/keras_cv/src/layers/object_detection_3d/voxel_utils_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.object_detection_3d import voxel_utils from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/object_detection_3d/voxelization_test.py b/keras_cv/src/layers/object_detection_3d/voxelization_test.py index 27795a1717..83ed09393b 100644 --- a/keras_cv/src/layers/object_detection_3d/voxelization_test.py +++ b/keras_cv/src/layers/object_detection_3d/voxelization_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import keras from keras_cv.src.layers.object_detection_3d.voxelization import ( diff --git a/keras_cv/src/layers/preprocessing/aug_mix.py b/keras_cv/src/layers/preprocessing/aug_mix.py index dbd9d5ea61..33a79612f9 100644 --- a/keras_cv/src/layers/preprocessing/aug_mix.py +++ b/keras_cv/src/layers/preprocessing/aug_mix.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import layers from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/aug_mix_test.py b/keras_cv/src/layers/preprocessing/aug_mix_test.py index c39130d536..2b38f40c6a 100644 --- a/keras_cv/src/layers/preprocessing/aug_mix_test.py +++ b/keras_cv/src/layers/preprocessing/aug_mix_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import preprocessing from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/auto_contrast.py b/keras_cv/src/layers/preprocessing/auto_contrast.py index eb78e8810c..c2c2881168 100644 --- a/keras_cv/src/layers/preprocessing/auto_contrast.py +++ b/keras_cv/src/layers/preprocessing/auto_contrast.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501 diff --git a/keras_cv/src/layers/preprocessing/base_image_augmentation_layer.py b/keras_cv/src/layers/preprocessing/base_image_augmentation_layer.py index ff67f0b9d0..d6775af10e 100644 --- a/keras_cv/src/layers/preprocessing/base_image_augmentation_layer.py +++ b/keras_cv/src/layers/preprocessing/base_image_augmentation_layer.py @@ -13,7 +13,14 @@ # limitations under the License. import keras -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import tree if hasattr(keras, "src"): diff --git a/keras_cv/src/layers/preprocessing/base_image_augmentation_layer_test.py b/keras_cv/src/layers/preprocessing/base_image_augmentation_layer_test.py index 8269010524..327574a48e 100644 --- a/keras_cv/src/layers/preprocessing/base_image_augmentation_layer_test.py +++ b/keras_cv/src/layers/preprocessing/base_image_augmentation_layer_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.backend import ops diff --git a/keras_cv/src/layers/preprocessing/channel_shuffle.py b/keras_cv/src/layers/preprocessing/channel_shuffle.py index 931be7b770..3377d3e7d1 100644 --- a/keras_cv/src/layers/preprocessing/channel_shuffle.py +++ b/keras_cv/src/layers/preprocessing/channel_shuffle.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501 diff --git a/keras_cv/src/layers/preprocessing/channel_shuffle_test.py b/keras_cv/src/layers/preprocessing/channel_shuffle_test.py index 9fa6f2326a..e0001dca27 100644 --- a/keras_cv/src/layers/preprocessing/channel_shuffle_test.py +++ b/keras_cv/src/layers/preprocessing/channel_shuffle_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops from keras_cv.src.layers.preprocessing.channel_shuffle import ChannelShuffle diff --git a/keras_cv/src/layers/preprocessing/cut_mix.py b/keras_cv/src/layers/preprocessing/cut_mix.py index b2a02476cc..8cf76788d8 100644 --- a/keras_cv/src/layers/preprocessing/cut_mix.py +++ b/keras_cv/src/layers/preprocessing/cut_mix.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.base_image_augmentation_layer import ( diff --git a/keras_cv/src/layers/preprocessing/cut_mix_test.py b/keras_cv/src/layers/preprocessing/cut_mix_test.py index 0127b0bc55..c6d545bfd8 100644 --- a/keras_cv/src/layers/preprocessing/cut_mix_test.py +++ b/keras_cv/src/layers/preprocessing/cut_mix_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops from keras_cv.src.layers.preprocessing.cut_mix import CutMix diff --git a/keras_cv/src/layers/preprocessing/equalization.py b/keras_cv/src/layers/preprocessing/equalization.py index c09f57caa1..c606f1c1cf 100644 --- a/keras_cv/src/layers/preprocessing/equalization.py +++ b/keras_cv/src/layers/preprocessing/equalization.py @@ -14,7 +14,13 @@ from functools import partial -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501 diff --git a/keras_cv/src/layers/preprocessing/fourier_mix.py b/keras_cv/src/layers/preprocessing/fourier_mix.py index 35042b1288..3f6c5c05c0 100644 --- a/keras_cv/src/layers/preprocessing/fourier_mix.py +++ b/keras_cv/src/layers/preprocessing/fourier_mix.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.base_image_augmentation_layer import ( diff --git a/keras_cv/src/layers/preprocessing/fourier_mix_test.py b/keras_cv/src/layers/preprocessing/fourier_mix_test.py index bde18d8504..a61511eb78 100644 --- a/keras_cv/src/layers/preprocessing/fourier_mix_test.py +++ b/keras_cv/src/layers/preprocessing/fourier_mix_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.preprocessing.fourier_mix import FourierMix from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/grayscale.py b/keras_cv/src/layers/preprocessing/grayscale.py index 6b231ad26a..7c3495507a 100644 --- a/keras_cv/src/layers/preprocessing/grayscale.py +++ b/keras_cv/src/layers/preprocessing/grayscale.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501 diff --git a/keras_cv/src/layers/preprocessing/grayscale_test.py b/keras_cv/src/layers/preprocessing/grayscale_test.py index 2d46308d59..af6f833055 100644 --- a/keras_cv/src/layers/preprocessing/grayscale_test.py +++ b/keras_cv/src/layers/preprocessing/grayscale_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import preprocessing from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/grid_mask.py b/keras_cv/src/layers/preprocessing/grid_mask.py index 68b303ff1a..8f1cbf59f2 100644 --- a/keras_cv/src/layers/preprocessing/grid_mask.py +++ b/keras_cv/src/layers/preprocessing/grid_mask.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import core from keras_cv.src import layers as cv_layers diff --git a/keras_cv/src/layers/preprocessing/grid_mask_test.py b/keras_cv/src/layers/preprocessing/grid_mask_test.py index d32826dec7..84552a1227 100644 --- a/keras_cv/src/layers/preprocessing/grid_mask_test.py +++ b/keras_cv/src/layers/preprocessing/grid_mask_test.py @@ -14,7 +14,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import keras_cv from keras_cv.src.backend import ops diff --git a/keras_cv/src/layers/preprocessing/jittered_resize.py b/keras_cv/src/layers/preprocessing/jittered_resize.py index 79a75b4f21..eb76d17168 100644 --- a/keras_cv/src/layers/preprocessing/jittered_resize.py +++ b/keras_cv/src/layers/preprocessing/jittered_resize.py @@ -16,7 +16,13 @@ # Reference: # https://github.com/tensorflow/models/blob/master/official/vision/ops/preprocess_ops.py -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/jittered_resize_test.py b/keras_cv/src/layers/preprocessing/jittered_resize_test.py index 421ca18607..0b37af0e05 100644 --- a/keras_cv/src/layers/preprocessing/jittered_resize_test.py +++ b/keras_cv/src/layers/preprocessing/jittered_resize_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src import core diff --git a/keras_cv/src/layers/preprocessing/mix_up.py b/keras_cv/src/layers/preprocessing/mix_up.py index 01fff9cb03..cee9a94d77 100644 --- a/keras_cv/src/layers/preprocessing/mix_up.py +++ b/keras_cv/src/layers/preprocessing/mix_up.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/mix_up_test.py b/keras_cv/src/layers/preprocessing/mix_up_test.py index b8049608a8..e791125628 100644 --- a/keras_cv/src/layers/preprocessing/mix_up_test.py +++ b/keras_cv/src/layers/preprocessing/mix_up_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.preprocessing.mix_up import MixUp from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/mosaic.py b/keras_cv/src/layers/preprocessing/mosaic.py index fe1258c623..ced9ecf23d 100644 --- a/keras_cv/src/layers/preprocessing/mosaic.py +++ b/keras_cv/src/layers/preprocessing/mosaic.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/mosaic_test.py b/keras_cv/src/layers/preprocessing/mosaic_test.py index ec7574b199..ddae75ea14 100644 --- a/keras_cv/src/layers/preprocessing/mosaic_test.py +++ b/keras_cv/src/layers/preprocessing/mosaic_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.preprocessing.mosaic import Mosaic from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/posterization.py b/keras_cv/src/layers/preprocessing/posterization.py index b60a1bc8e0..a0b9d492ac 100644 --- a/keras_cv/src/layers/preprocessing/posterization.py +++ b/keras_cv/src/layers/preprocessing/posterization.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.base_image_augmentation_layer import ( diff --git a/keras_cv/src/layers/preprocessing/posterization_test.py b/keras_cv/src/layers/preprocessing/posterization_test.py index e61b0a4eb2..0fc7ad0ab2 100644 --- a/keras_cv/src/layers/preprocessing/posterization_test.py +++ b/keras_cv/src/layers/preprocessing/posterization_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.preprocessing.posterization import Posterization from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/ragged_image_test.py b/keras_cv/src/layers/preprocessing/ragged_image_test.py index 97882db3ae..00a0988ef1 100644 --- a/keras_cv/src/layers/preprocessing/ragged_image_test.py +++ b/keras_cv/src/layers/preprocessing/ragged_image_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import layers diff --git a/keras_cv/src/layers/preprocessing/rand_augment_test.py b/keras_cv/src/layers/preprocessing/rand_augment_test.py index c56829bcf0..d40f9a8763 100644 --- a/keras_cv/src/layers/preprocessing/rand_augment_test.py +++ b/keras_cv/src/layers/preprocessing/rand_augment_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import layers diff --git a/keras_cv/src/layers/preprocessing/random_apply_test.py b/keras_cv/src/layers/preprocessing/random_apply_test.py index 9bff4dbdfa..338dc808c4 100644 --- a/keras_cv/src/layers/preprocessing/random_apply_test.py +++ b/keras_cv/src/layers/preprocessing/random_apply_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import layers diff --git a/keras_cv/src/layers/preprocessing/random_aspect_ratio.py b/keras_cv/src/layers/preprocessing/random_aspect_ratio.py index 7c1e62a2b9..c26500bc97 100644 --- a/keras_cv/src/layers/preprocessing/random_aspect_ratio.py +++ b/keras_cv/src/layers/preprocessing/random_aspect_ratio.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/random_aspect_ratio_test.py b/keras_cv/src/layers/preprocessing/random_aspect_ratio_test.py index 257953c3cd..f2b65c83ea 100644 --- a/keras_cv/src/layers/preprocessing/random_aspect_ratio_test.py +++ b/keras_cv/src/layers/preprocessing/random_aspect_ratio_test.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src import layers diff --git a/keras_cv/src/layers/preprocessing/random_augmentation_pipeline.py b/keras_cv/src/layers/preprocessing/random_augmentation_pipeline.py index 245c37cbe1..4ad9e9b875 100644 --- a/keras_cv/src/layers/preprocessing/random_augmentation_pipeline.py +++ b/keras_cv/src/layers/preprocessing/random_augmentation_pipeline.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/random_augmentation_pipeline_test.py b/keras_cv/src/layers/preprocessing/random_augmentation_pipeline_test.py index 408bbc241a..e58fa409f9 100644 --- a/keras_cv/src/layers/preprocessing/random_augmentation_pipeline_test.py +++ b/keras_cv/src/layers/preprocessing/random_augmentation_pipeline_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import layers diff --git a/keras_cv/src/layers/preprocessing/random_brightness.py b/keras_cv/src/layers/preprocessing/random_brightness.py index ded77fecaa..a754bde3b6 100644 --- a/keras_cv/src/layers/preprocessing/random_brightness.py +++ b/keras_cv/src/layers/preprocessing/random_brightness.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/random_brightness_test.py b/keras_cv/src/layers/preprocessing/random_brightness_test.py index 281ad0d70b..b4727a2077 100644 --- a/keras_cv/src/layers/preprocessing/random_brightness_test.py +++ b/keras_cv/src/layers/preprocessing/random_brightness_test.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import core from keras_cv.src.layers import preprocessing diff --git a/keras_cv/src/layers/preprocessing/random_channel_shift.py b/keras_cv/src/layers/preprocessing/random_channel_shift.py index f1e985741e..fb9e846252 100644 --- a/keras_cv/src/layers/preprocessing/random_channel_shift.py +++ b/keras_cv/src/layers/preprocessing/random_channel_shift.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.base_image_augmentation_layer import ( diff --git a/keras_cv/src/layers/preprocessing/random_channel_shift_test.py b/keras_cv/src/layers/preprocessing/random_channel_shift_test.py index d7123606c7..b5f31c75d0 100644 --- a/keras_cv/src/layers/preprocessing/random_channel_shift_test.py +++ b/keras_cv/src/layers/preprocessing/random_channel_shift_test.py @@ -14,7 +14,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops from keras_cv.src.layers import preprocessing diff --git a/keras_cv/src/layers/preprocessing/random_choice.py b/keras_cv/src/layers/preprocessing/random_choice.py index b043f12c71..b4484b1d97 100644 --- a/keras_cv/src/layers/preprocessing/random_choice.py +++ b/keras_cv/src/layers/preprocessing/random_choice.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.base_image_augmentation_layer import ( diff --git a/keras_cv/src/layers/preprocessing/random_choice_test.py b/keras_cv/src/layers/preprocessing/random_choice_test.py index 7d5eab924c..30bdecc1cf 100644 --- a/keras_cv/src/layers/preprocessing/random_choice_test.py +++ b/keras_cv/src/layers/preprocessing/random_choice_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import layers from keras_cv.src.layers.preprocessing.base_image_augmentation_layer import ( diff --git a/keras_cv/src/layers/preprocessing/random_color_degeneration.py b/keras_cv/src/layers/preprocessing/random_color_degeneration.py index a239d76bb3..e1bbf14109 100644 --- a/keras_cv/src/layers/preprocessing/random_color_degeneration.py +++ b/keras_cv/src/layers/preprocessing/random_color_degeneration.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/random_color_degeneration_test.py b/keras_cv/src/layers/preprocessing/random_color_degeneration_test.py index 6725579da8..39ab31c716 100644 --- a/keras_cv/src/layers/preprocessing/random_color_degeneration_test.py +++ b/keras_cv/src/layers/preprocessing/random_color_degeneration_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops from keras_cv.src.layers import preprocessing diff --git a/keras_cv/src/layers/preprocessing/random_color_jitter_test.py b/keras_cv/src/layers/preprocessing/random_color_jitter_test.py index 90128ac03d..afa6d9b147 100644 --- a/keras_cv/src/layers/preprocessing/random_color_jitter_test.py +++ b/keras_cv/src/layers/preprocessing/random_color_jitter_test.py @@ -14,7 +14,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import preprocessing from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/random_contrast.py b/keras_cv/src/layers/preprocessing/random_contrast.py index 89ecf8b98c..6e5f84f36f 100644 --- a/keras_cv/src/layers/preprocessing/random_contrast.py +++ b/keras_cv/src/layers/preprocessing/random_contrast.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501 diff --git a/keras_cv/src/layers/preprocessing/random_contrast_test.py b/keras_cv/src/layers/preprocessing/random_contrast_test.py index 8d440e8f0b..8ef9c15360 100644 --- a/keras_cv/src/layers/preprocessing/random_contrast_test.py +++ b/keras_cv/src/layers/preprocessing/random_contrast_test.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import preprocessing from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/random_crop.py b/keras_cv/src/layers/preprocessing/random_crop.py index 404cb9b5f4..c030017e6f 100644 --- a/keras_cv/src/layers/preprocessing/random_crop.py +++ b/keras_cv/src/layers/preprocessing/random_crop.py @@ -13,7 +13,13 @@ # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src import layers as cv_layers diff --git a/keras_cv/src/layers/preprocessing/random_crop_and_resize.py b/keras_cv/src/layers/preprocessing/random_crop_and_resize.py index 956e2a7788..2797e307d8 100644 --- a/keras_cv/src/layers/preprocessing/random_crop_and_resize.py +++ b/keras_cv/src/layers/preprocessing/random_crop_and_resize.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src import core diff --git a/keras_cv/src/layers/preprocessing/random_crop_and_resize_test.py b/keras_cv/src/layers/preprocessing/random_crop_and_resize_test.py index 10c9f1ad20..ba2c3ab1fd 100644 --- a/keras_cv/src/layers/preprocessing/random_crop_and_resize_test.py +++ b/keras_cv/src/layers/preprocessing/random_crop_and_resize_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import bounding_box diff --git a/keras_cv/src/layers/preprocessing/random_crop_test.py b/keras_cv/src/layers/preprocessing/random_crop_test.py index 89aa5120e6..b2b3eea14e 100644 --- a/keras_cv/src/layers/preprocessing/random_crop_test.py +++ b/keras_cv/src/layers/preprocessing/random_crop_test.py @@ -16,7 +16,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import layers as cv_layers diff --git a/keras_cv/src/layers/preprocessing/random_cutout.py b/keras_cv/src/layers/preprocessing/random_cutout.py index 7f93bf9ef0..b0e308bc91 100644 --- a/keras_cv/src/layers/preprocessing/random_cutout.py +++ b/keras_cv/src/layers/preprocessing/random_cutout.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501 diff --git a/keras_cv/src/layers/preprocessing/random_cutout_test.py b/keras_cv/src/layers/preprocessing/random_cutout_test.py index da060022c6..9dfce92cd3 100644 --- a/keras_cv/src/layers/preprocessing/random_cutout_test.py +++ b/keras_cv/src/layers/preprocessing/random_cutout_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops from keras_cv.src.layers import preprocessing diff --git a/keras_cv/src/layers/preprocessing/random_flip.py b/keras_cv/src/layers/preprocessing/random_flip.py index d39c1e7bb2..93764fe05e 100644 --- a/keras_cv/src/layers/preprocessing/random_flip.py +++ b/keras_cv/src/layers/preprocessing/random_flip.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/random_flip_test.py b/keras_cv/src/layers/preprocessing/random_flip_test.py index 3abac13327..fdfb24c66f 100644 --- a/keras_cv/src/layers/preprocessing/random_flip_test.py +++ b/keras_cv/src/layers/preprocessing/random_flip_test.py @@ -14,7 +14,14 @@ import unittest import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.backend import ops diff --git a/keras_cv/src/layers/preprocessing/random_gaussian_blur.py b/keras_cv/src/layers/preprocessing/random_gaussian_blur.py index e521b86fdb..7b4e4f7659 100644 --- a/keras_cv/src/layers/preprocessing/random_gaussian_blur.py +++ b/keras_cv/src/layers/preprocessing/random_gaussian_blur.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/random_gaussian_blur_test.py b/keras_cv/src/layers/preprocessing/random_gaussian_blur_test.py index 928b2b0f20..5fb2a41c21 100644 --- a/keras_cv/src/layers/preprocessing/random_gaussian_blur_test.py +++ b/keras_cv/src/layers/preprocessing/random_gaussian_blur_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import preprocessing from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/random_hue.py b/keras_cv/src/layers/preprocessing/random_hue.py index f291da7ced..e3094f77ae 100644 --- a/keras_cv/src/layers/preprocessing/random_hue.py +++ b/keras_cv/src/layers/preprocessing/random_hue.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/random_jpeg_quality.py b/keras_cv/src/layers/preprocessing/random_jpeg_quality.py index 69d4d6b227..9805f88f4a 100644 --- a/keras_cv/src/layers/preprocessing/random_jpeg_quality.py +++ b/keras_cv/src/layers/preprocessing/random_jpeg_quality.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.base_image_augmentation_layer import ( diff --git a/keras_cv/src/layers/preprocessing/random_jpeg_quality_test.py b/keras_cv/src/layers/preprocessing/random_jpeg_quality_test.py index 22a7926adc..072616e924 100644 --- a/keras_cv/src/layers/preprocessing/random_jpeg_quality_test.py +++ b/keras_cv/src/layers/preprocessing/random_jpeg_quality_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import preprocessing from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/random_rotation.py b/keras_cv/src/layers/preprocessing/random_rotation.py index 0cbf86a441..85cb6069d5 100644 --- a/keras_cv/src/layers/preprocessing/random_rotation.py +++ b/keras_cv/src/layers/preprocessing/random_rotation.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/random_rotation_test.py b/keras_cv/src/layers/preprocessing/random_rotation_test.py index 2ffecd5b3d..1d6fc93ddb 100644 --- a/keras_cv/src/layers/preprocessing/random_rotation_test.py +++ b/keras_cv/src/layers/preprocessing/random_rotation_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.backend import ops diff --git a/keras_cv/src/layers/preprocessing/random_saturation.py b/keras_cv/src/layers/preprocessing/random_saturation.py index f03b7e847f..d397bb6dfe 100644 --- a/keras_cv/src/layers/preprocessing/random_saturation.py +++ b/keras_cv/src/layers/preprocessing/random_saturation.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/random_saturation_test.py b/keras_cv/src/layers/preprocessing/random_saturation_test.py index aad13716e0..bec132f3ed 100644 --- a/keras_cv/src/layers/preprocessing/random_saturation_test.py +++ b/keras_cv/src/layers/preprocessing/random_saturation_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import core from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/random_sharpness.py b/keras_cv/src/layers/preprocessing/random_sharpness.py index c65d35d1df..2829469be6 100644 --- a/keras_cv/src/layers/preprocessing/random_sharpness.py +++ b/keras_cv/src/layers/preprocessing/random_sharpness.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.vectorized_base_image_augmentation_layer import ( # noqa: E501 diff --git a/keras_cv/src/layers/preprocessing/random_sharpness_test.py b/keras_cv/src/layers/preprocessing/random_sharpness_test.py index c83e2e157e..2163a0eca3 100644 --- a/keras_cv/src/layers/preprocessing/random_sharpness_test.py +++ b/keras_cv/src/layers/preprocessing/random_sharpness_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import preprocessing from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/preprocessing/random_shear.py b/keras_cv/src/layers/preprocessing/random_shear.py index 726b831f18..93c55bf7af 100644 --- a/keras_cv/src/layers/preprocessing/random_shear.py +++ b/keras_cv/src/layers/preprocessing/random_shear.py @@ -14,7 +14,13 @@ import warnings -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/random_shear_test.py b/keras_cv/src/layers/preprocessing/random_shear_test.py index 8876fd2729..0dee4aba0d 100644 --- a/keras_cv/src/layers/preprocessing/random_shear_test.py +++ b/keras_cv/src/layers/preprocessing/random_shear_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.backend import ops diff --git a/keras_cv/src/layers/preprocessing/random_translation.py b/keras_cv/src/layers/preprocessing/random_translation.py index 017cdb612b..ce3af2c0b0 100644 --- a/keras_cv/src/layers/preprocessing/random_translation.py +++ b/keras_cv/src/layers/preprocessing/random_translation.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/random_translation_test.py b/keras_cv/src/layers/preprocessing/random_translation_test.py index bf3786dacd..2659612f85 100644 --- a/keras_cv/src/layers/preprocessing/random_translation_test.py +++ b/keras_cv/src/layers/preprocessing/random_translation_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops from keras_cv.src.layers import preprocessing diff --git a/keras_cv/src/layers/preprocessing/random_zoom.py b/keras_cv/src/layers/preprocessing/random_zoom.py index 57100226cf..c375b459b7 100644 --- a/keras_cv/src/layers/preprocessing/random_zoom.py +++ b/keras_cv/src/layers/preprocessing/random_zoom.py @@ -13,7 +13,13 @@ # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow.keras import backend from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/random_zoom_test.py b/keras_cv/src/layers/preprocessing/random_zoom_test.py index 51b1e4d499..31a94a63d4 100644 --- a/keras_cv/src/layers/preprocessing/random_zoom_test.py +++ b/keras_cv/src/layers/preprocessing/random_zoom_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.backend import ops diff --git a/keras_cv/src/layers/preprocessing/repeated_augmentation.py b/keras_cv/src/layers/preprocessing/repeated_augmentation.py index 33f6ac7c08..3bd19f131b 100644 --- a/keras_cv/src/layers/preprocessing/repeated_augmentation.py +++ b/keras_cv/src/layers/preprocessing/repeated_augmentation.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/repeated_augmentation_test.py b/keras_cv/src/layers/preprocessing/repeated_augmentation_test.py index 2e424493da..baca82cf26 100644 --- a/keras_cv/src/layers/preprocessing/repeated_augmentation_test.py +++ b/keras_cv/src/layers/preprocessing/repeated_augmentation_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import keras_cv.src.layers as cv_layers from keras_cv.src.backend.config import keras_3 diff --git a/keras_cv/src/layers/preprocessing/rescaling.py b/keras_cv/src/layers/preprocessing/rescaling.py index aeece4df10..2fa08cc6cf 100644 --- a/keras_cv/src/layers/preprocessing/rescaling.py +++ b/keras_cv/src/layers/preprocessing/rescaling.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing.base_image_augmentation_layer import ( diff --git a/keras_cv/src/layers/preprocessing/rescaling_test.py b/keras_cv/src/layers/preprocessing/rescaling_test.py index 0e9c7294f0..9d8469231c 100644 --- a/keras_cv/src/layers/preprocessing/rescaling_test.py +++ b/keras_cv/src/layers/preprocessing/rescaling_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops from keras_cv.src.layers.preprocessing.rescaling import Rescaling diff --git a/keras_cv/src/layers/preprocessing/resizing.py b/keras_cv/src/layers/preprocessing/resizing.py index 69ae998dc2..aac723c43a 100644 --- a/keras_cv/src/layers/preprocessing/resizing.py +++ b/keras_cv/src/layers/preprocessing/resizing.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing/resizing_test.py b/keras_cv/src/layers/preprocessing/resizing_test.py index a4b606bf64..2dd654b349 100644 --- a/keras_cv/src/layers/preprocessing/resizing_test.py +++ b/keras_cv/src/layers/preprocessing/resizing_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import layers as cv_layers diff --git a/keras_cv/src/layers/preprocessing/solarization.py b/keras_cv/src/layers/preprocessing/solarization.py index 1d3a83d670..6ab518d71a 100644 --- a/keras_cv/src/layers/preprocessing/solarization.py +++ b/keras_cv/src/layers/preprocessing/solarization.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/solarization_test.py b/keras_cv/src/layers/preprocessing/solarization_test.py index f3abce6ae5..3b124e8e1c 100644 --- a/keras_cv/src/layers/preprocessing/solarization_test.py +++ b/keras_cv/src/layers/preprocessing/solarization_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.layers.preprocessing.solarization import Solarization diff --git a/keras_cv/src/layers/preprocessing/vectorized_base_image_augmentation_layer.py b/keras_cv/src/layers/preprocessing/vectorized_base_image_augmentation_layer.py index fe43515b3b..52ea96f020 100644 --- a/keras_cv/src/layers/preprocessing/vectorized_base_image_augmentation_layer.py +++ b/keras_cv/src/layers/preprocessing/vectorized_base_image_augmentation_layer.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import tree from keras_cv.src import bounding_box diff --git a/keras_cv/src/layers/preprocessing/vectorized_base_image_augmentation_layer_test.py b/keras_cv/src/layers/preprocessing/vectorized_base_image_augmentation_layer_test.py index 19805c1b5e..d785af6e72 100644 --- a/keras_cv/src/layers/preprocessing/vectorized_base_image_augmentation_layer_test.py +++ b/keras_cv/src/layers/preprocessing/vectorized_base_image_augmentation_layer_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing/with_labels_test.py b/keras_cv/src/layers/preprocessing/with_labels_test.py index cf766c8a92..179219da57 100644 --- a/keras_cv/src/layers/preprocessing/with_labels_test.py +++ b/keras_cv/src/layers/preprocessing/with_labels_test.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import layers diff --git a/keras_cv/src/layers/preprocessing/with_mixed_precision_test.py b/keras_cv/src/layers/preprocessing/with_mixed_precision_test.py index 15a8ece219..50eb3cf2b0 100644 --- a/keras_cv/src/layers/preprocessing/with_mixed_precision_test.py +++ b/keras_cv/src/layers/preprocessing/with_mixed_precision_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import layers diff --git a/keras_cv/src/layers/preprocessing/with_segmentation_masks_test.py b/keras_cv/src/layers/preprocessing/with_segmentation_masks_test.py index 466be689a1..d66b420568 100644 --- a/keras_cv/src/layers/preprocessing/with_segmentation_masks_test.py +++ b/keras_cv/src/layers/preprocessing/with_segmentation_masks_test.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.layers import preprocessing diff --git a/keras_cv/src/layers/preprocessing_3d/base_augmentation_layer_3d.py b/keras_cv/src/layers/preprocessing_3d/base_augmentation_layer_3d.py index c69f1a2ced..6b03a1bdd2 100644 --- a/keras_cv/src/layers/preprocessing_3d/base_augmentation_layer_3d.py +++ b/keras_cv/src/layers/preprocessing_3d/base_augmentation_layer_3d.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import keras diff --git a/keras_cv/src/layers/preprocessing_3d/base_augmentation_layer_3d_test.py b/keras_cv/src/layers/preprocessing_3d/base_augmentation_layer_3d_test.py index 23f94d7242..20f361067f 100644 --- a/keras_cv/src/layers/preprocessing_3d/base_augmentation_layer_3d_test.py +++ b/keras_cv/src/layers/preprocessing_3d/base_augmentation_layer_3d_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import random from keras_cv.src.layers.preprocessing_3d import base_augmentation_layer_3d diff --git a/keras_cv/src/layers/preprocessing_3d/input_format_test.py b/keras_cv/src/layers/preprocessing_3d/input_format_test.py index 20d85d0a0d..06f0e61077 100644 --- a/keras_cv/src/layers/preprocessing_3d/input_format_test.py +++ b/keras_cv/src/layers/preprocessing_3d/input_format_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.layers import preprocessing_3d diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/frustum_random_dropping_points.py b/keras_cv/src/layers/preprocessing_3d/waymo/frustum_random_dropping_points.py index 9df85ff685..a2e041a8d4 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/frustum_random_dropping_points.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/frustum_random_dropping_points.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import point_cloud from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py b/keras_cv/src/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py index 1d99e5aabe..c4bf08185c 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/frustum_random_point_feature_noise.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import point_cloud from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_dropping_points.py b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_dropping_points.py index ba13e19e37..5cdb4429de 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_dropping_points.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_dropping_points.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import random diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_flip.py b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_flip.py index 7e2bc48597..00e938ab77 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_flip.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_flip.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.bounding_box_3d import CENTER_XYZ_DXDYDZ_PHI diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_rotation.py b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_rotation.py index e21915a270..e1087229b0 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_rotation.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_rotation.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import random diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_scaling.py b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_scaling.py index 9992eae6d2..892ded2803 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_scaling.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_scaling.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import random diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_translation.py b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_translation.py index eec3b8edd0..51b790880c 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/global_random_translation.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/global_random_translation.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import random diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/group_points_by_bounding_boxes.py b/keras_cv/src/layers/preprocessing_3d/waymo/group_points_by_bounding_boxes.py index 473a85fd2e..c863a6e9a9 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/group_points_by_bounding_boxes.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/group_points_by_bounding_boxes.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.bounding_box_3d import CENTER_XYZ_DXDYDZ_PHI diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/group_points_by_bounding_boxes_test.py b/keras_cv/src/layers/preprocessing_3d/waymo/group_points_by_bounding_boxes_test.py index 66238256b7..6e0173f90f 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/group_points_by_bounding_boxes_test.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/group_points_by_bounding_boxes_test.py @@ -6,7 +6,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.preprocessing_3d import base_augmentation_layer_3d from keras_cv.src.layers.preprocessing_3d.waymo.group_points_by_bounding_boxes import ( # noqa: E501 diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/random_copy_paste.py b/keras_cv/src/layers/preprocessing_3d/waymo/random_copy_paste.py index c437d8537d..8d1b927482 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/random_copy_paste.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/random_copy_paste.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.backend import random diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/random_drop_box.py b/keras_cv/src/layers/preprocessing_3d/waymo/random_drop_box.py index 1c49ac16ef..37495062f6 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/random_drop_box.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/random_drop_box.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.layers.preprocessing_3d import base_augmentation_layer_3d diff --git a/keras_cv/src/layers/preprocessing_3d/waymo/swap_background.py b/keras_cv/src/layers/preprocessing_3d/waymo/swap_background.py index b0dfa5159f..304eb56d16 100644 --- a/keras_cv/src/layers/preprocessing_3d/waymo/swap_background.py +++ b/keras_cv/src/layers/preprocessing_3d/waymo/swap_background.py @@ -2,7 +2,13 @@ # # Licensed under the terms in https://github.com/keras-team/keras-cv/blob/master/keras_cv/layers/preprocessing_3d/waymo/LICENSE # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.api_export import keras_cv_export from keras_cv.src.bounding_box_3d import CENTER_XYZ_DXDYDZ_PHI diff --git a/keras_cv/src/layers/regularization/drop_path_test.py b/keras_cv/src/layers/regularization/drop_path_test.py index 95e59ae374..708eebd0bc 100644 --- a/keras_cv/src/layers/regularization/drop_path_test.py +++ b/keras_cv/src/layers/regularization/drop_path_test.py @@ -14,7 +14,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import DropPath from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/regularization/dropblock_2d_test.py b/keras_cv/src/layers/regularization/dropblock_2d_test.py index ef3ded658b..1ffc826135 100644 --- a/keras_cv/src/layers/regularization/dropblock_2d_test.py +++ b/keras_cv/src/layers/regularization/dropblock_2d_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.regularization.dropblock_2d import DropBlock2D from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/regularization/squeeze_excite_test.py b/keras_cv/src/layers/regularization/squeeze_excite_test.py index a0492381fa..ae81bf0f32 100644 --- a/keras_cv/src/layers/regularization/squeeze_excite_test.py +++ b/keras_cv/src/layers/regularization/squeeze_excite_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import SqueezeAndExcite2D from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/regularization/stochastic_depth_test.py b/keras_cv/src/layers/regularization/stochastic_depth_test.py index 28c061db99..f2088b4257 100644 --- a/keras_cv/src/layers/regularization/stochastic_depth_test.py +++ b/keras_cv/src/layers/regularization/stochastic_depth_test.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.regularization.stochastic_depth import StochasticDepth from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/transformer_encoder_test.py b/keras_cv/src/layers/transformer_encoder_test.py index 097983453b..d75af1ad67 100644 --- a/keras_cv/src/layers/transformer_encoder_test.py +++ b/keras_cv/src/layers/transformer_encoder_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers import TransformerEncoder from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/layers/vit_layers.py b/keras_cv/src/layers/vit_layers.py index b96f47db3b..04db6a9f57 100644 --- a/keras_cv/src/layers/vit_layers.py +++ b/keras_cv/src/layers/vit_layers.py @@ -14,7 +14,13 @@ import math -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow.keras import layers from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/layers/vit_layers_test.py b/keras_cv/src/layers/vit_layers_test.py index ab269c8403..cd21e1528c 100644 --- a/keras_cv/src/layers/vit_layers_test.py +++ b/keras_cv/src/layers/vit_layers_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.layers.vit_layers import PatchingAndEmbedding from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/losses/giou_loss_test.py b/keras_cv/src/losses/giou_loss_test.py index 5943e6a112..adecf433a0 100644 --- a/keras_cv/src/losses/giou_loss_test.py +++ b/keras_cv/src/losses/giou_loss_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.losses.giou_loss import GIoULoss from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/losses/numerical_tests/focal_loss_numerical_test.py b/keras_cv/src/losses/numerical_tests/focal_loss_numerical_test.py index 6f514cb4a2..7ea300bf19 100644 --- a/keras_cv/src/losses/numerical_tests/focal_loss_numerical_test.py +++ b/keras_cv/src/losses/numerical_tests/focal_loss_numerical_test.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from tensorflow import keras diff --git a/keras_cv/src/metrics/object_detection/box_coco_metrics.py b/keras_cv/src/metrics/object_detection/box_coco_metrics.py index fa2583418a..a1fd998721 100644 --- a/keras_cv/src/metrics/object_detection/box_coco_metrics.py +++ b/keras_cv/src/metrics/object_detection/box_coco_metrics.py @@ -16,7 +16,14 @@ import types import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import tensorflow.keras as keras from keras_cv.src import bounding_box diff --git a/keras_cv/src/metrics/object_detection/box_coco_metrics_test.py b/keras_cv/src/metrics/object_detection/box_coco_metrics_test.py index fb1252fdea..84e55550cd 100644 --- a/keras_cv/src/metrics/object_detection/box_coco_metrics_test.py +++ b/keras_cv/src/metrics/object_detection/box_coco_metrics_test.py @@ -14,7 +14,14 @@ import os import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.metrics import BoxCOCOMetrics diff --git a/keras_cv/src/models/backbones/csp_darknet/csp_darknet_backbone_presets_test.py b/keras_cv/src/models/backbones/csp_darknet/csp_darknet_backbone_presets_test.py index 230a3b8d18..573f9d34d4 100644 --- a/keras_cv/src/models/backbones/csp_darknet/csp_darknet_backbone_presets_test.py +++ b/keras_cv/src/models/backbones/csp_darknet/csp_darknet_backbone_presets_test.py @@ -14,7 +14,14 @@ """Tests for loading pretrained model presets.""" import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops from keras_cv.src.models.backbones.csp_darknet.csp_darknet_aliases import ( diff --git a/keras_cv/src/models/backbones/csp_darknet/csp_darknet_backbone_test.py b/keras_cv/src/models/backbones/csp_darknet/csp_darknet_backbone_test.py index 099db3064d..f93e4882fb 100644 --- a/keras_cv/src/models/backbones/csp_darknet/csp_darknet_backbone_test.py +++ b/keras_cv/src/models/backbones/csp_darknet/csp_darknet_backbone_test.py @@ -16,7 +16,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.backend import keras diff --git a/keras_cv/src/models/backbones/mix_transformer/mix_transformer_backbone.py b/keras_cv/src/models/backbones/mix_transformer/mix_transformer_backbone.py index 0b6ba83be0..98aef57839 100644 --- a/keras_cv/src/models/backbones/mix_transformer/mix_transformer_backbone.py +++ b/keras_cv/src/models/backbones/mix_transformer/mix_transformer_backbone.py @@ -52,47 +52,53 @@ def __init__( **kwargs, ): """A Keras model implementing the MixTransformer architecture to be - used as a backbone for the SegFormer architecture. - - References: - - [SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers](https://arxiv.org/abs/2105.15203) # noqa: E501 - - [Based on the TensorFlow implementation from DeepVision](https://github.com/DavidLandup0/deepvision/tree/main/deepvision/models/classification/mix_transformer) # noqa: E501 - - Args: - include_rescaling: bool, whether to rescale the inputs. If set - to `True`, inputs will be passed through a `Rescaling(1/255.0)` - layer. - depths: the number of transformer encoders to be used per stage in the - network - embedding_dims: the embedding dims per hierarchical stage, used as - the levels of the feature pyramid - input_shape: optional shape tuple, defaults to (None, None, 3). - input_tensor: optional Keras tensor (i.e. output of `keras.layers.Input()`) - to use as image input for the model. - - Example: - - Using the class with a `backbone`: - - ```python - import tensorflow as tf - import keras_cv - - images = np.ones(shape=(1, 96, 96, 3)) - labels = np.zeros(shape=(1, 96, 96, 1)) - backbone = keras_cv.models.MiTBackbone.from_preset("mit_b0_imagenet") - - # Evaluate model - model(images) - - # Train model - model.compile( - optimizer="adam", - loss=keras.losses.BinaryCrossentropy(from_logits=False), - metrics=["accuracy"], - ) - model.fit(images, labels, epochs=3) - ``` + used as a backbone for the SegFormer architecture. + + References: + - [SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers](https://arxiv.org/abs/2105.15203) # noqa: E501 + - [Based on the TensorFlow implementation from DeepVision](https://github.com/DavidLandup0/deepvision/tree/main/deepvision/models/classification/mix_transformer) # noqa: E501 + + Args: + include_rescaling: bool, whether to rescale the inputs. If set + to `True`, inputs will be passed through a `Rescaling(1/255.0)` + layer. + depths: the number of transformer encoders to be used per stage in the + network + embedding_dims: the embedding dims per hierarchical stage, used as + the levels of the feature pyramid + input_shape: optional shape tuple, defaults to (None, None, 3). + input_tensor: optional Keras tensor (i.e. output of `keras.layers.Input()`) + to use as image input for the model. + + Example: + + Using the class with a `backbone`: + + ```python + try: + import tensorflow as tf + except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) + import keras_cv + + images = np.ones(shape=(1, 96, 96, 3)) + labels = np.zeros(shape=(1, 96, 96, 1)) + backbone = keras_cv.models.MiTBackbone.from_preset("mit_b0_imagenet") + + # Evaluate model + model(images) + + # Train model + model.compile( + optimizer="adam", + loss=keras.losses.BinaryCrossentropy(from_logits=False), + metrics=["accuracy"], + ) + model.fit(images, labels, epochs=3) + ``` """ drop_path_rate = 0.1 dpr = [x for x in np.linspace(0.0, drop_path_rate, sum(depths))] diff --git a/keras_cv/src/models/backbones/resnet_v1/resnet_v1_backbone_test.py b/keras_cv/src/models/backbones/resnet_v1/resnet_v1_backbone_test.py index a49d16d620..9f51055df3 100644 --- a/keras_cv/src/models/backbones/resnet_v1/resnet_v1_backbone_test.py +++ b/keras_cv/src/models/backbones/resnet_v1/resnet_v1_backbone_test.py @@ -16,7 +16,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.backend import keras diff --git a/keras_cv/src/models/classification/image_classifier_test.py b/keras_cv/src/models/classification/image_classifier_test.py index d437d4f0c4..35ea430bd1 100644 --- a/keras_cv/src/models/classification/image_classifier_test.py +++ b/keras_cv/src/models/classification/image_classifier_test.py @@ -18,7 +18,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.backend import keras diff --git a/keras_cv/src/models/classification/video_classifier_test.py b/keras_cv/src/models/classification/video_classifier_test.py index ceb4ba2a48..200b4b6810 100644 --- a/keras_cv/src/models/classification/video_classifier_test.py +++ b/keras_cv/src/models/classification/video_classifier_test.py @@ -18,7 +18,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.backend import keras diff --git a/keras_cv/src/models/feature_extractor/clip/clip_processor.py b/keras_cv/src/models/feature_extractor/clip/clip_processor.py index cebbe962fa..ed6ff7b785 100644 --- a/keras_cv/src/models/feature_extractor/clip/clip_processor.py +++ b/keras_cv/src/models/feature_extractor/clip/clip_processor.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import tree from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/models/feature_extractor/clip/clip_processor_utils.py b/keras_cv/src/models/feature_extractor/clip/clip_processor_utils.py index a4467520e9..3abfdad5b6 100644 --- a/keras_cv/src/models/feature_extractor/clip/clip_processor_utils.py +++ b/keras_cv/src/models/feature_extractor/clip/clip_processor_utils.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops diff --git a/keras_cv/src/models/feature_extractor/clip/clip_tokenizer.py b/keras_cv/src/models/feature_extractor/clip/clip_tokenizer.py index 55b292618d..5ef8213672 100644 --- a/keras_cv/src/models/feature_extractor/clip/clip_tokenizer.py +++ b/keras_cv/src/models/feature_extractor/clip/clip_tokenizer.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import regex as re -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) try: import tensorflow_text as tf_text diff --git a/keras_cv/src/models/legacy/convmixer.py b/keras_cv/src/models/legacy/convmixer.py index 263807a36f..6a288b3156 100644 --- a/keras_cv/src/models/legacy/convmixer.py +++ b/keras_cv/src/models/legacy/convmixer.py @@ -19,7 +19,13 @@ - [Patches Are All You Need?](https://arxiv.org/abs/2201.09792) """ -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import layers diff --git a/keras_cv/src/models/legacy/convnext.py b/keras_cv/src/models/legacy/convnext.py index b38539e0a8..f75bd172f2 100644 --- a/keras_cv/src/models/legacy/convnext.py +++ b/keras_cv/src/models/legacy/convnext.py @@ -18,7 +18,13 @@ (CVPR 2022) """ -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import backend from tensorflow.keras import layers diff --git a/keras_cv/src/models/legacy/darknet.py b/keras_cv/src/models/legacy/darknet.py index 539a7287c5..c3a3ff4ebe 100644 --- a/keras_cv/src/models/legacy/darknet.py +++ b/keras_cv/src/models/legacy/darknet.py @@ -18,7 +18,13 @@ - [YoloV3 implementation](https://github.com/ultralytics/yolov3) """ -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import layers diff --git a/keras_cv/src/models/legacy/mlp_mixer.py b/keras_cv/src/models/legacy/mlp_mixer.py index 55ffa8c44e..1e8d9dea31 100644 --- a/keras_cv/src/models/legacy/mlp_mixer.py +++ b/keras_cv/src/models/legacy/mlp_mixer.py @@ -18,7 +18,13 @@ - [MLP-Mixer: An all-MLP Architecture for Vision](https://arxiv.org/abs/2105.01601) """ # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import backend from tensorflow.keras import layers diff --git a/keras_cv/src/models/legacy/models_test.py b/keras_cv/src/models/legacy/models_test.py index 203ac4625e..8d00d044b0 100644 --- a/keras_cv/src/models/legacy/models_test.py +++ b/keras_cv/src/models/legacy/models_test.py @@ -16,7 +16,14 @@ import os import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import backend diff --git a/keras_cv/src/models/legacy/object_detection/faster_rcnn/faster_rcnn.py b/keras_cv/src/models/legacy/object_detection/faster_rcnn/faster_rcnn.py index df5e2981b7..d9f79653dd 100644 --- a/keras_cv/src/models/legacy/object_detection/faster_rcnn/faster_rcnn.py +++ b/keras_cv/src/models/legacy/object_detection/faster_rcnn/faster_rcnn.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl import logging from tensorflow import keras diff --git a/keras_cv/src/models/legacy/object_detection/faster_rcnn/faster_rcnn_test.py b/keras_cv/src/models/legacy/object_detection/faster_rcnn/faster_rcnn_test.py index 02c57f5dad..baa0042143 100644 --- a/keras_cv/src/models/legacy/object_detection/faster_rcnn/faster_rcnn_test.py +++ b/keras_cv/src/models/legacy/object_detection/faster_rcnn/faster_rcnn_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from tensorflow import keras from tensorflow.keras import optimizers diff --git a/keras_cv/src/models/legacy/regnet.py b/keras_cv/src/models/legacy/regnet.py index 21aa55a0af..04f32243ef 100644 --- a/keras_cv/src/models/legacy/regnet.py +++ b/keras_cv/src/models/legacy/regnet.py @@ -17,7 +17,13 @@ - [Based on the Original keras.applications RegNet](https://github.com/keras-team/keras/blob/master/keras/applications/regnet.py) """ # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import backend from tensorflow.keras import layers diff --git a/keras_cv/src/models/legacy/vgg16.py b/keras_cv/src/models/legacy/vgg16.py index 0659014f54..090bf3dc8e 100644 --- a/keras_cv/src/models/legacy/vgg16.py +++ b/keras_cv/src/models/legacy/vgg16.py @@ -19,7 +19,13 @@ (ICLR 2015) """ # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import layers diff --git a/keras_cv/src/models/legacy/vgg19.py b/keras_cv/src/models/legacy/vgg19.py index 21c3739df6..37e579e64a 100644 --- a/keras_cv/src/models/legacy/vgg19.py +++ b/keras_cv/src/models/legacy/vgg19.py @@ -18,7 +18,13 @@ - [Very Deep Convolutional Networks for Large-Scale Image Recognition](https://arxiv.org/abs/1409.1556) (ICLR 2015) """ # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import layers diff --git a/keras_cv/src/models/legacy/vit.py b/keras_cv/src/models/legacy/vit.py index d89cd4fd04..12f05d2b14 100644 --- a/keras_cv/src/models/legacy/vit.py +++ b/keras_cv/src/models/legacy/vit.py @@ -19,7 +19,13 @@ (CoRR 2021) """ # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import layers diff --git a/keras_cv/src/models/legacy/weights.py b/keras_cv/src/models/legacy/weights.py index 5f93d1ba97..04462fa861 100644 --- a/keras_cv/src/models/legacy/weights.py +++ b/keras_cv/src/models/legacy/weights.py @@ -10,7 +10,13 @@ # distributed under the License is distributed on an "AS IS" BASIS, # 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 +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow.keras import utils diff --git a/keras_cv/src/models/object_detection/__internal__.py b/keras_cv/src/models/object_detection/__internal__.py index 5b3ddf912e..a54f850a5b 100644 --- a/keras_cv/src/models/object_detection/__internal__.py +++ b/keras_cv/src/models/object_detection/__internal__.py @@ -16,7 +16,14 @@ import math import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) try: import pandas as pd diff --git a/keras_cv/src/models/object_detection/__test_utils__.py b/keras_cv/src/models/object_detection/__test_utils__.py index ad795b9cbd..3f1ef2aa2c 100644 --- a/keras_cv/src/models/object_detection/__test_utils__.py +++ b/keras_cv/src/models/object_detection/__test_utils__.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import keras_cv from keras_cv.src.backend import ops diff --git a/keras_cv/src/models/object_detection/predict_utils.py b/keras_cv/src/models/object_detection/predict_utils.py index 9cd7a1bd44..9289b9130e 100644 --- a/keras_cv/src/models/object_detection/predict_utils.py +++ b/keras_cv/src/models/object_detection/predict_utils.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) try: from keras.src.utils import tf_utils diff --git a/keras_cv/src/models/object_detection/retinanet/retinanet_label_encoder.py b/keras_cv/src/models/object_detection/retinanet/retinanet_label_encoder.py index c33e5edafa..2eda323ba7 100644 --- a/keras_cv/src/models/object_detection/retinanet/retinanet_label_encoder.py +++ b/keras_cv/src/models/object_detection/retinanet/retinanet_label_encoder.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/models/object_detection/retinanet/retinanet_label_encoder_test.py b/keras_cv/src/models/object_detection/retinanet/retinanet_label_encoder_test.py index b528d42ba2..2669478ba5 100644 --- a/keras_cv/src/models/object_detection/retinanet/retinanet_label_encoder_test.py +++ b/keras_cv/src/models/object_detection/retinanet/retinanet_label_encoder_test.py @@ -14,7 +14,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import backend from keras_cv.src import layers as cv_layers diff --git a/keras_cv/src/models/object_detection/retinanet/retinanet_test.py b/keras_cv/src/models/object_detection/retinanet/retinanet_test.py index e08426b9d0..a17e1d4a11 100644 --- a/keras_cv/src/models/object_detection/retinanet/retinanet_test.py +++ b/keras_cv/src/models/object_detection/retinanet/retinanet_test.py @@ -16,7 +16,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized import keras_cv diff --git a/keras_cv/src/models/object_detection/yolo_v8/yolo_v8_label_encoder.py b/keras_cv/src/models/object_detection/yolo_v8/yolo_v8_label_encoder.py index 2fbbc8587b..134502ff5b 100644 --- a/keras_cv/src/models/object_detection/yolo_v8/yolo_v8_label_encoder.py +++ b/keras_cv/src/models/object_detection/yolo_v8/yolo_v8_label_encoder.py @@ -16,7 +16,13 @@ implementation at https://github.com/fcjian/TOOD/blob/master/mmdet/core/bbox/assigners/task_aligned_assigner.py """ # noqa: E501 -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box from keras_cv.src.api_export import keras_cv_export diff --git a/keras_cv/src/models/object_detection/yolox/binary_crossentropy.py b/keras_cv/src/models/object_detection/yolox/binary_crossentropy.py index 17a5d59e67..6cc699627c 100644 --- a/keras_cv/src/models/object_detection/yolox/binary_crossentropy.py +++ b/keras_cv/src/models/object_detection/yolox/binary_crossentropy.py @@ -15,7 +15,13 @@ import warnings -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras diff --git a/keras_cv/src/models/object_detection/yolox/layers/yolox_decoder.py b/keras_cv/src/models/object_detection/yolox/layers/yolox_decoder.py index 56e5619f0d..3f97d808ab 100644 --- a/keras_cv/src/models/object_detection/yolox/layers/yolox_decoder.py +++ b/keras_cv/src/models/object_detection/yolox/layers/yolox_decoder.py @@ -13,7 +13,13 @@ # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras import keras_cv.src.layers as cv_layers diff --git a/keras_cv/src/models/object_detection/yolox/layers/yolox_head_test.py b/keras_cv/src/models/object_detection/yolox/layers/yolox_head_test.py index 3f391ab5d3..de19dce812 100644 --- a/keras_cv/src/models/object_detection/yolox/layers/yolox_head_test.py +++ b/keras_cv/src/models/object_detection/yolox/layers/yolox_head_test.py @@ -13,7 +13,13 @@ # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from keras_cv.src.models.object_detection.yolox.layers import YoloXHead diff --git a/keras_cv/src/models/object_detection/yolox/layers/yolox_label_encoder.py b/keras_cv/src/models/object_detection/yolox/layers/yolox_label_encoder.py index 3928ee3152..15bb2f8f18 100644 --- a/keras_cv/src/models/object_detection/yolox/layers/yolox_label_encoder.py +++ b/keras_cv/src/models/object_detection/yolox/layers/yolox_label_encoder.py @@ -13,7 +13,13 @@ # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow.keras import layers from keras_cv.src import bounding_box diff --git a/keras_cv/src/models/object_detection/yolox/layers/yolox_label_encoder_test.py b/keras_cv/src/models/object_detection/yolox/layers/yolox_label_encoder_test.py index 8bc5660185..f0b8c3272c 100644 --- a/keras_cv/src/models/object_detection/yolox/layers/yolox_label_encoder_test.py +++ b/keras_cv/src/models/object_detection/yolox/layers/yolox_label_encoder_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.models.object_detection.yolox.layers import YoloXLabelEncoder from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/models/object_detection/yolox/layers/yolox_pafpn_test.py b/keras_cv/src/models/object_detection/yolox/layers/yolox_pafpn_test.py index 18484bd481..685cc121f1 100644 --- a/keras_cv/src/models/object_detection/yolox/layers/yolox_pafpn_test.py +++ b/keras_cv/src/models/object_detection/yolox/layers/yolox_pafpn_test.py @@ -13,7 +13,13 @@ # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from keras_cv.src.models.object_detection.yolox.layers import YoloXPAFPN diff --git a/keras_cv/src/models/object_detection_3d/center_pillar_backbone_test.py b/keras_cv/src/models/object_detection_3d/center_pillar_backbone_test.py index df4c303a10..9e999183c1 100644 --- a/keras_cv/src/models/object_detection_3d/center_pillar_backbone_test.py +++ b/keras_cv/src/models/object_detection_3d/center_pillar_backbone_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import keras from keras_cv.src.backend.config import keras_3 diff --git a/keras_cv/src/models/object_detection_3d/center_pillar_test.py b/keras_cv/src/models/object_detection_3d/center_pillar_test.py index 46902decc0..2b68898324 100644 --- a/keras_cv/src/models/object_detection_3d/center_pillar_test.py +++ b/keras_cv/src/models/object_detection_3d/center_pillar_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import keras from keras_cv.src.backend.config import keras_3 diff --git a/keras_cv/src/models/segmentation/basnet/basnet_test.py b/keras_cv/src/models/segmentation/basnet/basnet_test.py index 868156f82d..b9207e5a20 100644 --- a/keras_cv/src/models/segmentation/basnet/basnet_test.py +++ b/keras_cv/src/models/segmentation/basnet/basnet_test.py @@ -17,7 +17,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.backend import keras diff --git a/keras_cv/src/models/segmentation/deeplab_v3_plus/deeplab_v3_plus_test.py b/keras_cv/src/models/segmentation/deeplab_v3_plus/deeplab_v3_plus_test.py index 9170ef4f8e..2940f89231 100644 --- a/keras_cv/src/models/segmentation/deeplab_v3_plus/deeplab_v3_plus_test.py +++ b/keras_cv/src/models/segmentation/deeplab_v3_plus/deeplab_v3_plus_test.py @@ -16,7 +16,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.backend import keras diff --git a/keras_cv/src/models/segmentation/segformer/segformer_test.py b/keras_cv/src/models/segmentation/segformer/segformer_test.py index 1441847746..6a35cfba4d 100644 --- a/keras_cv/src/models/segmentation/segformer/segformer_test.py +++ b/keras_cv/src/models/segmentation/segformer/segformer_test.py @@ -16,7 +16,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import keras from keras_cv.src.backend import ops diff --git a/keras_cv/src/point_cloud/point_cloud.py b/keras_cv/src/point_cloud/point_cloud.py index f7bc0171dd..5a134534e4 100644 --- a/keras_cv/src/point_cloud/point_cloud.py +++ b/keras_cv/src/point_cloud/point_cloud.py @@ -13,7 +13,14 @@ # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.utils.resource_loader import LazySO diff --git a/keras_cv/src/point_cloud/point_cloud_test.py b/keras_cv/src/point_cloud/point_cloud_test.py index 559fa5cfd7..3222664cf7 100644 --- a/keras_cv/src/point_cloud/point_cloud_test.py +++ b/keras_cv/src/point_cloud/point_cloud_test.py @@ -16,7 +16,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src import point_cloud diff --git a/keras_cv/src/point_cloud/within_box_3d_test.py b/keras_cv/src/point_cloud/within_box_3d_test.py index 8f4ed9d786..7fa543e301 100644 --- a/keras_cv/src/point_cloud/within_box_3d_test.py +++ b/keras_cv/src/point_cloud/within_box_3d_test.py @@ -17,7 +17,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) import keras_cv from keras_cv.src.tests.test_case import TestCase diff --git a/keras_cv/src/tests/test_case.py b/keras_cv/src/tests/test_case.py index 7a388cf854..22ce4e1da7 100644 --- a/keras_cv/src/tests/test_case.py +++ b/keras_cv/src/tests/test_case.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from absl.testing import parameterized from keras_cv.src.backend import ops diff --git a/keras_cv/src/training/contrastive/contrastive_trainer.py b/keras_cv/src/training/contrastive/contrastive_trainer.py index 1538169c8d..8b46b21a0f 100644 --- a/keras_cv/src/training/contrastive/contrastive_trainer.py +++ b/keras_cv/src/training/contrastive/contrastive_trainer.py @@ -13,7 +13,13 @@ # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from keras_cv.src.utils.train import convert_inputs_to_tf_dataset diff --git a/keras_cv/src/training/contrastive/contrastive_trainer_test.py b/keras_cv/src/training/contrastive/contrastive_trainer_test.py index adde94d7e1..3e88f42f91 100644 --- a/keras_cv/src/training/contrastive/contrastive_trainer_test.py +++ b/keras_cv/src/training/contrastive/contrastive_trainer_test.py @@ -14,7 +14,14 @@ import numpy as np import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import layers from tensorflow.keras import metrics diff --git a/keras_cv/src/training/contrastive/simclr_trainer_test.py b/keras_cv/src/training/contrastive/simclr_trainer_test.py index 828c3e9e1d..a3d7e5447a 100644 --- a/keras_cv/src/training/contrastive/simclr_trainer_test.py +++ b/keras_cv/src/training/contrastive/simclr_trainer_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import layers from tensorflow.keras import optimizers diff --git a/keras_cv/src/utils/fill_utils.py b/keras_cv/src/utils/fill_utils.py index 2569feb576..0e2e732b35 100644 --- a/keras_cv/src/utils/fill_utils.py +++ b/keras_cv/src/utils/fill_utils.py @@ -11,7 +11,13 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import bounding_box diff --git a/keras_cv/src/utils/fill_utils_test.py b/keras_cv/src/utils/fill_utils_test.py index 7dd09cb14f..f5eb7963a4 100644 --- a/keras_cv/src/utils/fill_utils_test.py +++ b/keras_cv/src/utils/fill_utils_test.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.tests.test_case import TestCase from keras_cv.src.utils import fill_utils diff --git a/keras_cv/src/utils/preprocessing.py b/keras_cv/src/utils/preprocessing.py index 47470a2017..1b4ca6dd48 100644 --- a/keras_cv/src/utils/preprocessing.py +++ b/keras_cv/src/utils/preprocessing.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from tensorflow import keras from tensorflow.keras import backend diff --git a/keras_cv/src/utils/preprocessing_test.py b/keras_cv/src/utils/preprocessing_test.py index 70dd2866fa..c4e3c68ed8 100644 --- a/keras_cv/src/utils/preprocessing_test.py +++ b/keras_cv/src/utils/preprocessing_test.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.tests.test_case import TestCase from keras_cv.src.utils import preprocessing diff --git a/keras_cv/src/utils/resource_loader.py b/keras_cv/src/utils/resource_loader.py index 6813736a60..c3c5271f7f 100644 --- a/keras_cv/src/utils/resource_loader.py +++ b/keras_cv/src/utils/resource_loader.py @@ -20,7 +20,13 @@ import os import warnings -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) TF_VERSION_FOR_ABI_COMPATIBILITY = "2.13" abi_warning_already_raised = False diff --git a/keras_cv/src/utils/to_numpy.py b/keras_cv/src/utils/to_numpy.py index e2e6f96ba9..ba322de286 100644 --- a/keras_cv/src/utils/to_numpy.py +++ b/keras_cv/src/utils/to_numpy.py @@ -12,7 +12,14 @@ # See the License for the specific language governing permissions and # limitations under the License. import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import ops diff --git a/keras_cv/src/utils/train.py b/keras_cv/src/utils/train.py index 7091f4ad64..1019e2360a 100644 --- a/keras_cv/src/utils/train.py +++ b/keras_cv/src/utils/train.py @@ -12,7 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -import tensorflow as tf +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src.backend import keras diff --git a/keras_cv/src/version_check_test.py b/keras_cv/src/version_check_test.py index ea116871a3..ff3b964e91 100644 --- a/keras_cv/src/version_check_test.py +++ b/keras_cv/src/version_check_test.py @@ -13,7 +13,14 @@ # limitations under the License. import pytest -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import version_check diff --git a/keras_cv/src/visualization/plot_image_gallery.py b/keras_cv/src/visualization/plot_image_gallery.py index 8038286d48..30c51e88ac 100644 --- a/keras_cv/src/visualization/plot_image_gallery.py +++ b/keras_cv/src/visualization/plot_image_gallery.py @@ -15,7 +15,14 @@ import math import numpy as np -import tensorflow as tf + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "To use KerasCV, please install TensorFlow: `pip install tensorflow`. " + "The TensorFlow package is required for data preprocessing with any backend." + ) from keras_cv.src import utils from keras_cv.src.api_export import keras_cv_export