Supervision Exists Everywhere: A Data Efficient Contrastive Language-Image Pre-training Paradigm
Yangguang Li, Feng Liang, Lichen Zhao, Yufeng Cui, Wanli Ouyang, Jing Shao, Fengwei Yu, Junjie Yan
Introduction
Over the last few years, pre-trained models have greatly revolutionized computer vision (CV) and natural language processing (NLP). The first wave of exploring pre-trained models took place in the field of CV. Deep convolutional neural nets (Krizhevsky et al., 2012; Simonyan & Zisserman, 2014; He et al., 2016) are pre-trained on well-labeled ImageNet (Deng et al., 2009) and then transferred to downstream CV tasks (Girshick et al., 2014; Long et al., 2015; Vinyals et al., 2015). Standardly, CV models are pre-trained to predict a fixed set of pre-defined object categories, e.g., 1000 classes in ImageNet. However, this supervised pre-training is hard to scale since we need arduous human labeling to specify new visual concepts.
When pre-training meets NLP, the intrinsic supervision within the natural language makes the pre-training more scalable (Devlin et al., 2018; Radford et al., 2019; Brown et al., 2020). Witnessing the progress in NLP, researchers use natural language supervision to learn visual features. The language-image pre-training can scale up to a very large size, benefiting from abundant image-text pairs on the Internet. For instance, CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2021) adopt the contrastive loss to push the embedding of matched image-text pairs together while pushing those of non-matched pairs apart. They achieve prestigious performance by learning from an enormous dataset that contains 400M/1B image-text pairs. However, these methods also require huge storage and computing resources, which is not affordable for most laboratories and companies. We argue that these prior arts only use the single image-text contrastive supervision while overlooking the widespread supervision within the pairs, thus is inefficient.
Firstly, there underlies rich structural information within each modality itself (LeCun & Misra, 2021). We can tweak some words/pixels in a sentence/image while retaining a similar semantic meaning. This sort of self-supervision can be exploited to learn a more common-sense representation for each modality (Devlin et al., 2018; He et al., 2020; Chen et al., 2020a). Moreover, inspired by contrasting multi-crops in an image (Caron et al., 2020), we further extend the multi-view View is originally a visual concept. For simplicity, we use the same term for language. supervision into our multi-modality setting. Specifically, each image is paired with multiple textual descriptions obtained via stochastic augmentations, vice versa. The benefit is intuitive: this auxiliary multi-view supervision brings more invariant and robust information.
Besides these overlooked supervision, we propose a novel nearest-neighbor (NN) supervision from other similar pairs. This NN supervision is mainly based on the intuition that one image is likely to have other similar text descriptions among the dataset. As shown in right figure, the image with the text ’going to see a lot of vintage tractors this week’ can also be described by ’vintage at tractors a gathering’. For this reason, we sample the NN in the embedding space and utilize them as additional supervisory signals. Aggregating these supervision leads to our novel training paradigm DeCLIP, which stands for Data efficient Contrastive Language-Image Pretraining.
Extensive experiments show the effectiveness and efficiency of our DeCLIP. As shown in Fig. 2, with a ResNet50 image encoder and a Transformer text encoder, our model can achieve 60.4% zero-shot top1 accuracy on ImageNet, which is 0.8% above the CLIP-ResNet50 while using 7.1 fewer data. Using only 88M image-text pairs, our best ResNet50/ViT-B32 models boost the zero-shot performance to 62.5% and 66.2%, nearly 3.0% higher than the best number reported for these two architectures. We further verify the transferability of our models on downstream tasks. As indicated in Fig. 2, our DeCLIP-ResNet50 outperforms its counterpart in 8 out of 11 visual datasets. Moreover, Scaling up the model and computing also works well in our framework. Using 4.5 fewer data, our DeCLIP-RegNetY-64GF achieves 73.7% zero-shot ImageNet top1 accuracy, which is on-pair with CLIP-R5064. Pre-trained models, code, and datasets shall be released to the community. The contributions are summarized as follows:
To the best of our knowledge, this is the first work to study self-supervision and cross-modal multi-view supervision in the million-scale image-text pre-training task. Our work opens a new direction to fully exploit the intrinsic supervision within the multi-modal data instead of scaling up data naively.
We propose novel cross-modal Nearest-Neighbor Supervision (NNS) to harness information from other similar pairs. The NNS can also be regarded as a semantic-level augmentation.
Related Work
The critical idea of pre-training is to first extract general knowledge implicitly from the massive amount of data and then transfer the knowledge to versatile downstream tasks (Han et al., 2021). Big NLP models (Devlin et al., 2018; Brown et al., 2020) yield unprecedented performance via learning from tremendous language data over the Internet and labor-free supervision within the language itself. In the field of CV, supervised pre-training on ImageNet is still the standard practice. While achieving great success on downstream CV tasks (Girshick et al., 2014; Long et al., 2015; Vinyals et al., 2015) , this supervised manner is hard to scale. To address this challenge, our DeCLIP learns directly from image-text pairs that are abundant across the Internet. More importantly, by exploiting the widespread supervision within the pairs, our DeCLIP is more data-efficient than the prior art.
2 Supervision within Data
Language supervision Joulin et al. (2016); Gomez et al. (2017); Zhang et al. (2020); Sariyildiz et al. (2020); Desai & Johnson (2021) demonstrate the effectiveness of learning transferable visual features from language supervision. Pioneering work CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2021) achieve prestigious performance via learning from 400M/1B image-text pairs. We are following these two works to improve their data efficiency.
Relevant concurrent work including: SLIP Mu et al. (2021) introduces self-supervision to CLIP. FILIP Yao et al. (2021) leverages the finer-grained alignment between image patches and textual words. OTTER Wu et al. (2021); Cheng et al. (2021) uses online entropic optimal transport to find a soft image-text match as labels to mitigate the noise within the dataset.
Visual self-supervision Our work is also highly related to self-supervised learning (SSL) (LeCun & Misra, 2021). Contrastive learning, as a pretext task of SSL, has achieved remarkable success in visual representation learning (He et al., 2020; Chen et al., 2020a; Caron et al., 2020; Grill et al., 2020; Chen et al., 2020a). Researchers also extend contrastive learning into multi-modal settings (Yuan et al., 2021). However, it is only limited to a small COCO dataset (Yuan et al., 2021).
Nearest-neighbor supervision Recently, researchers have exploited nearest-neighbor supervision to learn visual features (Dwibedi et al., 2021; Van Gansbeke et al., 2021). They find that using nearest-neighbor as positive samples in the contrastive loss improves the performances on multiple downstream tasks. However, they mainly focus on the single visual modality pretraining on relatively small datasets, such as ImageNet. We propose novel nearest-neighbor supervision for multi-modal learning to harness information from other similar pairs.
3 Multi-Modal Learning
Most vision-language models Chen et al. (2020b); Lu et al. (2019); Li et al. (2020) use a bunch of cross-modal transformers to fuse and align the information between text and image. These methods either need an off-the-shelf object detector to extract region features or dedicated cross-modal transformer layers, significantly hindering their scalability. Our DeCLIP, by contrast, uses a simple yet effective two-tower framework with multi-modal interaction only at the top. Moreover, this series of models (Radford et al., 2021; Jia et al., 2021; Huo et al., 2021) can perform zero-shot recognition, adapting to new categories with no seen labeled data. Shen et al. (2021) also shows that the pre-trained CLIP model can significantly benefit the downstream VQA and image caption tasks. Our DeCLIP is supposed to be compatible with more modalities, e.g., acoustic signals (Akbari et al., 2021). More modalities included, more correlated supervision are expected to be exploited.
Approach
In this section, we first revisit CLIP and denote some basic concepts, such as image-text contrastive supervision (i.e., the InfoNCE loss). Next, we present the overview of our DeCLIP framework. Then we introduce every auxiliary supervision: Self-Supervision(SS), Multi-View Supervision(MVS), and Nearest-Neighbor Supervision(NNS).
Contrastive Language-Image Pre-training (CLIP) (Radford et al., 2021) aims to learn directly from the raw text about images. They use a dual-encoder architecture as in Fig. 4(a). The model consists of an image encoder (e.g., CNN (He et al., 2016) or ViT (Dosovitskiy et al., 2020)) and a text encoder(e.g., Transformer (Vaswani et al., 2017) or its variants (Radford et al., 2019)), with a multimodal interaction at the top. The image and text features are projected to the same dimension and followed by L2 normalization before interaction. At the training phase, a contrastive objective pushes the embeddings of matched image-text pairs together while pushing those of non-matched pairs apart. In a batch of image-text pairs , we denote and as image and text of the pair. Let and be the normalized embedding of the image and text, respectively. CLIP uses InfoNCE loss (Oord et al., 2018). The loss for the image encoder can be denoted as Eq. 1.
At the test phase, the learned text encoder synthesizes a zero-shot linear classifier by embedding the arbitrary categories of the test dataset. Because it is rare in the dataset that image caption is just a single word, CLIP uses prompts to make up the context of the category {label}, such as "a photo of a {label}". Unless otherwise specified, we use the same prompt engineering and ensembling techniques as CLIP. Details can be found in Appendix E.
2 Overview of DeCLIP
As shown in Fig. 4(b), our DeCLIP has three additional supervisory signals.
1 We first use existing methods to exploit image and text Self-Supervision (SS) within its modality. For image SS, we adopt the simple yet effective SimSiam (Chen & He, 2021). The objective is to maximize the similarity between two augmented image features. For text SS, we adopt the most widely used Masked Language Modeling (MLM) (Devlin et al., 2018) as the pre-text task. We believe other kinds of self-supervised learning algorithms (e.g. MoCo (He et al., 2020), SimCSE (Gao et al., 2021) are orthogonal with our framework.
2 While SS only focuses on a single modality, we further propose cross-modal Multi-View Supervision (MVS). We apply stochastic data augmentations for both images and texts, resulting in two correlated views1 of each example. Then, the image-text contrastive loss is calculated for all the pairs. Worth mentioning, the original CLIP does not use text augmentations and only uses random square crop image augmentations, thereby is data-hungry. The extension is instinctive and straightforward. Specifically, we contrast the pairs and resulting in more additional supervision.
3 We also propose novel Nearest-Neighbor Supervision (NNS) mined in embedding space to make better use of similar text descriptions among the dataset. In detail, we maintain a first-in-first-out feature queue that is representative of the whole data distribution. We use the nearest-neighbor search in embedding space to get the semantically similar text descriptions. Then we use the image-text contrastive loss to get additional supervision.
3 Supervision exists everywhere
As shown in Fig. 5(b), we follow the method in BERT (Devlin et al., 2018) for our text self-supervision. In detail, we first randomly choose of all tokens in each sequence. Then the token is replaced with (1) the [mask] token of the time (2) a random token of the time (3) the unchanged token of the time. Then, the output of the language module for the corresponding token is used to predict the original token with cross-entropy loss.
Multi-View Supervision
Nearest-Neighbor Supervision
In summary, we denote and as the loss function of image SS and text SS, respectively. is multi-view loss, and is nearest-neighbor loss. We have the overall loss function of our DeCLIP as in Eq. 2.
Experiments
We summarize our pre-training dataset as in Tab. 1. Our DeCLIP full data consists of two parts: open-source data and web-crawled data. The open-source data comes from three different datasets: Conceptual Captions (CC3M) (Sharma et al., 2018), Conceptual 12M (CC12M) (Changpinyo et al., 2021), and YFCC (Thomee et al., 2016). Worth mentioning, due to the download failure or non-English caption, we do not obtain the complete data for these datasets. We further use the YFCC15M query to crawl about 59M filtered web data on the Internet, together with open-source data to form the 88M DeCLIP full pre-training dataset. More details can be seen in Appendix C.
Downstream datasets
We assess our model performances in a wider variety of distributions and tasks. Following the CLIP (Radford et al., 2021), we evaluate the image encoder transferability on 11 widely used downstream datasets, such as Food-101, CIFAR-10, etc. To conduct a fair comparison, the metric and division for each dataset that can be collected are consistent with those of CLIP. More details of downstream datasets can be found in Tabel 6 of Appendix D.
2 Experiments Setup
Following CLIP, we first consider two different architectures for the image encoder: a modified version of ResNet50 (Radford et al., 2021) and ViT-B/32 (Dosovitskiy et al., 2020). The text encoder is a Transformer (Vaswani et al., 2017) with the architecture modifications described in Radford et al. (2019). The image and text features are projected to the same 1024 dimension, followed by L2 normalization before interaction. Benefiting from the rapid progress of large CV models, we further scale up our model. Our largest model is a RegNetY-64GF (Radosavovic et al., 2020; Goyal et al., 2021) image encoder with a BERT (Devlin et al., 2018) text encoder, which is on-pair with the largest CLIP-R5064 model.
Pre-training setup
For a fair comparison with CLIP, we train our DeCLIP-ResNet50 and DeCLIP-ViT-B/32 from scratch for 32 epochs. Unless otherwise specified, we use full data, i.e., 88M image-text pairs, to obtain the best performance. The input resolution of the image encoder is , and the maximum context length of the text encoder is 76. The learnable temperature parameter is initialized to 0.07. The loss weights of additional supervision , and are all set to 0.2. More details can be found in Appendix C.
Downstream evaluation setup
We evaluate our model transferability by performing linear classification on frozen features, i.e., the pre-trained image encoder is fixed and serves as a feature extractor. After feature extraction, we train the linear classifier with the L-BFGS optimizer as the same in Radford et al. (2021).
3 Main Results
After pre-training, we use natural language to refer to visual concepts enabling the zero-shot ability of our model. As shown in Fig. 2, our DeCLIP-ResNet50 consistently outperforms the CLIP-ResNet50 across all dataset sizes. When the data amount reaches 56M (29M open-source + 27M web-crawled), our model can achieve 60.4% accuracy, 0.8% above the CLIP-ResNet50, while using 7.1 fewer data. As described in Tab. 2, with our full data, our best ResNet50/ViT-B32 models boost the zero-shot performance to 62.5% and 66.2%, nearly 3.0% higher than the best number reported for these two architectures. Moreover, our DeCLIP-ResNet50 is even 0.3% better than CLIP-ResNet101, revealing the effectiveness and efficiency of our framework. Scaling up model capacity works in our framework as well. Our biggest DeCLIP-RegNetY-64GF achieves 73.7% accuracy, which is 0.1% above CLIP ResNet5064 with fewer parameters.
Downstream evaluation results
We report our linear probe performance on 11 downstream datasets in Tab. 3. Our DeCLIP-ResNet50 outperforms its CLIP counterpart in 8 out of 11 datasets, with a 0.8% average improvement. There are some datasets that our models perform worse than CLIP models, such as SUN and Food101. We conjecture that this is caused by the different distribution of the pre-trained dataset. Interestingly, our ResNet50 and ViT-B/32 models might have distinct performance on several datasets, such as Pets and Aircraft. We infer that these two types of neural networks might have different data preferences, i.e., different feature extraction capacities when they meet the same data.
4 Ablation Study
In order to understand the effectiveness of each additional supervision, we conduct an ablation study as indicated in Tab. 4. We follow the DeCLIP-ResNet50 protocol in the pre-training setup except for a smaller 1024 batch size on a smaller CC3M dataset. The single image-text contrastive supervision (CLIP) results in 20.6% zero-shot top1 accuracy on ImageNet. We can observe that MVS boost amazing 4.2% improvement over the original CLIP. As discussed in Sec. 3.3, the benefits might come from two sides: 1). the MVS can look at a small local view of an image which might be a better fit with the text description. 2). augmented views can provide diverse and high-quality additional supervision, thus leading to more robust representations. SS can further contribute an additional 0.6% improvement on the basis of MVS. We believe SS could bring more improvements with proper dedicated SSL methods. NNS further brings 1.8% improvement on the high basis of SS. We will discuss more about NNS at Sec. 4.5. On the YFCC15M dataset, our DeCLIP using full additional supervision gets significant effect improvement, Appendix F shows the details.
Ablation on training cost
Since we need to encode twice for each image-text pair, we admit our DeCLIP needs a higher training cost than CLIP. Regarding the training time, one DeCLIP iteration equals 1.5 CLIP iteration. In this ablation, we train the original CLIP-ResNet50 longer than our DeCLIP-ResNet50. As shown in Fig. 7, longer 64 epochs training can bring about 1.1% improvement. However, our model has 27.2% top1 accuracy, which is still 5.3% higher than the time-equivalent CLIP. It reveals that our framework can extract richer and more representative features through our proposed supervision. We also include memory usage ablation in Appendix F.
5 Analysis
We try to understand what renders our DeCLIP effective. As shown in Fig. 8, we visualize the class activation maps (CAM) (Zhou et al., 2016) of different models trained on the YFCC dataset. The results validate that the proposed method learns more representative features with the aid of multiple supervision.
Nearest neighbor samples
In Fig 9, we show some nearest neighbor (NN) samples from different datasets. The first row is the original image-text pair, while the second row is the NN pair. In general, we can see that the texts have similar intellectual meanings. Therefore, the NN pair can provide high-quality supervision. When taking datasets into consideration, the matching performs very well in well-filtered datasets, such as CC3M and CC12M. This matching might be a little worse in more noisy datasets, such as YFCC and web-crawled, but it can still provide some beneficial guidance.
Conclusion
This paper introduces DeCLIP, a Data efficient Contrastive Language-Image Pre-training paradigm. Our goal is to learn visual representations through the use of broader and scalable supervision. Specifically, instead of using the single image-text contrastive supervision, we fully exploit data potential through the use of (1) self-supervision within each modality; (2) multi-view supervision across modalities; (3) nearest-neighbor supervision from other similar pairs. Experimentally, DeCLIP shows superior effectiveness and efficiency with different types of neural nets(CNN and ViT) and different amounts of data. We hope our work could bring insights about exploiting the multi-modal data.
References
Appendix A Pseudo code of DeCLIP
The training pseudo code of DeCLIP is as follows:
Appendix B Data Augmentation
The image SS uses SimSiam (Chen & He, 2021) method as the image self-supervision. The prediction module is a 2-layer MLP, in which the hidden dimensions are 512 and output dimensions are 1024, the projection module is a 3-layer MLP, in which the hidden and output dimensions are both 1024. The text SS uses the Masked Language Model (Devlin et al., 2018) as the pretext task. In detail, we first randomly choose of all tokens in each sequence. Then the token is replaced with (1) the [mask] token of the time (2) a random token of the time (3) the unchanged token of the time.
Image augmentations
The augmentation policy includes: RandomResizedCrop with scale in [0.2,1.0] (Wu et al., 2018), ColorJitter containing {brightness, contrast, saturation, hue} strength of {0.4, 0.4, 0.4, 0.1} with an applying probability of 0.8, RandomGrayscale with an applying probability of 0.2. Blurring augmentation (Chen et al., 2020a) has a Gaussian kernel with std in [0.1, 2.0], and RandomHorizontalFlip.
Text augmentations
We use the EDA (Wei & Zou, 2019) method as our text augmentation strategy, which contains three types of text augmentation strategies: synonym replacement, random swap, and random deletion. Each text will randomly select one of these three types for text augmentation.
Appendix C Pre-training datasets & implementation details
Conceptual Captions (Sharma et al., 2018) is a 3.3 M image caption open-source data. Due to the failure of the download link, we only download about 3M data(CC3M). Conceptual 12M (Sharma et al., 2018) contains approximately 12M of image-text pairs(CC12M), which is larger than the CC3M and covers a more diverse set of visual concepts. Also, due to the failure of the download link, we only download about 11M data. YFCC (Thomee et al., 2016), the Yahoo Flickr Creative Commons 100M data, is a dataset for vision language tasks. We download about 86.5M data from the YFCC website and use four filtering rules to filter the DeCLIP YFCC15M dataset to benchmark against CLIP YFCC15M. The four rules are: filtering data with damaged images, filtering data without the caption, filtering data with a caption English word ratio less than 0.8, filtering data with a caption only including one part of speech.
Web-crawled data.
We use the user tags and machine tags of YFCC15M to form a tag list, and use WordNet (Miller, 1995) to find synonyms for each tag in the tag list to form a synonym tag list. The tag list and synonym tag list form a query list. Then we use the query list to crawl images from the Internet, after filtering data with smaller images, filtering data with damaged images, filtering data without the caption, and filtering data with Chinese in the caption, we collect 59M web crawled data. Tabel 5 shows the source link of pre-training datasets, and Figure 10 shows some cases random sampled from each dataset.
Implementation details
We train DeCLIP-ResNet50 (abbr. as R50) and DeCLIP-ViT-B/32 (abbr. as V-B32) from scratch for 32 epochs. For R50, we use the FP16-SGD optimizer with the batch size of 10,240 (12880). Starting with an 0.01 learning rate (lr), we first linearly increasing the lr to 0.2 (a.k.a warm-up) in one epoch. Then we use cosine anneal lr decay to decrease the lr. The weight decay is set to 0.0001. For V-B32, we use a hybrid FP16-AdamW-SGD optimizer with bacth size 10,240(12880). For the ViT image encoder, we use AdamW optimizer with the lr warming up from 1e-4 to 1e-3 in one epoch. The weight decay is set to 0.05. For the text encoder, we use the SGD optimizer with the lr warming up from 1e-3 to 0.02 in one epoch. The weight decay is set to 1e-4.
Pre-training cost
Our R50 and V-B32 took 8/10 days to train on 80 V100 GPUs, respectively. Our largest DeCLIP-RegNetY-64GF took 21 days on 160 V100 GPUs, while the largest CLIP-R5064 from (Radford et al., 2021) spent 18 days on 592 V100 GPUs.
Appendix D Downstream Datasets & implementation details
We begin with the 12 datasets from the well-studied evaluation suite introduced by Kornblith et al. (2019). Within these 12 datasets, Birdsnap can not be downloaded, and PASCAL VOC 2007 classification is replaced by more challenging ImageNet-1K, resulting in our 11 datasets. They are: Food-101, CIFAR-10, CIFAR-100, SUN397, Stanford Cars, FGVC Aircraft, Describable Textures, Oxford-IIIT Pets, Caltech-101, Oxford Flowers 102. Tab. 6 is the detailed information of these datasets.
Implementation details
We follow CLIP (Radford et al., 2021) to train a logistic regression classifier using L-BFGS, with maximum 1,000 iterations, and report the corresponding metric for each dataset. We determine the L2 regularization strength using a hyperparameter sweep on the validation sets over the range between and , with 96 logarithmically spaced steps. To save compute required for the sweeps, we perform a parametric binary search that starts with = [, , , 1, , , ] and iteratively halves the interval around the peak until it reaches a resolution of 8 steps per decade. The hyperparameter sweeps are performed on a validation split of each dataset. For the datasets that contains a validation split in addition to from the test split, we use the provided validation set to perform the hyperparameter search, and for the datasets that do not provide a validation split or have not published labels for the test data, we split the training dataset to perform the hyperparameter search and report the performance on the validation data.
Appendix E Prompt Engineering
Due to the reason that it’s relatively rare in the dataset for the text to be a single word, we use prompts such as "a photo of a {label}" for zero-shot classification. For a fair comparison, we use the same prompts as proposed in Radford et al. (2021) for the ImageNet dataset. As shown in Fig 11, the prompts reduce the domain gap between the training dataset and testset, and fully consider the different situations for the picture.
Appendix F Additional study
Data is critical for language-image pre-training task. As shown in Tab. 7, we evaluate our DeCLIP on different sources of datasets. Combining Tab.7 and Fig.2, we can see that when the amount of training data continues to scale up, the zero-shot recognition ability continues to improve as well. In addition, we can see that the open source data has high quality. The 29M open source data can achieve 49.3% zero-shot top1 accuracy on ImageNet through the DeCLIP training paradigm. Our open-source data is an affordable benchmark, which would be beneficial for explorations.
Our YFCC re-implementation
Although we use the same number of image-text pairs as the CLIP YFCC-15M, our YFCC data is different from CLIP. We also reproduce the naive CLIP on our YFCC-15M data, which results in 35.9% zero-shot top1 accuracy on ImageNet-1K (see Fig. 8). It is relatively higher than the number in CLIP paper (31.1%). We conjecture the improvements might be caused by the different data cleaning strategies. However, our DeCLIP can achieve 41.9% zero-shot accuracy which is also 6.0% higher than our CLIP re-implementation.
Memory usage
Because of the additional views, our DeCLIP is more memory-consuming. Thanks to the ICLR anonymous review comments: a fairer comparison might be doubling the batch size of CLIP. Flowing the ablation study in Fig. 7, we double the batch size and train CLIP-ResNet50 for 64 epochs. The final result is 22.3% which is still 4.9% lower than our DeCLIP model. We summarize the memory usage, training cost, and the final accuracy as below. All experiments are conducted on CC-3M with 16 V100 GPUs.