Run this model with HF Jobs
Run keras/clip_vit_large_patch14 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/keras/clip_vit_large_patch14. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/keras/clip_vit_large_patch14 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use keras/clip_vit_large_patch14 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- KerasHub
How to use keras/clip_vit_large_patch14 with KerasHub:
import keras_hub # Create a Backbone model unspecialized for any task backbone = keras_hub.models.Backbone.from_preset("hf://keras/clip_vit_large_patch14") - Keras
How to use keras/clip_vit_large_patch14 with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://keras/clip_vit_large_patch14") - Notebooks
- Google Colab
- Kaggle
Update README.md with new model card content
Browse files10 unmodified lines11121314151617181920212223242526277 unmodified lines353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868710 unmodified lines## Links* [CLIP Quickstart Notebook](https://www.kaggle.com/code/divyasss/clip-quickstart-single-shot-classification)* [CLIP API Documentation](https://keras.io/api/keras_cv/models/clip/)* [CLIP Model Card](https://huggingface.co/docs/transformers/en/model_doc/clip)## InstallationKeras and KerasCV can be installed with:```pip install -U -q keras-cvpip install -U -q keras>=3```Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the [Keras Getting Started](https://keras.io/getting_started/) page.7 unmodified lines| clip-vit-base-patch32 | 151.28M | The model uses a ViT-B/32 Transformer architecture as an image encoder and uses a masked self-attention Transformer as a text encoder. These encoders are trained to maximize the similarity of (image, text) pairs via a contrastive loss.The model uses a patch size of 32 and input images of size (224, 224) || clip-vit-large-patch14 | 427.62M | The model uses a ViT-L/14 Transformer architecture as an image encoder and uses a masked self-attention Transformer as a text encoder. These encoders are trained to maximize the similarity of (image, text) pairs via a contrastive loss.The model uses a patch size of 14 and input images of size (224, 224) || clip-vit-large-patch14-336 | 427.94M | The model uses a ViT-L/14 Transformer architecture as an image encoder and uses a masked self-attention Transformer as a text encoder. These encoders are trained to maximize the similarity of (image, text) pairs via a contrastive loss.The model uses a patch size of 14 and input images of size (336, 336) |## Example code```from keras import opsimport kerasfrom keras_cv.models.feature_extractor.clip import CLIPProcessorfrom keras_cv.models import CLIPprocessor = CLIPProcessor("vocab.json", "merges.txt")# processed_image = transform_image("cat.jpg", 224)tokens = processor(["mountains", "cat on tortoise", "house"])model = CLIP.from_preset("clip-vit-base-patch32")output = model({"images": processed_image,"token_ids": tokens['token_ids'],"padding_mask": tokens['padding_mask']})# optional if you need to pre process imagedef transform_image(image_path, input_resolution):mean = ops.array([0.48145466, 0.4578275, 0.40821073])std = ops.array([0.26862954, 0.26130258, 0.27577711])image = keras.utils.load_img(image_path)image = keras.utils.img_to_array(image)image = (ops.image.resize(image,(input_resolution, input_resolution),interpolation="bicubic",)/ 255.0)central_fraction = input_resolution / image.shape[0]width, height = image.shape[0], image.shape[1]left = ops.cast((width - width * central_fraction) / 2, dtype="int32")top = ops.cast((height - height * central_fraction) / 2, dtype="int32")right = ops.cast((width + width * central_fraction) / 2, dtype="int32")bottom = ops.cast((height + height * central_fraction) / 2, dtype="int32")image = ops.slice(image, [left, top, 0], [right - left, bottom - top, 3])image = (image - mean) / stdreturn ops.expand_dims(image, axis=0)```10 unmodified lines11121314151617181920212223242526272829307 unmodified lines383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110 unmodified lines## Links* [CLIP Quickstart Notebook](https://www.kaggle.com/code/laxmareddypatlolla/clip-quickstart-notebook)* [CLIP API Documentation](https://keras.io/keras_hub/api/models/clip/)* [CLIP Model Card](https://huggingface.co/docs/transformers/en/model_doc/clip)* [KerasHub Beginner Guide](https://keras.io/guides/keras_hub/getting_started/)* [KerasHub Model Publishing Guide](https://keras.io/guides/keras_hub/upload/)## InstallationKeras and KerasHub can be installed with:```pip install -U -q keras-hubpip install -U -q keras```Jax, TensorFlow, and Torch come preinstalled in Kaggle Notebooks. For instructions on installing them in another environment see the [Keras Getting Started](https://keras.io/getting_started/) page.7 unmodified lines| clip-vit-base-patch32 | 151.28M | The model uses a ViT-B/32 Transformer architecture as an image encoder and uses a masked self-attention Transformer as a text encoder. These encoders are trained to maximize the similarity of (image, text) pairs via a contrastive loss.The model uses a patch size of 32 and input images of size (224, 224) || clip-vit-large-patch14 | 427.62M | The model uses a ViT-L/14 Transformer architecture as an image encoder and uses a masked self-attention Transformer as a text encoder. These encoders are trained to maximize the similarity of (image, text) pairs via a contrastive loss.The model uses a patch size of 14 and input images of size (224, 224) || clip-vit-large-patch14-336 | 427.94M | The model uses a ViT-L/14 Transformer architecture as an image encoder and uses a masked self-attention Transformer as a text encoder. These encoders are trained to maximize the similarity of (image, text) pairs via a contrastive loss.The model uses a patch size of 14 and input images of size (336, 336) || clip_vit_b_32_laion2b_s34b_b79k | 151.28M | 151 million parameter, 12-layer for vision and 12-layer for text, patch size of 32, Open CLIP model. || clip_vit_h_14_laion2b_s32b_b79k | 986.11M | 986 million parameter, 32-layer for vision and 24-layer for text, patch size of 14, Open CLIP model. || clip_vit_g_14_laion2b_s12b_b42k | 1.37B | 1.4 billion parameter, 40-layer for vision and 24-layer for text, patch size of 14, Open CLIP model. || clip_vit_bigg_14_laion2b_39b_b160k | 2.54B | 2.5 billion parameter, 48-layer for vision and 32-layer for text, patch size of 14, Open CLIP model. |## Example Usage```pythonimport kerasimport numpy as npimport matplotlib.pyplot as pltfrom keras_hub.models import CLIPBackbone, CLIPTokenizerfrom keras_hub.layers import CLIPImageConverter# instantiate the model and preprocessing toolsclip = CLIPBackbone.from_preset("clip_vit_large_patch14")tokenizer = CLIPTokenizer.from_preset("clip_vit_large_patch14",sequence_length=5)image_converter = CLIPImageConverter.from_preset("clip_vit_large_patch14")# obtain tokens for some input texttokens = tokenizer.tokenize(["mountains", "cat on tortoise", "house"])# preprocess image and textimage = keras.utils.load_img("cat.jpg")image = image_converter(np.array([image]).astype(float))# query the model for similaritiesclip({"images": image,"token_ids": tokens,})```## Example Usage with Hugging Face URI```pythonimport kerasimport numpy as npimport matplotlib.pyplot as pltfrom keras_hub.models import CLIPBackbone, CLIPTokenizerfrom keras_hub.layers import CLIPImageConverter# instantiate the model and preprocessing toolsclip = CLIPBackbone.from_preset("hf://keras/clip_vit_large_patch14")tokenizer = CLIPTokenizer.from_preset("hf://keras/clip_vit_large_patch14",sequence_length=5)image_converter = CLIPImageConverter.from_preset("hf://keras/clip_vit_large_patch14")# obtain tokens for some input texttokens = tokenizer.tokenize(["mountains", "cat on tortoise", "house"])# preprocess image and textimage = keras.utils.load_img("cat.jpg")image = image_converter(np.array([image]).astype(float))# query the model for similaritiesclip({"images": image,"token_ids": tokens,})```
README.md+65-51