From e920d0ee3ba92f94e8b22a976eccf06d197d2fb7 Mon Sep 17 00:00:00 2001 From: Divyashree Sreepathihalli Date: Tue, 19 Mar 2024 13:27:00 +0000 Subject: [PATCH 1/3] fix nlp import --- .../models/feature_extractor/clip/clip_processor.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/keras_cv/models/feature_extractor/clip/clip_processor.py b/keras_cv/models/feature_extractor/clip/clip_processor.py index 80e616cc02..d6f21c2a8d 100644 --- a/keras_cv/models/feature_extractor/clip/clip_processor.py +++ b/keras_cv/models/feature_extractor/clip/clip_processor.py @@ -11,8 +11,11 @@ # 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. -from keras_nlp.layers import StartEndPacker +try: + from keras_nlp.layers import StartEndPacker +except ImportError: + keras_nlp = None from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.backend import ops @@ -45,6 +48,11 @@ class CLIPProcessor: """ def __init__(self, input_resolution, vocabulary, merges, **kwargs): + if keras_nlp is None: + raise ValueError( + "ClipTokenizer requires keras-nlp. Please install " + "using pip `pip install -U keras-nlp && pip install -U keras`" + ) self.input_resolution = input_resolution self.vocabulary = vocabulary self.merges = merges From c6256cd3e7acf94ac570c16147c2e74435e00d9c Mon Sep 17 00:00:00 2001 From: Divyashree Sreepathihalli Date: Tue, 19 Mar 2024 13:52:39 +0000 Subject: [PATCH 2/3] update import format --- keras_cv/models/feature_extractor/clip/clip_processor.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/keras_cv/models/feature_extractor/clip/clip_processor.py b/keras_cv/models/feature_extractor/clip/clip_processor.py index d6f21c2a8d..8020c17cb9 100644 --- a/keras_cv/models/feature_extractor/clip/clip_processor.py +++ b/keras_cv/models/feature_extractor/clip/clip_processor.py @@ -12,15 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from keras_nlp.layers import StartEndPacker -except ImportError: - keras_nlp = None from keras_cv.api_export import keras_cv_export from keras_cv.backend import keras from keras_cv.backend import ops from keras_cv.models.feature_extractor.clip.clip_tokenizer import CLIPTokenizer +try: + from keras_nlp.layers import StartEndPacker +except ImportError: + keras_nlp = None + @keras_cv_export("keras_cv.models.feature_extractors.CLIPProcessor") class CLIPProcessor: From 277b83e403e98adac1ce1a1485d6bfd4fa1eff85 Mon Sep 17 00:00:00 2001 From: Divyashree Sreepathihalli Date: Tue, 19 Mar 2024 14:08:56 +0000 Subject: [PATCH 3/3] update import --- keras_cv/models/feature_extractor/clip/clip_processor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/keras_cv/models/feature_extractor/clip/clip_processor.py b/keras_cv/models/feature_extractor/clip/clip_processor.py index 8020c17cb9..0d33f5b4da 100644 --- a/keras_cv/models/feature_extractor/clip/clip_processor.py +++ b/keras_cv/models/feature_extractor/clip/clip_processor.py @@ -18,6 +18,7 @@ from keras_cv.models.feature_extractor.clip.clip_tokenizer import CLIPTokenizer try: + import keras_nlp from keras_nlp.layers import StartEndPacker except ImportError: keras_nlp = None