ランキングに戻る

pharmapsychotic/clip-interrogator

Python

Image to prompt with BLIP and CLIP

clippytorch
スター成長
スター
3k
フォーク
430
週間成長
Issue
54
1k2k
2022年8月2023年11月2025年3月2026年7月
成果物PyPIpip install clip-interrogator
README

clip-interrogator

Want to figure out what a good prompt might be to create new images like an existing one? The CLIP Interrogator is here to get you answers!

Run it!

🆕 Now available as a Stable Diffusion Web UI Extension! 🆕


Run Version 2 on Colab, HuggingFace, and Replicate!

Open In Colab Generic badge Replicate Lambda


Version 1 still available in Colab for comparing different CLIP models

Open In Colab

About

The CLIP Interrogator is a prompt engineering tool that combines OpenAI's CLIP and Salesforce's BLIP to optimize text prompts to match a given image. Use the resulting prompts with text-to-image models like Stable Diffusion on DreamStudio to create cool art!

Using as a library

Create and activate a Python virtual environment

python3 -m venv ci_env
(for linux  ) source ci_env/bin/activate
(for windows) .\ci_env\Scripts\activate

Install with PIP

# install torch with GPU support for example:
pip3 install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu117

# install clip-interrogator
pip install clip-interrogator==0.5.4

# or for very latest WIP with BLIP2 support
#pip install clip-interrogator==0.6.0

You can then use it in your script

from PIL import Image
from clip_interrogator import Config, Interrogator
image = Image.open(image_path).convert('RGB')
ci = Interrogator(Config(clip_model_name="ViT-L-14/openai"))
print(ci.interrogate(image))

CLIP Interrogator uses OpenCLIP which supports many different pretrained CLIP models. For the best prompts for Stable Diffusion 1.X use ViT-L-14/openai for clip_model_name. For Stable Diffusion 2.0 use ViT-H-14/laion2b_s32b_b79k

Configuration

The Config object lets you configure CLIP Interrogator's processing.

  • clip_model_name: which of the OpenCLIP pretrained CLIP models to use
  • cache_path: path where to save precomputed text embeddings
  • download_cache: when True will download the precomputed embeddings from huggingface
  • chunk_size: batch size for CLIP, use smaller for lower VRAM
  • quiet: when True no progress bars or text output will be displayed

On systems with low VRAM you can call config.apply_low_vram_defaults() to reduce the amount of VRAM needed (at the cost of some speed and quality). The default settings use about 6.3GB of VRAM and the low VRAM settings use about 2.7GB.

See the run_cli.py and run_gradio.py for more examples on using Config and Interrogator classes.

Ranking against your own list of terms (requires version 0.6.0)

from clip_interrogator import Config, Interrogator, LabelTable, load_list
from PIL import Image

ci = Interrogator(Config(blip_model_type=None))
image = Image.open(image_path).convert('RGB')
table = LabelTable(load_list('terms.txt'), 'terms', ci)
best_match = table.rank(ci.image_to_features(image), top_count=1)[0]
print(best_match)
関連リポジトリ
CVHub520/X-AnyLabeling

Effortless data labeling with AI support from Segment Anything and other awesome models.

PythonPyPIGNU General Public License v3.0samyolo
github.com/CVHub520/X-AnyLabeling-Server
9.8k1.1k
OFA-Sys/Chinese-CLIP

Chinese version of CLIP which achieves Chinese cross-modal retrieval and representation generation.

Jupyter NotebookMIT Licensechinesecomputer-vision
6k549
easychen/pushdeer

开放源码的无App推送服务,iOS14+扫码即用。亦支持快应用/iOS和Mac客户端、Android客户端、自制设备

COtherapppush
5k514
open-compass/VLMEvalKit

Open-source evaluation toolkit of large multi-modality models (LMMs), support 220+ LMMs, 80+ benchmarks

PythonPyPIApache License 2.0gpt-4vlarge-language-models
huggingface.co/spaces/opencompass/open_vlm_leaderboard
4.3k736
open-mmlab/mmpretrain

OpenMMLab Pre-training Toolbox and Benchmark

PythonPyPIApache License 2.0image-classificationresnet
mmpretrain.readthedocs.io/en/latest/
3.8k1.1k
yuanzhoulvpi2017/zero_nlp

中文nlp解决方案(大模型、数据、模型、训练、推理)

Jupyter NotebookMIT Licensebertnlp
3.8k443
jingyi0000/VLM_survey

Collection of AWESOME vision-language models for vision tasks

computer-visiondeep-learning
3.1k233
rom1504/clip-retrieval

Easily compute clip embeddings and build a clip retrieval system with them

Jupyter NotebookMIT Licensesemantic-searchdeep-learning
rom1504.github.io/clip-retrieval/
2.8k240
QIN2DIM/hcaptcha-challenger

🥂 Gracefully face hCaptcha challenge with multimodal large language model.

PythonPyPIGNU General Public License v3.0hcaptchahcaptcha-solver
2.4k435
cambrian-mllm/cambrian

Cambrian-1 is a family of multimodal LLMs with a vision-centric design.

PythonPyPIApache License 2.0chatbotclip
cambrian-mllm.github.io
2k139
RuffianZhong/RWidgetHelper

Android UI 快速开发,专治原生控件各种不服

JavaMavenstateselector
2k181
roboflow/awesome-openai-vision-api-experiments

Must-have resource for anyone who wants to experiment with and build on the OpenAI vision API 🔥

PythonPyPIchatgptcomputer-vision
1.7k135