Skip to main content

Package for calculating Clip Score using PyTorch

Project description

PyPI

CLIP score for PyTorch

This repository provides a batch-wise quick processing for calculating CLIP scores. The project structure is adapted from (pytorch-fid)[https://github.com/mseitzer/pytorch-fid] and (CLIP)[https://github.com/openai/CLIP].

The CLIP Score measures the Cosine Similarity between two embedded features. This repository utilizes the pretrained (CLIP Model)[https://github.com/openai/CLIP] to calculate the mean average of cosine similarities between two modalities.

Installation

Install from pip:

pip install clip-score

Requirements:

  • python3
  • pytorch
  • torchvision
  • pillow
  • numpy

Usage

We assume that the image and the text data are contained in two individual folders. What's more, there is the same name of each sample in two modalities. To compute the CLIP score between images and texts:

python -m clip_score path/to/image path/to/text

To run the evaluation on GPU, use the flag --device cuda:N, where N is the index of the GPU to use.

To measure the CLIP Score within image-image or text-text:

In case you would like to calculate the CLIP score in the same modality, the folder structure should follow the upper usage case. Besides, you need to specify the prefered modalities by --real_flag and --fake_flag. --real_flag refers to the modality of the former path and the --fake_flag refers to the later. The default settins are --real_flag=img and --fake_flag=txt. For example:

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: FID 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clip-score-0.1.0.tar.gz (10.4 kB view hashes)

Uploaded Source

Built Distribution

clip_score-0.1.0-py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page