百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

SEARLE

> DevOps
开源

[ICCV 2023] - 使用文本反转的零样本合成图像检索

198 stars0 点赞5 次浏览
访问官网GitHub

工具介绍

[ICCV 2023] - 使用文本反转的零样本合成图像检索

SEARLE (ICCV 2023)

Zero-shot Composed Image Retrieval With Textual Inversion

[2024/05/07] The extended version of our ICCV 2023 paper is now public: iSEARLE: Improving Textual Inversion for Zero-Shot Composed Image Retrieval . The code will be released upon acceptance.

This is the official repository of the ICCV 2023 paper "Zero-Shot Composed Image Retrieval with Textual Inversion" and its extended version "iSEARLE: Improving Textual Inversion for Zero-Shot Composed Image Retrieval".

You are currently viewing the code and model repository. If you are looking for more information about the newly-proposed dataset CIRCO see the repository.

Overview

Abstract

Composed Image Retrieval (CIR) aims to retrieve a target image based on a query composed of a reference image and a relative caption that describes the difference between the two images. The high effort and cost required for labeling datasets for CIR hamper the widespread usage of existing methods, as they rely on supervised learning. In this work, we propose a new task, Zero-Shot CIR (ZS-CIR), that aims to address CIR without requiring a labeled training dataset. Our approach, named zero-Shot composEd imAge Retrieval with textuaL invErsion (SEARLE), maps the visual features of the reference image into a pseudo-word token in CLIP token embedding space and integrates it with the relative caption. To support research on ZS-CIR, we introduce an open-domain benchmarking dataset named Composed Image Retrieval on Common Objects in context (CIRCO), which is the first dataset for CIR containing multiple ground truths for each query. The experiments show that SEARLE exhibits better performance than the baselines on the two main datasets for CIR tasks, FashionIQ and CIRR, and on the proposed CIRCO.

Workflow of our method. Top: in the pre-training phase, we generate pseudo-word tokens of unlabeled images with an optimization-based textual inversion and then distill their knowledge to a textual inversion network. Bottom: at inference time on ZS-CIR, we map the reference image to a pseudo-word $S_*$ and concatenate it with the relative caption. Then, we use CLIP text encoder to perform text-to-image retrieval.

Citation

bibtex
@article{agnolucci2024isearle,
  title={iSEARLE: Improving Textual Inversion for Zero-Shot Composed Image Retrieval}, 
  author={Agnolucci, Lorenzo and Baldrati, Alberto and Bertini, Marco and Del Bimbo, Alberto},
  journal={arXiv preprint arXiv:2405.02951},
  year={2024},
}
bibtex
@inproceedings{baldrati2023zero,
  title={Zero-Shot Composed Image Retrieval with Textual Inversion},
  author={Baldrati, Alberto and Agnolucci, Lorenzo and Bertini, Marco and Del Bimbo, Alberto},
  booktitle={Proceedings of the IEEE/CVF International Conference on Computer Vision},
  pages={15338--15347},
  year={2023}
}

Getting Started

We recommend using the Anaconda package manager to avoid dependency/reproducibility problems. For Linux systems, you can find a conda installation guide here.

Installation

  1. Clone the repository
bash
git clone https://github.com/miccunifi/SEARLE
  1. Install Python dependencies
bash
conda create -n searle -y python=3.8
conda activate searle
conda install -y -c pytorch pytorch=1.11.0 torchvision=0.12.0
pip install comet-ml==3.33.6 transformers==4.24.0 tqdm pandas==1.4.2
pip install git+https://github.com/openai/CLIP.git

Data Preparation

FashionIQ

Download the FashionIQ dataset following the instructions in the official repository.

After downloading the dataset, ensure that the folder structure matches the following:

├── FashionIQ
│   ├── captions
|   |   ├── cap.dress.[train | val | test].json
|   |   ├── cap.toptee.[train | val | test].json
|   |   ├── cap.shirt.[train | val | test].json

│   ├── image_splits
|   |   ├── split.dress.[train | val | test].json
|   |   ├── split.toptee.[train | val | test].json
|   |   ├── split.shirt.[train | val | test].json

│   ├── images
|   |   ├── [B00006M009.jpg | B00006M00B.jpg | B00006M6IH.jpg | ...]

CIRR

Download the CIRR dataset following the instructions in the official repository.

After downloading the dataset, ensure that the folder structure matches the following:

├── CIRR
│   ├── train
|   |   ├── [0 | 1 | 2 | ...]
|   |   |   ├── [train-10108-0-img0.png | train-10108-0-img1.png | ...]

│   ├── dev
|   |   ├── [dev-0-0-img0.png | dev-0-0-img1.png | ...]

│   ├── test1
|   |   ├── [test1-0-0-img0.png | test1-0-0-img1.png | ...]

│   ├── cirr
|   |   ├── captions
|   |   |   ├── cap.rc2.[train | val | test1].json
|   |   ├── image_splits
|   |   |   ├── split.rc2.[train | val | test1].json

CIRCO

Download the CIRCO dataset following the instructions in the official repository.

After downloading the dataset, ensure that the folder structure matches the following:

├── CIRCO
│   ├── annotations
|   |   ├── [val | test].json

│   ├── COCO2017_unlabeled
|   |   ├── annotations
|   |   |   ├──  image_info_unlabeled2017.json
|   |   ├── unlabeled2017
|   |   |   ├── [000000243611.jpg | 000000535009.jpg | ...]

ImageNet

Download ImageNet1K (ILSVRC2012) test set following the instructions in the official site.

After downloading the dataset, ensure that the folder structure matches the following:

├── ImageNet1K
│   ├── test
|   |   ├── [ILSVRC2012_test_[00000001 | ... | 00100000].JPEG]

SEARLE Inference with Pre-trained Models

Validation

To compute the metrics on the validation set of FashionIQ, CIRR or CIRCO using the SEARLE pre-trained models, simply run the following command:

bash
python src/validate.py --eval-type [searle | searle-xl] --dataset  --dataset-path 
    --eval-type                if 'searle', uses the pre-trained SEARLE model to predict the pseudo tokens;
                                    if 'searle-xl', uses the pre-trained SEARLE-XL model to predict the pseudo tokens, 
                                    options: ['searle', 'searle-xl']           
    --dataset                  Dataset to use, options: ['fashioniq', 'cirr', 'circo']
    --dataset-path             Path to the dataset root folder
     
    --preprocess-type          Preprocessing type, options: ['clip', 'targetpad'] (default=targetpad)

Since we release the pre-trained models via torch.hub, the models will be automatically downloaded when running the inference script.

The metrics will be printed on the screen.

Test

To generate the predictions file for uploading on the CIRR Evaluation Server or the CIRCO Evaluation Server using the SEARLE pre-trained models, please execute the following command:

bash
python src/generate_test_submission.py --submission-name   --eval-type [searle | searle-xl] --dataset  --dataset-path 
…

Since we release the pre-trained models via torch.hub, the models will be automatically downloaded when running the inference script.

The predictions file will be saved in the data/test_submissions/{dataset}/ folder.

SEARLE Minimal Working Example

…

SEARLE

This section provides instructions for reproducing the results of the SEARLE method. It covers the steps to train the textual inversion network and perform inference using the trained model.

0. GPT phrases generation

To perform both the optimization-based textual inversion and the training of the textual inversion network phi, we need to generate a set of phrases for each concept in the dictionary. The concepts are taken from the Open Images V7 dataset.

Run the following command to generate the phrases:

bash
python src/gpt_phrases_generation.py
    --exp-name                 Name of the experiment (default="GPTNeo27B")
    --gpt-model                GPT model to use (default="EleutherAI/gpt-neo-2.7B")
    --max-length               Maximum length of the generated phrases (default=35)
    --num-return-sequences     Number of generated phrases for each concept (default=256)
    --temperature            Temperature of the sampling (default=0.5)
    --no-repeat-ngram-size     Size of the n-gram to avoid repetitions (default=2)
    --resume-experiment Resume the experiment if it exists (default=false)

Since the phrase generation process can be time-consuming, you can download the pre-generated phrases used in our experiments here. After downloading, unzip the file in the data/GPT_phrases folder so that the folder structure matches the following: data/GPT_phrases/GPTNeo27B/concept_to_phrases.pkl

1. Image concepts association

We associate to each image a set of textual concepts taken from the Open Images V7 dataset.

Run the following command to associate concepts with the images:

bash
python src/image_concepts_association.py --clip-model-name  --dataset imagenet --dataset-path  --split test
    --clip-model-name         CLIP model to use, e.g 'ViT-B/32', 'ViT-L/14'
    --dataset-path            Path to the ImageNet root folder
    --batch-size              Batch size (default=32)
    --num-workers             Number of workers (default=8)
    --preprocess-type         Preprocessing type, options: ['clip', 'targetpad'] (default=targetpad)

The associations will be saved in a CSV file located in the data/similar_concept/imagenet/test folder.

2. Optimization-based Textual Inversion (OTI)

Perform the Optimization-based Textual Inversion on the ImageNet test set.

Run the following command to perform OTI:

bash
python src/oti_inversion.py --exp-name  --clip-model-name  --dataset imagenet --dataset-path  --split test  
…

The OTI pre-inverted-tokens will be saved in the data/oti_pseudo_tokens/imagenet/test/{exp_name} folder.

3. Textual Inversion Network Training

Finally, train the Textual Inversion Network by distilling the knowledge from the OTI pre-inverted-tokens.

It is recommended to have a properly initialized Comet.ml account to have better logging of the metrics (nevertheless, all the metrics will also be logged on a csv file).

To train the Textual Inversion Network, run the following command:

bash
python src/train_phi.py --exp-name  --clip-model-name  --imagenet-dataset-path  --cirr-dataset-path  --oti-exp-name  --save-training 
…

The Textual Inversion Network checkpoints will be saved in the data/phi_models/{exp_name} folder.

4a. Val Set Evaluation

To evaluate the Textual Inversion Network on the validation sets, run the following command:

bash
python src/validate.py --exp-name  --eval-type phi --dataset  --dataset-path  --phi-checkpoint-name 
    --exp-name                 Name of the experiment (should be the same as --exp-name in step 3)
    --dataset                  Dataset to use, options: ['fashioniq', 'cirr', 'circo']
    --dataset-path             Path to the dataset root folder
    --phi-checkpoint-name      Name of the Textual Inversion Network checkpoint, e.g. 'phi_20.pt'   
    --preprocess-type          Preprocessing type, options: ['clip', 'targetpad'] (default=targetpad)

The metrics will be printed on the screen.

4b. Test Set Evaluation

To generate the predictions file to be uploaded on the CIRR Evaluation Server or on the [CIRCO Evalu

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Pythoncircocirrclipcomposed-image-retrieval

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类DevOps
定价开源

> 相关工具

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理