Home

Awesome

CLOOB: Modern Hopfield Networks with InfoLOOB Outperform CLIP

Andreas Fürst<sup>* 1</sup>, Elisabeth Rumetshofer<sup>* 1</sup>, Johannes Lehner<sup>1</sup>, Viet Tran<sup>1</sup>, Fei Tang<sup>3</sup>, Hubert Ramsauer<sup>1</sup>, David Kreil<sup>2</sup>, Michael Kopp<sup>2</sup>, Günter Klambauer<sup>1</sup>, Angela Bitto-Nemling<sup>1</sup>, Sepp Hochreiter<sup>1 2</sup>

<sup>1</sup> ELLIS Unit Linz and LIT AI Lab, Institute for Machine Learning, Johannes Kepler University Linz, Austria
<sup>2</sup> Institute of Advanced Research in Artificial Intelligence (IARAI)
<sup>3</sup> HERE Technologies
<sup>*</sup> Equal contribution


Detailed blog post on this paper at this link.

The full paper is available here.


Implementation of CLOOB

This repository contains the implemenation of CLOOB used to obtain the results reported in the paper. The implementation is based on OpenCLIP, an open source implementation of OpenAI's CLIP.

Setup

We provide an 'environment.yml' file to set up a conda environment with all required packages. Run the following command to clone the repository and create the environment.

# Clone repository and swtich into the directory
git clone https://github.com/ml-jku/cloob
cd cloob

# Create the environment and activate it
conda env create --file environment.yml
conda activate cloob

# Add the directory to the PYTHONPATH environment variable
export PYTHONPATH="$PYTHONPATH:$PWD/src"

Data

For pre-training we use the two datasets supported by OpenCLIP, namely Conceptual Captions and YFCC.

Conceptual Captions

OpenCLIP already provides a script to download and prepare the Conceptual Captions dataset, which contains 2.89M training images and 13k validation images. First, download the Conceptual Captions URLs and then run the script gather_cc.py.

python3 src/data/gather_cc.py path/to/Train_GCC-training.tsv path/to/Validation_GCC-1.1.0-Validation.tsv

YFCC

We use the same subset of ~15M images from the YFCC100M dataset as CLIP. They provide a list of (line number, photo identifier, photo hash) of each image contained in this subset here.

For more information see YFCC100m Subset on OpenAI's github.

Downstream Tasks

In the paper we report results on several downstream tasks. Except for ImageNet we provide links to already pre-processed versions (where necessary) of the respective test set.

DatasetDescriptionOfficialProcessed
BirdsnapThis dataset contains images of North American bird species, however <br> our dataset is smaller than reported in CLIP as some samples are no longer available.LinkLink
Country211This dataset was published in CLIP and is a small subset of the YFCC100m dataset. <br> It consists of photos that can be assigned to 211 countries via GPS coordinates. <br> For each country 200 photos are sampled for the training set and 100 for testing.LinkLink
Flowers102Images of 102 flower categories commonly occuring in the United Kingdom were collected.<br> Several classes are very similar and there is a large variation in scale, pose and lighting.LinkLink
GTSRBThis dataset was released for a challenge held at the IJCNN 2011. <br> The dataset contains images of german traffic signs from more than 40 classes.LinkLink
Stanford CarsThis dataset contains images of 196 car models at the level of make, <br> model and year (e.g. Tesla Model S Sedan 2012).LinkLink
UCF101The dataset has been created by extracting the middle frame from each video.LinkLink
ImageNetThis dataset spans 1000 object classes and contains 1,281,167 training images, <br> 50,000 validation images and 100,000 test images.Link-
ImageNet v2The ImageNetV2 dataset contains new test data for the ImageNet benchmark.Link-

Usage

In the following there is an example command for pretraining on CC with an effective batch size of 512 when used on 4 GPUs.

python -u src/training/main.py \
--train-data="<dataset-dir>/conceptual_captions/Train-GCC-training_output.csv" \
--val-data="<dataset-dir>/conceptual_captions/Validation_GCC-1.1.0-Validation_output.csv" \
--path-data="<dataset-dir>/conceptual_captions" \
--imagenet-val="<dataset-dir>/imagenet/val" \
--warmup 20000 \
--batch-size=128 \
--lr=1e-3 \
--wd=0.1 \
--lr-scheduler="cosine-restarts" \
--restart-cycles=10 \
--epochs=70 \
--method="cloob" \
--init-inv-tau=30 \
--scale-hopfield=8 \
--workers=8 \
--model="RN50" \
--dist-url="tcp://127.0.0.1:6100" \
--batch-size-eval=512

Zeroshot evaluation of downstream tasks

We provide a Jupyter notebook to perform zeroshot evaluation with a trained model.

LICENSE

MIT LICENSE