Skip to content

Commit e21312a

Browse files
Fix nlp import (#2396)
* fix nlp import * update import format * update import --------- Co-authored-by: Divyashree Sreepathihalli <divyashreepathihalli>
1 parent fb05c82 commit e21312a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

keras_cv/models/feature_extractor/clip/clip_processor.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14-
from keras_nlp.layers import StartEndPacker
1514

1615
from keras_cv.api_export import keras_cv_export
1716
from keras_cv.backend import keras
1817
from keras_cv.backend import ops
1918
from keras_cv.models.feature_extractor.clip.clip_tokenizer import CLIPTokenizer
2019

20+
try:
21+
import keras_nlp
22+
from keras_nlp.layers import StartEndPacker
23+
except ImportError:
24+
keras_nlp = None
25+
2126

2227
@keras_cv_export("keras_cv.models.feature_extractor.CLIPProcessor")
2328
class CLIPProcessor:
@@ -45,6 +50,11 @@ class CLIPProcessor:
4550
"""
4651

4752
def __init__(self, input_resolution, vocabulary, merges, **kwargs):
53+
if keras_nlp is None:
54+
raise ValueError(
55+
"ClipTokenizer requires keras-nlp. Please install "
56+
"using pip `pip install -U keras-nlp && pip install -U keras`"
57+
)
4858
self.input_resolution = input_resolution
4959
self.vocabulary = vocabulary
5060
self.merges = merges

0 commit comments

Comments
 (0)