Zurück zum Ranking

salesforce/ALBEF

Python

Code for ALBEF: a new vision-language pre-training method

vision-and-languagerepresentation-learningimage-textweakly-supervised-learningcontrastive-learning
Sterne-Wachstum
Sterne
1.8k
Forks
220
Wochenwachstum
Issues
64
5001k1.5k
Juli 2021März 2023Nov. 2024Juli 2026
ArtefaktePyPIpip install albef
README

Align before Fuse: Vision and Language Representation Learning with Momentum Distillation, NeurIPS 2021 Spotlight (Salesforce Research).

Announcement: ALBEF is now officially integrated into LAVIS - a one-stop library for language-and-vision research and applications!

This is the official PyTorch implementation of the ALBEF paper [Blog]. This repository supports pre-training on custom datasets, as well as finetuning on VQA, SNLI-VE, NLVR2, Image-Text Retrieval on MSCOCO and Flickr30k, and visual grounding on RefCOCO+. Pre-trained and finetuned checkpoints are released.

Requirements:

  • pytorch 1.8.0
  • transformers 4.8.1
  • timm 0.4.9

Download:

Visualization:

We provide code in visualize.ipynb to visualize the important areas in an image for each word in a text. Here is an example visualization using the visual grounding checkpoint.

Try the Replicate demo here Replicate.

Pre-training on custom datasets:

  1. Prepare training json files where each json file contains a list. Each item in the list is a dictonary with two key-value pairs: {'image': path_of_image, 'caption': text_of_image}.
  2. In configs/Pretrain.yaml, set the paths for the json files.
  3. Pre-train the model using 8 A100 GPUs:
python -m torch.distributed.launch --nproc_per_node=8 --use_env Pretrain.py --config ./configs/Pretrain.yaml --output_dir output/Pretrain 

Image-Text Retrieval:

  1. Download MSCOCO or Flickr30k datasets from the original websites.
  2. Download and extract the provided dataset json files.
  3. In configs/Retrieval_coco.yaml or configs/Retrieval_flickr.yaml, set the paths for the json files and the image path.
  4. Finetune the pre-trained checkpoint using 8 A100 GPUs:
python -m torch.distributed.launch --nproc_per_node=8 --use_env Retrieval.py \
--config ./configs/Retrieval_flickr.yaml \
--output_dir output/Retrieval_flickr \
--checkpoint [Pretrained checkpoint]

VQA:

  1. Download VQA v2 dataset and Visual Genome dataset from the original websites.
  2. Download and extract the provided dataset json files.
  3. In configs/VQA.yaml, set the paths for the json files and the image paths.
  4. Finetune the pre-trained checkpoint using 8 A100 GPUs:
python -m torch.distributed.launch --nproc_per_node=8 --use_env VQA.py \
--config ./configs/VQA.yaml \
--output_dir output/vqa \
--checkpoint [Pretrained checkpoint]
  1. Evaluate the result using the official evaluation server.

Visual Entailment:

  1. Download SNLI-VE dataset from the original website.
  2. Download and extract the provided dataset json files.
  3. In configs/VE.yaml, set the paths for the json files and the image path.
  4. Finetune the pre-trained checkpoint using 8 A100 GPUs:
python -m torch.distributed.launch --nproc_per_node=8 --use_env VE.py \
--config ./configs/VE.yaml \
--output_dir output/VE \
--checkpoint [Pretrained checkpoint]

Visual Grounding on RefCOCO+:

  1. Download MSCOCO dataset from the original website.
  2. Download and extract the provided dataset json files.
  3. In configs/Grounding.yaml, set the paths for the json files and the image path.
  4. Finetune the pre-trained checkpoint using 8 A100 GPUs:
python -m torch.distributed.launch --nproc_per_node=8 --use_env Grounding.py \
--config ./configs/Grounding.yaml \
--output_dir output/RefCOCO \
--gradcam_mode itm \ 
--block_num 8 \
--checkpoint [Pretrained checkpoint]

NLVR2:

NLVR2 requires an additional pre-training step with text-assignment (TA) to adapt the model for image-pair inputs. In order to perform TA, first set the paths for the json training files in configs/NLVR_pretrain.yaml, then run:

python -m torch.distributed.launch --nproc_per_node=8 --use_env Pretrain_nlvr.py \
--config ./configs/NLVR_pretrain.yaml \
--output_dir output/NLVR_pretrain \
--checkpoint [Pretrained checkpoint]

We provide the checkpoint after TA pre-training, which can be fine-tuned with the following steps.

  1. Download NLVR2 dataset from the original website.
  2. Download and extract the provided dataset json files.
  3. In configs/NLVR.yaml, set the paths for the json files and the image path.
  4. Finetune the pre-trained checkpoint using 8 A100 GPUs:
python -m torch.distributed.launch --nproc_per_node=8 --use_env NLVR.py \
--config ./configs/NLVR.yaml \
--output_dir output/NLVR \
--checkpoint [TA pretrained checkpoint]

Citation

If you find this code to be useful for your research, please consider citing.

@inproceedings{ALBEF,
      title={Align before Fuse: Vision and Language Representation Learning with Momentum Distillation}, 
      author={Junnan Li and Ramprasaath R. Selvaraju and Akhilesh Deepak Gotmare and Shafiq Joty and Caiming Xiong and Steven Hoi},
      year={2021},
      booktitle={NeurIPS},
}
Ähnliche Repositories
aishwaryanr/awesome-generative-ai-guide

A one stop repository for generative AI research updates, interview resources, notebooks and much more!

HTMLMIT Licenseawesomeawesome-list
linkedin.com/in/areganti/
28.4k5.8k
salesforce/LAVIS

LAVIS - A One-stop Library for Language-Vision Intelligence

Jupyter NotebookBSD 3-Clause "New" or "Revised" Licensedeep-learningdeep-learning-library
11.3k1.1k
roboflow/maestro

streamline the fine-tuning process for multimodal models: PaliGemma 2, Florence-2, and Qwen2.5-VL

PythonPyPIApache License 2.0captioningfine-tuning
maestro.roboflow.com
2.7k222
om-ai-lab/OmAgent

[EMNLP-2024] Build multimodal language agents for fast prototype and production

PythonPyPIApache License 2.0large-language-modelsmultimodal-agent
om-agent.com
2.7k293
dandelin/ViLT

Code for the ICML 2021 (long talk) paper: "ViLT: Vision-and-Language Transformer Without Convolution or Region Supervision"

PythonPyPIApache License 2.0vision-and-language
1.5k230
open-mmlab/Multimodal-GPT

Multimodal-GPT

PythonPyPIApache License 2.0flamingogpt
1.5k129
llm-jp/awesome-japanese-llm

日本語LLMまとめ - Overview of Japanese LLMs

TypeScriptnpmApache License 2.0language-modellanguage-models
llm-jp.github.io/awesome-japanese-llm
1.4k45
om-ai-lab/OmDet

Real-time and accurate open-vocabulary end-to-end object detection

PythonPyPIApache License 2.0object-detectionopen-vocabulary
1.4k118
NVlabs/prismer

The implementation of "Prismer: A Vision-Language Model with Multi-Task Experts".

PythonPyPIOtherimage-captioninglanguage-model
shikun.io/projects/prismer
1.3k74
yuewang-cuhk/awesome-vision-language-pretraining-papers

Recent Advances in Vision and Language PreTrained Models (VL-PTMs)

vision-and-languagepretraining
1.2k104
rhymes-ai/Aria

Codebase for Aria - an Open Multimodal Native MoE

Jupyter NotebookApache License 2.0mixture-of-expertsmultimodal
1.1k87
OFA-Sys/ONE-PEACE

A general representation model across vision, audio, language modalities. Paper: ONE-PEACE: Exploring One General Representation Model Toward Unlimited Modalities

PythonPyPIApache License 2.0foundation-modelsmultimodal
1.1k71