Skip to content

Commit

Permalink
Add CLIP to KerasCV (#2331)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
divyashreepathihalli authored Feb 22, 2024
1 parent 0f9e34d commit 15db57c
Show file tree
Hide file tree
Showing 15 changed files with 2,408 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
pip install torch>=2.0.1+cpu
pip install "jax[cpu]"
pip install keras-core
pip install keras-nlp-nightly --no-deps
pip install tensorflow-text==2.15
pip install -e ".[tests]" --progress-bar off --upgrade
- name: Test with pytest
env:
Expand Down Expand Up @@ -75,6 +77,7 @@ jobs:
run: |
pip install -r requirements.txt
pip install -e ".[tests]" --progress-bar off --upgrade
pip install keras-nlp-nightly
- name: Test with pytest
env:
TEST_CUSTOM_OPS: false # TODO(ianstenbit): test custom ops, or figure out what our story is here
Expand Down
5 changes: 5 additions & 0 deletions .kokoro/github/ubuntu/gpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,26 @@ then
pip install --extra-index-url https://download.pytorch.org/whl/cpu torch==2.1.0+cpu
pip install torchvision~=0.16.0
pip install "jax[cpu]"
pip install keras-nlp-nightly --no-deps
pip install tensorflow-text==2.15

elif [ "$KERAS_BACKEND" == "tensorflow" ]
then
echo "TensorFlow backend detected."
pip install -r requirements-tensorflow-cuda.txt --progress-bar off
pip install keras-nlp-nightly

elif [ "$KERAS_BACKEND" == "jax" ]
then
echo "JAX backend detected."
pip install -r requirements-jax-cuda.txt --progress-bar off
pip install keras-nlp-nightly

elif [ "$KERAS_BACKEND" == "torch" ]
then
echo "PyTorch backend detected."
pip install -r requirements-torch-cuda.txt --progress-bar off
pip install keras-nlp-nightly
fi

pip install --no-deps -e "." --progress-bar off
Expand Down
1 change: 1 addition & 0 deletions keras_cv/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
from keras_cv.models.backbones.vit_det.vit_det_aliases import ViTDetLBackbone
from keras_cv.models.backbones.vit_det.vit_det_backbone import ViTDetBackbone
from keras_cv.models.classification.image_classifier import ImageClassifier
from keras_cv.models.feature_extractor.clip import CLIP
from keras_cv.models.object_detection.retinanet.retinanet import RetinaNet
from keras_cv.models.object_detection.yolo_v8.yolo_v8_backbone import (
YOLOV8Backbone,
Expand Down
13 changes: 13 additions & 0 deletions keras_cv/models/feature_extractor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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
# limitations under the License.
23 changes: 23 additions & 0 deletions keras_cv/models/feature_extractor/clip/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 The KerasCV Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# 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
# limitations under the License.

from keras_cv.models.feature_extractor.clip.clip_image_model import (
CLIPImageEncoder,
)
from keras_cv.models.feature_extractor.clip.clip_model import CLIP
from keras_cv.models.feature_extractor.clip.clip_processor import CLIPProcessor
from keras_cv.models.feature_extractor.clip.clip_text_model import (
CLIPTextEncoder,
)
from keras_cv.models.feature_extractor.clip.clip_tokenizer import CLIPTokenizer
Loading

0 comments on commit 15db57c

Please sign in to comment.