Package for calculating CLIP-Score using PyTorch
Project description
CLIP Score for PyTorch
This repository provides a batch-wise quick processing for calculating CLIP scores. It uses the pretrained CLIP model to measure the cosine similarity between two modalities. The project structure is adapted from pytorch-fid and CLIP.
Installation
Requirements:
- Install PyTorch:
pip install torch # Choose a version that suits your GPU
- Install CLIP:
pip install git+https://github.com/openai/CLIP.git
- Install clip-score from PyPI:
pip install clip-score
Usage
To compute the CLIP score between images and texts, make sure that the image and text data are contained in two separate folders, and each sample has the same name in both modalities. Run the following command:
python -m clip_score path/to/image path/to/text
To run the evaluation on a GPU, use the --device cuda:N
flag, where N
is the index of the GPU to use.
Computing CLIP Score within the Same Modality
If you want to calculate the CLIP score within the same modality (e.g., image-image or text-text), follow the same folder structure as mentioned above. Additionally, specify the preferred modalities using the --real_flag
and --fake_flag
options. By default, --real_flag=img
and --fake_flag=txt
. Examples:
python -m clip_score path/to/imageA path/to/imageB --real_flag img --fake_flag img
python -m clip_score path/to/textA path/to/textB --real_flag txt --fake_flag txt
Citing
If you use this repository in your research, consider citing it using the following Bibtex entry:
@misc{taited2023CLIPScore,
author={SUN Zhengwentai},
title={{clip-score: CLIP Score for PyTorch}},
month={March},
year={2023},
note={Version 0.1.0},
howpublished={\url{https://github.com/taited/clip-score}},
}
License
This implementation is licensed under the Apache License 2.0.
The project structure is adapted from mseitzer's pytorch-fid project. The CLIP model is adapted from OpenAI's CLIP.
The CLIP Score was introduced in OpenAI's Learning Transferable Visual Models From Natural Language Supervision.
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
File details
Details for the file clip-score-0.1.1.tar.gz
.
File metadata
- Download URL: clip-score-0.1.1.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb24fdbd30dc45d1fa989b4509bd906ec536519c593bf64f0a92ba1cc5757811 |
|
MD5 | 218d6a9760aab3308da4f3028d771d61 |
|
BLAKE2b-256 | 53147e970ca2ff092a4fdae1296c82feb511c3e7e6c168986e8ce28131f9161a |