A package for visualizing the prompt-image feature matching in ViT-based CLIP models, highlighting the alignment between image features and textual prompts.
Project description
clip_cam
clip_cam is a Python package for visualizing the image-prompt feature matching in ViT-based CLIP models, highlighting the alignment between image features and textual prompts. It allows you to visualize how CLIP interprets the relationship between an image and a text description, providing insights into its attention patterns.
🚀 Features
- Generate Grad-CAM-style heatmaps for image-text matching.
- Support for Vision Transformer (ViT) architectures.
- Easy integration with existing CLIP implementations.
- Custom checkpoint support for fine-tuned models.
📦 Installation
You can install clip_cam via pip:
pip install clip_cam
🔥 Usage
Run the following command to generate a visualization:
python clip_cam.py --model_name "ViT-B/16" --image_path "path/to/image.jpg" --text "your text prompt"
Arguments:
--image_path: Path to the input image.--text: Text input/prompt.--model_name: CLIP model name (default:ViT-B/16).--checkpoint: (Optional) Path to a fine-tuned CLIP model checkpoint.
Example:
python clip_cam.py --model_name "ViT-B/16" --image_path "cat.jpg" --text "a cute kitten"
🛠️ How It Works
- Model Loading: Uses the specified CLIP model with optional fine-tuned checkpoint.
- Feature Extraction:
- Extracts dense visual features from the image.
- Encodes the text prompt and normalizes the embeddings.
- Matching & Visualization:
- Computes image-text matching scores.
- Resizes the matching map using bilinear interpolation.
- Visualizes the results generating a heatmap of image-text matching.
🔥 Example Visualization
Example visualization showing attention heatmap over the image for the provided text prompt.
📜 License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clip_cam-0.1.5.tar.gz.
File metadata
- Download URL: clip_cam-0.1.5.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98a014ccd6139353d82350853599901895cde1c2d716e196921551dc7564a36c
|
|
| MD5 |
26dc239f780e2022245e16610afd8820
|
|
| BLAKE2b-256 |
4aff8099e0e3709ec5fc7d000dbb7805bbed03fedfac08ac232dc5888e4e492c
|
File details
Details for the file clip_cam-0.1.5-py3-none-any.whl.
File metadata
- Download URL: clip_cam-0.1.5-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2acbf23d782f597d983fab25256329bd9282395664b0f39a1a79c29d00b7cf2
|
|
| MD5 |
5dfc56201be9b6e33c79843029b5adf5
|
|
| BLAKE2b-256 |
a37b9470ef7cdb9bce9e9ec7cdebe8e9418076f8c3dfc6738bbf92b5baaf6d64
|