OTTER: D ATA E FFICIENT L ANGUAGE -S UPERVISED Z ERO -S HOT R ECOGNITION WITH O PTIMAL T RANSPORT D ISTILLATION
A BSTRACT
Traditional computer vision models are trained to predict a fixed set of predefined categories.
Recently, natural language has been shown to be a broader and richer source of supervision that provides finer descriptions to visual concepts than supervised "gold" labels.
Previous works such as CLIP, use InfoNCE loss to train a model to predict the pairing between images and text captions.
CLIP however is data hungry and requires more than 400M image text pairs for training.
The inefficiency can be partially attributed to the fact that the image-text pairs are noisy.
To address this, we propose OTTER ( O ptimal T ranspor T distillation for
E fficient zero shot R ecognition) which uses online entropic optimal transport to find a soft image text match as labels for contrastive learning.
Based on pretrained image and text encoders models trained with OTTER achieve strong performance with only 3M image text pairs.
Compared with InfoNCE loss label smoothing and knowledge distillation OTTER consistently outperforms these baselines in zero-shot evaluation on Google Open Images (19,958 classes) and multi-labeled
ImageNet 10K (10032 classes) from Tencent ML-Images.
Over 42 evaluations on 7 different dataset/architecture settings x 6 metrics OTTER outperforms (32) or ties (2) all baselines in 34 of them.
Our source code is open sourced at https: //github.com/facebookresearch/OTTER .
I NTRODUCTION
In real-world image recognition tasks, input images come from a broad range of distributions, spanning tens of thousands of object categories unknown during training.
It is thus important for computer vision models to generalize to a large number of visual concepts that may or may not be present in the training data.
This problem is called zero-shot learning (ZSL), which aims to transfer knowledge from some known classes with training data to a much larger number of unfamiliar classes.
Previous works on ZSL have explored using attributes (Romera-Paredes & Torr, 2015; Akata et al., 2015; 2013), class hierarchy (Wang et al., 2018; Kampffmeyer et al., 2019), and pretrained word embeddings (Frome et al., 2013;
Norouzi et al., 2014) to transfer knowledge from pretrained image representations to recognize new classes.
Recently, natural language has been used as a powerful source of supervision for visual representation learning.
(Desai & Johnson, 2020; Sariyildiz et al., 2020; Zhang et al., 2020; Jia et al., 2020) demonstrate the effectiveness of pretraining on image-text data.
Among them, CLIP (Radford et al., 2021) applies natural language supervision to zero-shot image recognition.
It collects an enormous dataset with over 400M image caption pairs from the
Internet, and trains an image encoder and a text encoder jointly with a contrastive loss to maximize the cosine similarity of paired image and text embeddings.
CLIP demonstrates good zero-shot classification results on a wide range of downstream image classification datasets.
However, a main constraint of CLIP is that it requires over 400M image-text pairs for training.
Collecting and training on such a huge dataset is very expensive.
The inefficiency can be partially attributed to the fact that the training labels from image-text pairs are noisy.
As shown in Figure 1, in a typical image-text dataset, we observe that images and captions are loosely correlated.
It is very common that one caption (image) can potentially match several other images (captions), and the ground-truth pairing is one of the most dramatic mountain ranges I have seen aerial: woman waving her arms on the rock cinematic aerial shot of the dramatic coastline at the cliffs view of a lake and pine forest a forest of stunted trees that stand in sharp contrast … landscape with mown grass and a haystack newly built small house next to the sea and the beach the public house traditional pub in old building on corner a cottage in the picturesque village
OriginalCaptions one of the most dramatic mountain ranges I have seen aerial: woman waving her arms on the rock cinematic aerial shot of the dramatic coastline at the cliffs
PermutedCaptions landscape with mown grass and a haystack a forest of stunted trees that stand in sharp contrast … view of a lake and pine forest the public house traditional pub in old building on corner a cottage in the picturesque village newly built small house next to the sea and the beach not the only sensible match.
Note that examples in Figure 1 are not hand-picked special cases.
In fact, such noisy image-text matching is prevalent in image-text datasets.
To quantitatively analyze this, we use a CLIP(Radford et al., 2021)
VIT-B/32 pretrained on OpenAI’s
400M dataset to estimate the matching probabilities between a batch of paired image-text samples.
Specifically, we randomly sample 1000 batches from the CC3M (Sharma et al., 2018) and YFCC15M (subset of YFCC100M
(Thomee et al., 2016))
datasets, and use the pretrained CLIP model to compute the image-to-text matching probabilities by taking the dot-product of the feature embeddings and taking a softmax along each row.
For each batch, we compute three statistics (averaged across rows): default probability, non-default max probability, and non-default average probability.
Note in both datasets, the matching probability between paired samples are far smaller than 1.0, and the probability decreases with the batch size.
This indicates that there exist image and text samples that are not paired, but have nontrivial matching probabilities.
This is further confirmed by the max matching probabilities between unpaired samples.
In the extreme cases (CC 3M, 2048 batch size), the average of max matching probability between unpaired image-text samples is very close to the average of probability of paired samples.
Despite prevalent noisy matching between images and texts, CLIP uses the InfoNCE loss (Hadsell et al., 2006) for training and uses the ground-truth pairings as hard labels.
This ignores the many-to-many relationship within a batch of images and text captions, leading to noisy training signals and lower data efficiency.
[Table]
To address this, we propose OTTER, or O ptimal T ranspor T distillation for E fficient zero-shot
R ecognition.
We improve InfoNCE to consider the many-to-many relationship between unpaired images and texts.
Specifically, given a batch of image and text tuples { ( v i , t i ) } i =1: N , we first use image/text encoders to estimate a similarity matrix whose elements denotes similarity from image v i to text caption t j .
Based on the similarity matrix, we use optimal transport to find a matching probability between each possible image-text combination.
To model the many-to-many relationship, we add an entropic regularization to the optimal transport so that the match is softly assigned.
Entropic-regularized optimal transport can be solved efficiently with the iterative Sinkhorn-Knopp algorithm (Cuturi, 2013).
Finally, we use the match as soft label to train the image and text encoders.
Based on pretrained image and text models, we use OTTER to train zero-shot models on the
Conceptual Captions (CC) (Sharma et al., 2018), (subset of) Wikipedia-based Image Text (Srinivasan et al., 2021), and YFCC 15M (Thomee et al., 2016) datasets, which contain 3M, 5M, and 15M image-caption pairs, respectively.
We evaluate the image encoder’s zero-shot recognition of common visual concepts on Google Open Images (GOI)
(Kuznetsova et al., 2020) (19,958 categories) and multi-labeled ImageNet 10K (10032 categories) from Tencent-ML-Images (Wu et al., 2019a).
Over 42 evaluations on 7 different dataset-architecture settings × 6 metrics, OTTER outperforms (32) or ties (2) all baselines in 34 of them.
We also propose a quantitative vision-language compositionality benchmark and show comparable results to CLIP in Appendix D.
R ELATED W ORKS
Zero-Shot Learning in Computer Vision : Zero-shot learning (ZSL) studies the generalization of knowledge to unseen classes.
Previous methods for zero-shot recognition in computer vision mainly follow three paradigms.
The first type, including DeViSE (Frome et al., 2013) and ConSE (Norouzi et al., 2014), uses pretrained word embedding vectors to represent different categories and implicitly model their relationships.
However, word embedding is a preliminary and limited representation of class relationships, which hurts performance.
The second paradigm, including GCNZ (Wang et al., 2018), DPGZ (Kampffmeyer et al., 2019), and HZSL (Liu et al., 2020), explicitly models class relationships as a graph, and uses a graph convolutional network (GCN), or a predefined class hierarchy, such as WordNet (Feinerer & Hornik, 2020), to learn the knowledge propagation between classes.
However, real-world class relationships are complicated and simple graph structures such as
WordNet are too limited to model such relationships.
Lastly, (Romera-Paredes & Torr, 2015; Akata et al., 2015; 2013) rely on human-labeled attributes to model semantics of classes.
The scalability of these methods are limited by the need for attribute annotations.
More recently, CLIP (Radford et al., 2021) applies language-supervision to ZSL by training on image caption pairs.
Our work is based on
CLIP and we generalize the InfoNCE loss to improve its data efficiency.
Vision and Language : Natural language has long been used as a source of supervision in fields like image-text retrieval Hironobu et al.
(1999), object classification Wang et al.
(2009), and video understanding (Ramanathan et al., 2013).
Socher et al.
Karpathy et al.
; Li et al.
; Chen et al.
(2021a) have proposed methods of learning visual and language representations in a joint embedding space.
More recently, (Lu et al., 2019; Chen et al., 2020c; Qi et al., 2020) propose using a cross-modal attention mechanism to increase performance in image-text matching.
In addition, (Joulin* et al., 2016; Li et al., 2017; Desai & Johnson, 2020; Sariyildiz et al., 2020) demonstrate that good visual representations can be learned by predicting image captions.
To scale up vision-language joint training, CLIP (Radford et al., 2021) and ALIGN (Jia et al., 2020) both collect their own image-text datasets with 400M and 1B image-caption pairs.
Optimal transport (OT) is a theory that enables comparison of two probability distributions whose supports may not overlap.
OT has been applied to many areas such as domain adaptation (Courty et al., 2016), generative models (Salimans et al., 2018), and self-supervised vision representation learning (Caron et al., 2020;
Asano et al., 2019).
In vision and language, (Chen et al., 2020a) uses
OT to align objects in images and words in texts.
The problem formulation of our work is similar to (Damodaran et al., 2018), where OT is used to mitigate the label noise in remote-sensing data under supervised learning.
In our paper, we extend the method from supervised learning to contrastive learning, where OT is a natural way to estimate pairings between images and texts.
In another related work, (Chen et al., 2021b) adds an additional OT-based Wasserstein loss to contrastive representation distillation (Tian et al., 2019).
The loss matches student representations to teacher representations in a batch.
(Chen et al., 2021b) is different from our method since it directly minimizes the Wassertein loss between two models’ representations, while our method uses OT to estimate the pairing probability and use the probability for knowledge distillation.
Directly minimizing Wasserstein loss between image/text embeddings in our case will lead to collapsed representations, where models generate constant output regardless of inputs.
Other related works: Our work is also related to areas including learning with noisy labels, contrastive learning, and knowledge distillation.
Our method uses OT to estimate the matching probability of unpaired images and texts.
This is reminiscent to estimating label transition probability under noisy labels (Song et al., 2020).
Our method is based on contrastive learning, which is commonly used in self-supervised visual representation learning (Chen et al., 2020b;
He et al., 2020).
For vision representation learning, (Robinson et al., 2020) argues that sampling hard negative pairs can improve learning efficiency.
For language-supervised representation learning, however, it is important to mitigate the noise of widely spread hard negative samples, since positive image-text pairs are usually only loosely correlated.
Our method is also an extension to knowledge distillation (KD) (Hinton et al., 2015).
Typical KD directly relies on a teacher model to directly generate a target distribution (Xie et al., 2020; Bagherinezhad et al., 2018; Caron et al., 2021).
Our method is different since our target distribution is computed by OT based on the pairwise similarity estimated by a teacher model.
Experiments show that this works better for image-text contrastive learning.
[Figure]
M ETHODS
We introduce OTTER in this section.
Let { ( v i , t i ) } i =1: N be a batch of paired image-text tuples sampled from data distribution p ( v , t ) .
Our model contains an image encoder f v ( · ) and a text encoder f t ( · ) that map image v i and text t i to ℓ 2 -normalized embeddings z vi and z ti respectively.
3. C ONTRASTIVE L EARNING WITH I NFO NCE L OSS
CLIP (Radford et al., 2021) trains the image and text encoders with contrastive learning to pull the paired image and text embeddings closer, and push the unpaired embeddings farther.
This is achieved by miminizing the InfoNCE loss L InfoNCE =
L v + L t .
L v is the loss for matching images to text captions, and L t is for text-to-image matching.
L v is defined as
[Equation]
1) where ( z v ⊤
i
z
tj ) is the cosine similarity between two ℓ 2 -normalized embedding vectors.
τ is a (trainable) temperature parameter.
I ij is the element of an identity matrix I N with I ii
= 1 , ∀ i and I ij = 0 , ∀ i ̸
=
j .
Note p v is normalized across z tk for k = 1 , · · · , N in the denominator.
Symmetrically, we define L t and p t in the same way as Equation (1) except we normalize across z v k .
Equation (1) is a rather redundant way of writing the InfoNCE loss, as I ij are all zeros for unpaired image-text samples.
However, this shows that InfoNCE is essentially the cross entropy between a one-hot distribution I ij and the estimated probability p v ( z vi , z tj ; τ ) .
One-hot distribution assumes that within a batch of images and text captions, the only match for image v i is its paired text caption t i .
However, as shown in Figure 1 and Table 1, this assumption is not true.
Paired images and text captions are only loosely correlated.
It is common that one image can match with several other texts and vice versa.
The ground-truth match provided by the dataset is not the only sensible match between images and texts.
One-hot labels are therefore noisy, leading to degraded learning performance.
3. M ODELING THE P ROBABILITY OF U NPAIRED I MAGE -T EXT M ATCHING
To better capture the many-to-many relationship in image-text datasets, we modify InfoNCE in
Equation (1) to consider the matching probability of unpaired images and texts.
For a batch of N image-text pairs, we define Y i ∈ { 1 , . . .
, N } as a random variable, and let q v ( Y i =
j | v 1: N , t 1: N ) be the probability that image v i should be matched with text caption t j in the batch.
We model this as
[Equation]
where M ij :=
q v ( Y i =
j | Y i ̸
= i, v 1: N , t 1: N ) , M ii = 0 ∀ i is the conditional probability of image v i being matched to t j given that it is not matched to text t i .
For simplicity, we write q vi ( j ) :
= q v ( Y i =
j | v 1: N , t 1: N ) .
α ∈ [0 , 1] is the prior probability that image
v
i is matched with its paired text caption t i .
α reflects the noise level in the dataset.
In an ideal noiseless dataset, α = 1 , so q vi ( j ) =
I ij .
This is the case where we should use the one-hot labels I ij for contrastive learning.
However, in image-text datasets, it is common for an unpaired text caption t j to be a better match for image v i , as shown in Table 1.
In this case, α < 1 and using I ij as the target distribution is no longer accurate.
So we generalize the InfoNCE loss in Equation (1) by replacing I ij with the more generic q vi ( j ) as
[Equation]
αI ij provides supervision on paired image-text samples and (1 − α )
M vij supervises unpaired samples.
The question is how do we estimate M vij .
A simple estimation is to let M vij =
(1 − I ij ) /
( N − 1) ∀ i, j be a uniform distribution.
This is equivalent to the label smoothing method proposed in (Szegedy et al., 2016).
However, this completely ignores the contents of images v 1: N and texts t 1: N .
3. M ODELING WITH O PTIMAL T RANSPORT
To design a better method of estimating M vij , we start from two intuitions: first, in a reasonable image-text dataset, there are no bad images or texts.
We assume all the images and texts are equally matchable so they should have equal matching probabilities.
Second, the matching probability from image v i to caption t j should depend on their similarity estimation S ij .
A relatively higher similarity
S ij should lead to higher matching probability M vij .
An estimation for M vij that satisfies the two intuitions can be obtained by solving the following entropic optimal transport problem (Cuturi, 2013)
[Equation]
S v ∈ R N × N is a similarity matrix whose elements S vij denotes the similarity from v i to t j .
We discuss how to compute S v in Section 3.4.
⟨ M , S v ⟩ F = (cid:80) ij M ij S vij is the Frobenius inner product between the similarity matrix S v and the matching plan M .
Maximizing this term ensures M is similar to S v , i.e. , larger S vij leads to larger M ij and vice versa.
Meanwhile, we add an entropy regularization on M as H ( M ) =
− (cid:80) ij M ij log M ij .
This ensures that M does not over concentrate on a few elements.
We constrain the solution of Equation (4) to be a transportation polytope
[Equation]
This constraint ensures that the solution M v ∗ satisfies the first intuition – all images and texts are equally important and should be matched with equal probabilities.
Moreover, as proven in (Cuturi, 2013), the solution to Equation (4) takes the form of a normalized exponential matrix
[Equation]
where r , c ∈ R N are row and column normalization vectors and can be calculated through the iterative Sinkhorn-Knopp algorithm (Cuturi, 2013).
The Sinkhorn-Knopp algorithm can be efficiently implemented on GPU and we provide a pseudo-code implementation in Appendix B.
From Equation (6), it is clear that M v ∗ satisfies our second intuition that a similarity S ij leads to higher matching probability since M v ∗ ij ∼ exp( S vij /λ ) .
The role of the entropic regularization is also clear.
A larger λ or higher entropy regularization and leads to "softer" distribution for M v ∗ ij .
On the other hand, a smaller λ or lower entropy regularization leads to "harder" distribution for M v ∗ ij .
3. C OMPUTING THE S IMILARITY M ATRIX
To compute the similarity from image v i to text t j , we can use a pair of teacher encoders ˜ f v ( · ) , ˜ f t ( · ) to compute ℓ 2 -normalized embeddings ˜
z
v i , ˜ z
t j .
Denoting ˜Z v , ˜Z t ∈ R d × N as matrcies whose columns are ˜ z v 1: N , ˜
z t 1: N respectively, we compute the similarity matrix as
[Equation]
The first term ˜Z v ⊤ ˜Z v ∈ R N × N compares the image similarities, as ( ˜Z v ⊤ ˜Z v ) ij = ˜
z
v ⊤ i ˜
z vj is the cosine similarity between image embeddings.
Intuitively, it assumes that for a pair of similar images, it is likely that we can exchange their text captions.
Similarly, ˜Z t ⊤ ˜Z t compares the text similarities.
It assumes that if a pair of text captions are similar, it is more likely that one text caption can match the other image.
The term ˜Z v ⊤ ˜Z t considers the similarity between the image and text embeddings.
Finally, η I N with η → ∞ ensures the diagonal terms of S v are infinitely small.
This effectively sets the diagonal terms of M v ∗ to 0, which is necessary since M ij is conditioned on Y i
̸
= i .
There are several options to instantiate ˜ f v ( · ) and ˜ f t ( · ) .
The simplest option is to use the original image and text encoder f v ( · ) , f t ( · ) as ˜ f v ( · ) , ˜ f t ( · ) .
Alternatively, following recent works (He et al., 2020; Caron et al., 2021; Liu et al., 2021), ˜ f v ( · ) , ˜ f t ( · ) can share the same model architecture with f v ( · ) , f t ( · ) , but their weights are updated as an exponential moving average as ˜ θ ← m ˜ θ
+ (1 − m ) θ, where ˜ θ is the weight for ˜ f v ( · ) ,
˜ f t ( · ) , θ is the weight for f v ( · ) , f t ( · ) , and m is a momentum parameter set to 0 .
Of course, we can also use trained image and text encoders such as CLIP for ˜ f v ( · ) and ˜ f t ( · ) .
We adopt the first two options in our paper, since we want to avoid using extra image-text pairs.
3. R ELATIONSHIP WITH K NOWLEDGE D ISTILLATION
OTTER is an extension of conventional knowledge distillation (KD)
(Hinton et al., 2015).
Equation (3) computes the cross entropy H ( q vi , p vi ) between q vi ( j ) and p vi ( j ) :
= p v ( z vi , z tj ; τ ) , where q vi ( j ) is the teacher distribution solved by OT and p vi ( j ) is the student distribution with logits ( z i v ⊤ z j t )
/τ computed by f ( · ) v , f ( · ) t .
A more conventional way to compute KD’s teacher distribution is
[Equation]
where ˜z vi , ˜z tj are computed by the teacher ˜ f v ( · ) , ˜ f t ( · ) .
We can re-write Equation (8) in the matrix form as Q v =
Diag ( r ) exp( ˜Z v ⊤ ˜Z t /τ )
Diag ( c ) , where r i = 1 , and c i = 1 / (cid:80) Nk
=1 exp(( ˜z v ⊤ i ˜z tk ) /τ ) .
Note this teacher distribution has the same form as OTTER in Equation (6), but with two differences.
First,
OTTER’s similarity matrix S v in Equation (7) have three more terms: γ v ˜Z v ⊤ ˜Z v , γ t ˜Z t ⊤ ˜Z t , η I N .
In comparison, KD ignores image-image, text-text similarities and does not exclude diagonal terms.
By setting γ v = γ t = η = 0 , their similarity matrices are equivalent.
Second, OTTER’s normalization vectors r , c in Equation (6) are solved with Sinkhorn-Knopp while for KD r , c are computed by a
Softmax function.
In fact, if we set the #iteration to 0 in Algorithm 2 (Appendix B), Sinkhorn-Knopp is equivalent to Softmax, as also noted by (Caron et al., 2021).
E XPERIMENTS
In this section, we discuss our experiments validating the effectiveness of OTTER.
We open-sourced our code at https://github.com/facebookresearch/OTTER .
To setup a baseline, we follow CLIP (Radford et al., 2021) to train an image and a text encoder to predict the pairing of image and text samples using the infoNCE loss.
Since the dataset used by CLIP is not released, we train on three publicly available datasets, Conceptual Captions 3M (CC) (Sharma et al., 2018),
Wikipedia-base Image-Text Dataset (WIT)
, and YFCC 15M (Thomee et al., 2016).
We only train on images with English captions in all 10 partitions of the WIT dataset, resulting in 5M image-text pairs in total.
Since the datasets we use are small ( ∼ 100x smaller than the one used by CLIP), we have to use pre-trained models to initialize the image and text encoders.
Also, due to the datasets’ limited scale and concept coverage, models trained on CC or WIT do not perform well on domain-specific datasets such as Stanford Cars (Krause et al., 2013) and FGVC Aircraft (Maji et al., 2013).
To test zero-shot recognition on common visual concepts , we evaluate our models on the test set of Google
Open Image (GOI) (Kuznetsova et al., 2020), which contains 19,958 classes.
We also evaluate on the test set of multi-labeled ImageNet 10K (10032 classes) dataset whose labels come from Tencent
ML-Images (Wu et al., 2019a).
Each image in ImageNet 10K is auto-labeled with highly-correlated class labels from GOI, alleviating the single-label issue of ImageNet 21K and 1K. To compare with previous ZSL methods (Norouzi et al., 2014; Frome et al., 2013; Wang et al., 2018; Liu et al., 2020), we report the ZSL performance of one of our models on ImageNet21K+1K.
Training: We adopt a training recipe similar to BiT’s finetuning strategy (Kolesnikov et al., 2020):
We use SGD with an initial learning rate of 3e-3, a cosine annealing scheduler, momentum 0.9, and no weight decay.
Input images are resized to 256x256 and randomly cropped to 224x224 while test images are resized to 256x256 and center-cropped to 224x224.
We train on 8 V100 GPUs using
Pytorch (Paszke et al., 2019) distributed data parallel with a total batch size of 512 (64 per GPU) for
10 epochs.
While CLIP (Radford et al., 2021) computes InfoNCE using sub-batches on each GPU, we gather logits from all GPUs for OTTER and baselines.
Inference: For inference, we follow CLIP to compute the text embeddings for the target classes using the trained text encoder, and we use a prompt template of “a photo of {label}" to augment the label texts.
Next, we fit a KNN using the text embeddings.
Given an image, we find the top K nearest label embedding neighbors to the image embedding based on cosine similarity.
Evaluation: GOI (Kuznetsova et al., 2020) and ImageNet 10K from Tencent-ML-Images (Wu et al., 2019a) are multi-labeled.
Following previous work on ZSL (Norouzi et al., 2014; Frome et al., 2013;
Wang et al., 2018; Liu et al., 2020), we use flat hit @ k (FH@K) for evaluation.
FH@K is the percentage of test images such that the top K predictions of the model overlap with true labels and is formally defined as 1 N (cid:80) Ni =1 1 ( {{ f ( v i ) } K ∩ L i ̸ = ∅ } ) , where { f ( v i ) } K is the top K predictions for the i -th image and L i is the set of true labels.
[Table] [Table]
C OMPARING OTTER WITH B ASELINES
To compare with OTTER
[Table]
we include three baselines: 1) InfoNCE with hard labels; 2) InfoNCE with label-smoothing (LS) (Szegedy et al., 2016), as described in Section 3.2; 3) InfoNCE with knowledge distillation (KD) (Hinton et al., 2015), as described in Section 3.5.
In addition to the experimental setting described above
[Table]
we use the following OTTER hyper-parameters: we set the loss coefficient α = 0 .
5 , set γ v = γ t = 1 for the similarity matrix.
We use the exponential-moving average (EMA) of the image/text encoders as teachers and set the EMA decay to 0.999.
For Sinkhorn-Knopp, we set
[Table]
λ = 0 .
15 and the number of iterations to 5.
For the KD baseline, we also use EMA teacher and set α = 0 . 5 .
For the label-smoothing baseline, we set α = 0 .
9 , which yields better results than α = 0 .
On CC, we train the image-text models based on four different pretrained image encoders:
ResNet- {50, 34} (He et al., 2016), FBNetV3-{A, C} (Wu et al., 2019b; Wan et al., 2020;
Dai et al., 2020), and two pretrained text encoders: DeCLUTR-Sci-base (Giorgi et al., 2020) pretrained on S2ORC (Lo et al., 2020) and Sentence BERT (Reimers & Gurevych, 2019) pretrained on SNLI (Bowman et al., 2015) and MultiNLI (Williams et al., 2018).
We also train ResNet50 + DeCLUTR-Sci-base on the (partial) WIT (Srinivasan et al., 2021) and the YFCC15M (subset of YFCC 100M) (Thomee et al., 2016) datasets.
We report FH@K=1, 5, 10 on the test sets of both GOI and multi-labeled
ImageNet 10K (Wu et al., 2019a).
As shown in Table 2, over the 42 evaluations on 7 different dataset-architecture settings x 6 metrics, OTTER outperforms (32) or ties (2) all other baselines in 34 of them.
Compared with CLIP’s performance on the GOI test set, a ResNet50 trained by
OTTER outperforms CLIP-RN50 by 2.6 pts FH@1 and by 6.6 pts FH@10.
To further illustrate the significance of the performance gain, we show that a ResNet50 (25.6M params) trained with OTTER outperforms a Wide ResNet50x2 (68.4M params) trained with InfoNCE under the same setting.
For reference, to put OTTER in the context of traditional ZSL methods, we present FH@K results on zero-shot transfer to the ImageNet 21K+1K (Deng et al., 2009) dataset, which contains 21,841 classes in total.
The result is reported in Table 3.
With 400M image-text pairs, CLIP (Radford et al., 2021) vastly outperforms all other methods.
ImageNet22K’s classes contain many uncommon words, such as scientific names of animals or medical terms.
While not directly comparable with traditional ZSL methods due to differences in datasets used and model architectures, OTTER is significantly better than previous ZSL methods, beating the previous SotA, HZSL(Liu et al., 2020), by 68% relatively.
4. V ISUALIZING OTTER
In order to check if the image/text matching found by OTTER is sensible, we provide visualizations of OTTER’s matching results.
In Figure 3, we visualize the matching results on a small batch ofimage-text pairs.
We set α = 0 .
5 for paired image-text samples, as shown in the diagonal elements in Figure 3.
The off-diagonal elements are estimated by OTTER.
Since the interpretation of the matching results are highly subjective, we leave the interpretation to readers.
Next, we use OTTER to process a larger batch of 512 image-text pairs.
This is our batch size for training.
We pick the top-8 largest off-diagonal pairs from the optimal tranport result and show them in Figure 4.
As we can see, in a large batch, we can easily find unpaired images and captions that turn out to be good matches.
InfoNCE will simply regard these pairs as negative examples and push them away from each other while OTTER can better handle this by treating them as semi-positive pairs.
4. I MPORTANCE OF S IMILARITY M ATRIX AND EMA
In Equation 7, we design the similarity matrix S v as the composition of image, text, and image-text similarity matrices.
In Table 4, we show experiments to validate the effectiveness of this composition and the necessity of using EMA.
There are various levels of performance drop when we don’t use the image or text similarities, or when EMA is turned off.
Note that our baseline hyper-parameters are different from Table 2, so the accuracy is also different.
We compare different settings using
FH@K=1 on the GOI test set.
More in-depth ablation studies are shown in Appendix A. one of the most dramatic mountain ranges I have seen aerial: woman waving her arms on the rock cinematic aerial shot of the dramatic coastline at the cliffs view of a loch and pine forest a forest of stunted trees that stand in sharp contrast … landscape with mown grass and a haystack newly built small house next to the sea and the beach the public house traditional pub in old building on corner a cottage in the picturesque village
[Figure]
ice hockey
[Figure]
blocks a shot during the second period … vector illustration with a cup of coffee and hand drawn … a cute cat starring with sharp eyes seamless sketch of a cup of hot coffee and steam close-up of a calico cat playing with a toy profession cuts the hair of the client with clipper
[Table]
similaritymatrix
[Table]
C ONCLUSION
Image-text datasets collected from the Internet are noisy, and the InfoNCE loss used by previous works such as CLIP fails to recognize the potential matches between unpaired images and captions in a batch.
As a solution, OTTER extends the InfoNCE loss to consider the many-to-many relationship between unpaired images and texts by computing a pair-wise similarity matrix and using entropic optimal transport to solve for the off-diagonal matching probabilities.
OTTER outperforms (32) or ties (2) all other baselines on Google Open Images and ImageNet 10K in 34 out of 42 comparisons.
In future research, we want to test the effectiveness of OTTER on larger datasets, such as CLIP 400M.
A A BLATION S TUDIES
In this section
[Table]
we analyze the impact of hyper-parameters on the performance of OTTER in Table 5.
Note that our baseline hyper-parameters are different from Table 2, so the accuracy is also different.
We compare different settings using FH@K=1 on the GOI test set.
[Table]
Confidence in the image-text pairs: In Section 3.2, we define α = q vi ( i ) as the probability that the paired text caption is the correct match with the image.
This reflects the confidence, or the noise level, in the ground truth pairs.
We set α = 0 .
9 in our experiment, and found that both lack of confidence (0.1) or over-confidence (0.9) can hurt the performance.
Relatively, α = 0 .
9 leads to worse performance, validating the necessity of mitigating label noise.
Image-to-image, text-to-text similarity: We included the image and text similarity when computing the pair-wise similarities for OT.
The assumption is that samples with similar images or text captions are likely to share labels.
To test this, we set γ v , γ t to 0 in the experiments.
We found that both image-to-image and text-to-text similarity are helpful.
Relatively, text similarity seems to be more important than image similarity, as removing text similarity leads to a larger performance drop.
Do we need EMA teacher?
In the default setting, we used the exponential moving average of the image/text encoders to compute the similarity estimation.
We test the alternative option of using the image/text encoders themselves, and found that this leads to a small accuracy drop (0.6 points).
Impact of optimal transport: One key component of OTTER is to use optimal transport to match images with text captions within a batch.
However, do we really need optimal transport?
To compute the teacher distillation, a simple alternative is to use a Softmax function.
As we discussed in Section 3.5, Softmax is equivalent to our Sinkhorn-Knopp implementation when we set the number of iterations to 0.
So we validate the necessity of optimal transport by setting the #iteration to 0, 2, 4, 6.
Experiments show that using Softmax (0 iteration of Sinkhorn) leads to the worst performance (-1.9).
This validates the necessity of using optimal transport to ensure all images and texts within a batch are matchable.
Besides, using 2 (fewer) and 6 (more) iterations also lead to accuracy drops (-1.7, -1.0).
Using more iterations of Sinkhorn leads to a more converged solution to the optimal transport problem, but this does not seem to be positively correlated with better performance.
We also explored the impact of entropy regularization controlled by λ in Equation (6).
Experiments show that the target distribution being too "hard" ( λ = 0 . 05) or too "soft" ( λ = 0 . 30) can hurt the performance.
Batch size: Previous works on contrastive learning show that a larger batch size raises the lower bound of mutual information (Hadsell et al., 2006) and leads to better performance (Chen et al., 2020b; He et al., 2020).
However, for noisy image-text pairs, larger batch sizes can potentially bring more unpaired matches.
We study the impact of batch sizes by setting it to 256 , 512 , 768 in the experiments.
We find that both smaller (256) and larger (768) batch sizes lead to worse performance.
We hypothesize that batch size needs to be co-adapted with hyper-parameter settings of α and λ .
α estimates the noise level, which is positively correlated with the batch size.
λ yields different "softness" with different batch sizes.
However, further investigation is to required to validate this.
B P SEUDOCODE FOR OTTER
[Table] [Table]
for img, txt in loader: # Regular InfoNCE loss emb
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table] [Table]
logits =
[Table]
[Table] [Table]
L_
[Table]
=
[Table]
[Table] [Table]
, I_N
[Table]
+ xent(
[Table] [Table]
, I_N)
[Table]
emb_v_t, emb_t_t =
ft
[Table] [Table]
[Equation] [Equation]
[Table]
[Equation]
sim
[Equation] [Equation]
N #
[Table]
M
[Table]
[Equation]
[Table]
[Equation]
M
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table]
[Equation]
[Table] [Table]
update(fs, ft, tpi, tpd)
Algorithm 2: PyTorch Pseudocode for Sinkhorn- def sinkhorn(S, lambda=0.15, niter=5): T = exp(S / lambda)
T = T / T.sum() N = T.shape[0] # iterative row/column normalization for _ in range(niter):
T /=
(T.sum(dim=1, keepdim=
True) * N) # row normalization T /=
(T.sum(dim=0, keepdim=
True)
* N) # column normalization
# Note if niter=0, this is equivalent to Softmax return T /= T.sum(dim=1, keepdim=True) # row normalization
C V ARIANCE A NALYSIS
In our experiments, we noticed variance of experimental results with identical settings.
To study this, we repeat the experiments in Table 2 with a ResNet50 image encoder and a DeCLUTR-Sci-base text encoder for 3 times each using different random seed to analyze the variance of the experiments.
We noticed higher variance on GOI experiments.
For example, for the FH@10 metric, the variance can be up to 1.88 pts.
Note that the mean accuracy’s gap between OTTER and baselines are all significantly larger than the standard deviation, indicating that the performance improvement of OTTER is not a result of randomness.
However, such high variance is worth noting and requires future investigation on how to reduce it.
[Table]
D Q UANTITATIVE A NALYSIS ON THE I MAGE -T EXT C OMPOSITIONALITY ON CUB
ALIGN Jia et al.
(2020) presents an interesting demonstration of the compositionality of image and text embeddings generated by language supervised vision models.
On an image retrieval task, a query is formed by adding an image embedding vector to a text embedding vector.
The returned image is expected to be similar to the image query and the text query.
ALIGN demonstrates the compositionality by qualitatively showing several retrieval results
[Table]
but does not provide any quantitative evaluations.
In this paper, we design a preliminary benchmark based on the CUB dataset (Welinder et al.
to evaluate the image-text compositionality.
[Table]
(cid:38)(cid:82)(cid:86)(cid:76)(cid:81)(cid:72)(cid:3)(cid:54)(cid:76)(cid:80)(cid:76)(cid:79)(cid:68)(cid:85)(cid:76)(cid:87)(cid:92) (cid:39)(cid:68)(cid:87)(cid:68)(cid:86)(cid:72)(cid:87)(cid:3)(cid:76)(cid:80)(cid:68)(cid:74)(cid:72)(cid:3)(cid:72)(cid:80)(cid:69)(cid:72)(cid:71)(cid:71)(cid:76)(cid:81)(cid:74) (cid:52)(cid:88)(cid:72)(cid:85)(cid:92)(cid:3)(cid:72)(cid:80)(cid:69)(cid:72)(cid:71)(cid:71)(cid:76)(cid:81)(cid:74)(cid:86) (cid:44)(cid:80)(cid:68)(cid:74)(cid:72)(cid:3)(cid:14)(cid:3)(cid:87)(cid:72)(cid:91)(cid:87)(cid:3)(cid:84)(cid:88)(cid:72)(cid:85)(cid:76)(cid:72)(cid:86)
CUB (Welinder et al.
(2010)) consists of 6033 bird images, and each image- i is annotated with a set of bird attributes, which we denote as A i .
In this dataset, there are in total 288 unique attributes.
Given an image and several CUB bird attributes in text, we generate image and text embeddings using our pretrained models and add the embeddings together to form a query embedding vector.
We use the query vector to match images in CUB, and choose the nearest neighbor, based on cosine similarity, as the retrieved image.
This process is illustrated in Figure 5.
To evaluate the retrieval quality, we compare the overlap between the retrieved image’s attributes with the image-text query’s attributes.
We now describe how we generate text queries in addition to an image query.
Randomly adding text attributes to image queries may result in unmatchable queries.
To ensure that the added text query is sensible and the combined image-text query can be matched to an image in the dataset, we obtain a text query with the following approach: We first select a pair of images, denoted as image- i and image- j .
We use image- i as the image query, and let Q v =
A i be the image query’s attribute set.
Then, to form the text query, we compare the differences of image- j and i , and let
Q t =
A j − A
i be the text query’s attribute set.
The combined image-text query should contain attributes Q = Q v (cid:83) Q t .
We show an example of image query, text query, and combined query in
Figure 6.
Following this process, we generate 1,000,000 image-text queries from randomly sampled image pairs from CUB where each image pair shares at least 10 common attributes.
The image-text queries used in our experiment are provided in the attached file image_text_query_list.txt in the supplementary material.
[Table]
Our evaluation measures the overlap between the retrieved image’s attribute set R k with the imagetext query set Q k , image query set Q vk , text query set Q tk .
Specifically, we compute: 1) the attributes overlapping rate (OR) 1 N (cid:80)
Nk =
| Q k ∩ R k | | Q k | .
This measures the retrieval quality for the combined image-text query.
2) the average image attributes overlapping rate (IOR) 1 N (cid:80) N k =1 | Q vk ∩ R k | | Q v k | .
This evaluates if the returned image hits/misses attributes in the image query.
3) the average text attributes overlapping rate (TOR) 1 N (cid:80)
Nk =
| Q tk ∩ R k | | Q tk | .
This evaluates if the retrieved image hits/misses attributes of text queries.
An ideal match should achieve higher scores in OR, IOR, and TOR simultaneously
[Table]
We report our results comparing with CLIP and other baselines in Table 7.
First, we report the measurement of a random baseline.
With this random baseline, for any image-text query, we return a random image from the dataset.
We can see that this gives a non-trivial OR (27.7%), IOR (31.3%), and TOR (23.2%).
This is not surprising because images in CUB have many overalapping attributes.
However, although both CLIP and our models are never directly trained on CUB nor trained to predict bird attributes, their overlapping rates are significantly higher than the random baseline.
CLIP achieves comparable accuracy with our models, with 1% higher OR, 2.3% higher IOR, and -2.2% lower TOR.
Among different training methods, OTTER outperforms all baselines in OR and IOR, and achieves slightly worse (-0.1%) TOR than the InfoNCE baseline.
Also note that our models achieve similar IOR and TOR, which shows both image and text queries are considered.
This demonstrates good compositionality.
In Figure 7, we show qualitative results of our model trained by OTTER.
For example, in the first row, we add yellow forehead color , black eye color , yellow upper-parts color and yellow breast color as text attributes to an image of a black bird.
The retrieved bird image contains attributes from both image and text queries – it has yellow body colors while maintains black leg and black wing colors.
From both quantitative and qualitative results, our model demonstrates good image-text compositionality.
E I MAGE A TTRIBUTIONS
Figure 1, Paul Bica, Coast of Kauai, Hawaii, CC BY 2. 2.
Figure 1, James St. John, Columnar-jointed rhyolitic obsidian lava flow, CC BY 2. 3.
Figure 1, Mordaka, QK9A1397, CC BY-SA 4. 4.
Figure 1, Alan Reid, Heathery moor on the flank of Stone Saul, CC BY-SA 2. 5.
Figure 1, Jimmy Emmerson, The Tormented Valley, CC BY
NC
ND
Figure 1, Roman Boed from The Netherlands, Black Forest- Meadow (10561897306), CC
Figure 1, Daniel Clerc / CC-BY-SA-3.0, 2013 bois herpin 013, CC BY-SA 3.
Figure 1, Dave Bevis, 22 and 24 High Street, Newcastle-under-Lyme, CC BY-SA 2. 9.
Figure 1, Nilfanion, Thatched cottages in Coverack (8379), CC BY-SA 4.
Figure 4, TheAHL, Chuck Kobasew (cropped), CC BY
Figure 4, Mark Mauno, Jasper Fitzi, CC BY 2. 12.
Figure 4, Famartin, 2020-04-27 18 55
A Calico cat looking for food in a kitchen in the Franklin Farm section of Oak Hill, Fairfax County, Virginia, CC BY-SA
Figure