Skip to content

Commit 15db57c

Browse files
Add CLIP to KerasCV (#2331)
* clip refactor * code cleanup and reformat * update encoder name * update clip encoder name * update clip encoder name in image encoder * add weights conversion script * update setup to install keras-nlp * new black formatting * add preset file * update array * update clip prests kaggle handle * update text model * update text encoder * update position embeddings * update positonal embeddings * add attention masks * update expanded mask * revert previous commit * change causal masks * undo previous commit * update attention masks * update clip encoder * add print statements * update the pooler output * remove print statements * add tests and preset * cleanup and reformat * update build * add copywrite to presets file * fix build state errors * update github actions and add preprocessor test * incorporate review comments * add modifications from review * change import checks * update keras_nlp import check * update kokoro tests * update kaggle preset version * update install instructions for keras-nlp --------- Co-authored-by: Divyashree Sreepathihalli <divyashreepathihalli>
1 parent 0f9e34d commit 15db57c

File tree

15 files changed

+2408
-1
lines changed

15 files changed

+2408
-1
lines changed

.github/workflows/actions.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ jobs:
3838
pip install torch>=2.0.1+cpu
3939
pip install "jax[cpu]"
4040
pip install keras-core
41+
pip install keras-nlp-nightly --no-deps
42+
pip install tensorflow-text==2.15
4143
pip install -e ".[tests]" --progress-bar off --upgrade
4244
- name: Test with pytest
4345
env:
@@ -75,6 +77,7 @@ jobs:
7577
run: |
7678
pip install -r requirements.txt
7779
pip install -e ".[tests]" --progress-bar off --upgrade
80+
pip install keras-nlp-nightly
7881
- name: Test with pytest
7982
env:
8083
TEST_CUSTOM_OPS: false # TODO(ianstenbit): test custom ops, or figure out what our story is here

.kokoro/github/ubuntu/gpu/build.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,26 @@ then
2929
pip install --extra-index-url https://download.pytorch.org/whl/cpu torch==2.1.0+cpu
3030
pip install torchvision~=0.16.0
3131
pip install "jax[cpu]"
32+
pip install keras-nlp-nightly --no-deps
33+
pip install tensorflow-text==2.15
3234

3335
elif [ "$KERAS_BACKEND" == "tensorflow" ]
3436
then
3537
echo "TensorFlow backend detected."
3638
pip install -r requirements-tensorflow-cuda.txt --progress-bar off
39+
pip install keras-nlp-nightly
3740

3841
elif [ "$KERAS_BACKEND" == "jax" ]
3942
then
4043
echo "JAX backend detected."
4144
pip install -r requirements-jax-cuda.txt --progress-bar off
45+
pip install keras-nlp-nightly
4246

4347
elif [ "$KERAS_BACKEND" == "torch" ]
4448
then
4549
echo "PyTorch backend detected."
4650
pip install -r requirements-torch-cuda.txt --progress-bar off
51+
pip install keras-nlp-nightly
4752
fi
4853

4954
pip install --no-deps -e "." --progress-bar off

keras_cv/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@
183183
from keras_cv.models.backbones.vit_det.vit_det_aliases import ViTDetLBackbone
184184
from keras_cv.models.backbones.vit_det.vit_det_backbone import ViTDetBackbone
185185
from keras_cv.models.classification.image_classifier import ImageClassifier
186+
from keras_cv.models.feature_extractor.clip import CLIP
186187
from keras_cv.models.object_detection.retinanet.retinanet import RetinaNet
187188
from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone import (
188189
YOLOV8Backbone,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2023 The KerasCV Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2023 The KerasCV Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from keras_cv.models.feature_extractor.clip.clip_image_model import (
16+
CLIPImageEncoder,
17+
)
18+
from keras_cv.models.feature_extractor.clip.clip_model import CLIP
19+
from keras_cv.models.feature_extractor.clip.clip_processor import CLIPProcessor
20+
from keras_cv.models.feature_extractor.clip.clip_text_model import (
21+
CLIPTextEncoder,
22+
)
23+
from keras_cv.models.feature_extractor.clip.clip_tokenizer import CLIPTokenizer

0 commit comments

Comments
 (0)