| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is a minimal implementation of the CLIP model proposed by OpenAI, using PyTorch. For all the gory
details: Learning Transferable Visual Models From Natural Language
Supervision
Attention maps adapted for ViT by following: Quantifying Attention Flow in Transformers
SigLIP loss from: Sigmoid Loss for Language Image Pre-Training
The main idea behind CLIP is to map different modalities (e.g. images and their corresponding captions) into a common vector space. By doing so, the model learns to align semantically similar pairs (e.g. an image and its accurate description) while pushing away those that don’t match. This alignment is achieved by using a similarity matrix: the diagonal elements (representing matching pairs) are being forced via the loss function to have high similarity, while off-diagonal elements (representing non-matching pairs) are forced to have low similarity. (See animation below for a visual explanation.)
Practically speaking, CLIP leverages the information-rich features extracted from the transformers to capture the underlying semantics of each modality. In this implementation, I use a Vision Transformer (ViT) for processing images and a BERT-uncased model for handling text. Together with the similarity matrix, these transformer encoders allow the model to generalize across a diverse set of features. This method isn’t limited to images and text, it can be extended to other modalities, such as speech paired with text.
This model can be trained as follows:
CLIP is capable of:
git clone https://github.com/ntat/Lightweight_CLIP_model.gitpip install -r requirements.txtpython main.py accelerate launch --num_processes <N> main.py sbatch multi_node.shAll results were obtained using the standard clip loss function. A trivial hyperparameter sweep was performed. Always adjust learning rates accordingly when you increase or decrease the number of GPUs.
Top-5 images retrieved from the test set given a text prompt.
More results in retrieval_result_pics folder.
We pick 5 pictures at random from the test set, and perform 0-shot classification.
More results in zero_shot_classification_results folder.
| Back | FazBrowse Home | New Git URL |