Deep image representations using caption generators

by   Konda Reddy Mopuri, et al.
indian institute of science

Deep learning exploits large volumes of labeled data to learn powerful models. When the target dataset is small, it is a common practice to perform transfer learning using pre-trained models to learn new task specific representations. However, pre-trained CNNs for image recognition are provided with limited information about the image during training, which is label alone. Tasks such as scene retrieval suffer from features learned from this weak supervision and require stronger supervision to better understand the contents of the image. In this paper, we exploit the features learned from caption generating models to learn novel task specific image representations. In particular, we consider the state-of-the art captioning system Show and Tell SnT-pami-2016 and the dense region description model DenseCap densecap-cvpr-2016. We demonstrate that, owing to richer supervision provided during the process of training, the features learned by the captioning system perform better than those of CNNs. Further, we train a siamese network with a modified pair-wise loss to fuse the features learned by SnT-pami-2016 and densecap-cvpr-2016 and learn image representations suitable for retrieval. Experiments show that the proposed fusion exploits the complementary nature of the individual features and yields state-of-the art retrieval results on benchmark datasets.


page 1

page 2

page 3

page 4


Feature-informed Embedding Space Regularization For Audio Classification

Feature representations derived from models pre-trained on large-scale d...

Learning Deep Representations of Medical Images using Siamese CNNs with Application to Content-Based Image Retrieval

Deep neural networks have been investigated in learning latent represent...

Adversarially-Trained Deep Nets Transfer Better

Transfer learning has emerged as a powerful methodology for adapting pre...

Transfer Learning for Clinical Time Series Analysis using Recurrent Neural Networks

Deep neural networks have shown promising results for various clinical p...

SUPERB-SG: Enhanced Speech processing Universal PERformance Benchmark for Semantic and Generative Capabilities

Transfer learning has proven to be crucial in advancing the state of spe...

Learning Deep Representations via Contrastive Learning for Instance Retrieval

Instance-level Image Retrieval (IIR), or simply Instance Retrieval, deal...

Learning Finer-class Networks for Universal Representations

Many real-world visual recognition use-cases can not directly benefit fr...

Code Repositories

1 Introduction

Deep learning has enabled us to learn various sophisticated models using large amounts of labeled data. Computer vision tasks such as image recognition, segmentation, face recognition, etc. require large volumes of labeled data to build reliable models. However, when the training data is not sufficient, in order to avoid over-fitting, it is a common practice to use pre-trained models rather than training from scratch. This enables us to utilize the large volumes of data (eg: 

[3]) on which the pre-trained models are learned and transfer that knowledge to the new target task. Hierarchical nature of the learned representations and task specific optimization makes it easy to reuse them. This process of reusing pre-training and learning new task specific representations is referred to as transfer learning or fine-tuning the pre-trained models. There exist many successful instances of transfer learning (e.g. [4]

) in computer vision using Convolution Neural Networks (CNNs). Large body of these adaptations are fine-tuned architectures of the well-known recognition models 

[5, 6, 7, 8, 9, 10]

trained on the IMAGENET 

[3] and Places [9] datasets.

Figure 1: Sample image-caption pairs from MSCOCO dataset [11]. The caption gives more information than just listing down the objects present in the image. For example, caption for image on the right panel provides additional information such as separated by mesh fence which is not available with the labels alone. The proposed method exploits the features learned with this stronger supervision to achieve efficient task specific image representations.

However, these models perform object or scene classification and have very limited information about the image. All that these models are provided with during training is the category label. No other information about the scene is provided. For example, the image shown in Figure

2 has dog and person as labels. Useful information such as indoor or outdoor, interaction between the objects, presence of other objects in the scene is missing. Tasks such as image search (similar image retrieval) suffer from the features learned by this weak supervision. Image retrieval requires the models to understand the image contents in a better manner (eg: [12, 13]) to be able to retrieve similar images. Specifically, when the images have multiple objects and graded relevance scores (multiple similarity levels, eg: on a scale from to ) instead of binary relevance (similar or dissimilar), the problem becomes more severe.

On the other hand, automatic caption generation models (e.g. [14, 1, 15, 16]) are trained with human given descriptions of the images. These models are trained with stronger supervision compared to the recognition models. For example, Figure 1 shows pair of images form MSCOCO [11] dataset along with their captions. Richer information is available to these models about the scene than mere labels. In this paper, we exploit the features learned via strong supervision by these models and learn task specific image representations for retrieval via pairwise constraints.

In case of CNNs, the learning acquired from training for a specific task (e.g. recognition on IMAGENET) is transferred to other vision tasks. Transfer learning followed by task specific fine-tuning has proven to be efficient to tackle less data scenarios. However, similar transfer learning is left unexplored in the case of caption generators. For the best of our knowledge, this is the first attempt to explore that knowledge via fine-tuning the representations learned by them to a retrieval task.

Figure 2: Predictions of Show and Tell [1] and Densecap [2] models on a sample image from the rPascal [17] dataset. Note that they are complementary in nature: [1] (left panel) gives summary of the scene, where as [2] (right panel) provides more details about the individual objects. The Proposed fusion network benefits from both to learn an efficient image representation.

The major contributions of our work can be listed as:

  • We show that the features learned by the image captioning systems represent image contents better than those of CNNs via image retrieval experiments. We attempt to exploit the strong supervision observed during their training via transfer learning.

  • We train a siamese network using a modified pair-wise loss suitable for non-binary relevance scores to fuse the complementary features learned by [1] and [2]. We demonstrate that the task specific image representations learned via our proposed fusion achieve state-of-the-art performance on benchmark retrieval datasets.

The paper is organised as follows: Section 2 provides a short summary of [1] and [2] before presenting details about the proposed approach to perform transfer learning. This section also discusses the proposed fusion architecture. Section 3 details the experiments performed on benchmark datasets and discusses various aspects along with the results. Finally, Section 4 concludes the paper.

2 Alternate Image Representations

Transfer learning followed by task specific fine-tuning is a well known technique in deep learning. In this section we present an approach to exploit the fine supervision employed by the captioning models and the resulting features. Especially, we target the task of similar image retrieval and learn suitable features.

Figure 3: Overview of the Show and Tell [1] system. Note that the green arrow indicates the image encodings and the orange denotes word embeddings. is the predicted word at time instant and

denotes the output of the soft-max probability distribution over the dictionary words.

Throughout the paper, we consider the state-of-the art captioning model Show and Tell by Vinyals et al. [1]. Their model is an encoder-decoder framework containing a simple cascading of a CNN to an LSTM. The CNN encodes visual information from the input image and feeds via a learnable transformation to the LSTM. This is called image encoding, which is shown in Figure 3 in green color. The LSTM’s task is to predict the caption word by word conditioned on the image and previous words. Image encoding is the output of a transformation () learned from the final layer of the CNN (Inception V3 [18]) before it is fed to the LSTM. The system is trained end-to-end with image-caption pairs to update the image and word embeddings along with the LSTM parameters. Note that the Inception V3 layers (prior to image encoding) are frozen (not updated) during the first phase of training and they are updated during the later phase.

The features at the image encoding layer (green arrow in Figure 3) are learned from scratch. Note that these are the features input to the text generating part and fed only once. These features are very effective to summarize all the important visual content in the image to be described in the caption. These features need to be more expressive than the deep fully connected layers of the typical CNNs trained with weak supervision (labels). Therefore, we consider transferring these features to learn task specific features for image retrieval. We refer to these features as Full Image Caption features since the generated caption gives a visual summary of the whole image.

On the other hand Johnson et al. [2] proposed an approach to densely describe the regions in the image, called dense captioning task. Their model contains a fully convolutional CNN for object localization followed by an RNN to provide the description. Both the modules are linked via a non-linear projection (layer), similar to [1]. The objective is to generalize the task of object detection and image captioning. Their model is trained end-to-end over the Visual genome [19] dataset which provides object level annotations and corresponding descriptions. They fine-tune the later (from fifth) layers of the CNN module (VGG [6] architecture) along with training the image encodings and RNN parameters. Similar to features we consider the image encodings to transfer the ability of this model to describe regions in the image. This model provides encodings for each of the described image regions and associated priorities. Figure 2 (right panel) shows an example image and the region descriptions predicted by DenseCap model. Note that the detected regions and corresponding descriptions are dense and reliable. In order to have a summary of the image contents, we perform mean pooling on the representations (features) belonging to top-K (according to the predicted priorities) regions. We refer to the pooled encodings as Densecap features.

Especially for tasks such as image retrieval, models trained with strong object and attribute level supervision can provide better pre-trained features than those of weak label level supervision. Therefore, we propose an approach to exploit the Densecap features along with the features and learn task specific image representations.

2.1 Complementary features and Fusion

Figure 2 shows descriptions predicted by [1] and [2] for a sample image. Note that the predictions are complementary in nature. provides the summary of the scene: a boy is standing next to a dog. Where as, Densecap provides more details about the scene and objects: presence of green grass, metal fence, brick wall and attributes of objects such as black dog, white shirt,etc.

In the proposed approach, we attempt to learn image representations that exploit the strong supervision available from the training process of [1] and [2]. Further, we take advantage of the complementary nature of these two features and fuse them to learn task specific features for image retrieval.

Figure 4: The proposed siamese architecture learns image representations by fusing the complementary information extracted from [1] and [2]. Note that both the wings contain a series of dense layers whose weights are tied. The similarity is computed at the final layer and error is back propagated to update the intermediate layers.

We train a siamese network to fuse both the features. The overview of the architecture is presented in Figure 4. The proposed siamese architecture has two wings. A pair of images is presented to the network along with their relevance score (high for similar images, low for dissimilar ones). In the first layer of the architecture, and Densecap features are late fused (concatenated) and presented to the network. A sequence of layers is added on both the wings to learn discriminative embeddings. Note that these layers on both the wings have tied weights (identical transformations in the both the paths). In the final layer, the features are compared to find the similarity and the loss is computed with respect to the ground truth relevance. The error gets back-propagated to update the network parameters. Our network accepts the complementary information provided by both the features and learns a metric via representations suitable for image retrieval. More details about the training are presented in section 3.4.

3 Experiments

3.1 Datasets

Figure 5: Example query images and their relevant images. Top row belongs to rPascal and bottom row belongs to rImagenet dataset. Note that in the top right corner of the image it’s relevance to query is shown in red and images are arranged in decreasing order of their relevance.
Figure 6: Retrieval performance of the features on rPascal dataset. Note that the features learned by the caption generation system [1] outperform the underlying inception v3 features (non-finetuned visual features) and the word2vec pooled representations of the predicted captions. They also beat the state-of-the art Attribute Graph method [17].
Figure 7: Retrieval performance of the features on rImagenet dataset. Note that the features learned by the caption generation system [1] outperform the underlying inception v3 features (non-finetuned visual features) and the word2vec pooled representations of the predicted captions. They also beat the state-of-the art Attribute Graph method [17].

We begin by explaining the retrieval datasets111The datasets are available at considered for our experiments. In order to have more natural scenario, we consider retrieval datasets that have graded relevance scores instead of binary relevance (similar or dissimilar). We require the relevance to be assigned based on overall visual similarity as opposed to any one particular aspect of the image (e.g. objects). To match these requirements, we consider two datsets rPascal (ranking Pascal) and rImagenet (ranking Imagenet) composed by Prabhu et al. [17]. These datasets are subsets of aPascal [20] and Imagenet [3] respectively. Each of the datasets contains query images and a set of corresponding relevant images. They are composed by annotators participating to assign relevance scores. The scores have grades, ranging from (irrelevant) to (excellent match).

  • rPascal: This dataset is composed from the test set of aPascal [20]. The queries comprise of indoor and outdoor scenes. The dataset consists of a total of images with an average of reference images per query.

  • rImagenet: It is composed from the validation set of ILSVRC 2013 detection challenge. Images containing at least objects are chosen. The queries contain indoor scenes and outdoor scenes. The dataset consists of a total of images with an average of reference images per query.

Figure 5 shows sample images from the two datasets. Note that the first image in each row is query and the following images are reference images with relevance scores displayed at top right corner.

3.2 Evaluation metric

We followed the evaluation procedure presented in [17]

. For quantitative evaluation of the performance, we compute normalized Discounted Cumulative Gain (nDCG) of the retrieved list. nDCG is a standard evaluation metric used for ranking algorithms (e.g.

[21] and [17]). For all the queries in each dataset, we find the nDCG value and report the mean nDCG per dataset evaluated at different ranks (K).

3.3 Features learned by the caption generator ()

Figure 8: Retrieval performance of the learned image representations over rPascal dataset.

In this subsection we demonstrate the effectiveness of the features obtained from the caption generation model [1]. For each image we extract the features to encode it’s contents. Note that these are the features learned by the caption generation model via the strong supervision provided during the training. Retrieval is performed by computing distance between the query and the reference images’ features and arranging in the increasing order of the distances.

Figure 6 and  7 show the plots of nDCG evaluted at different ranks on the two datasets. As a baseline comparison, we have compared the performance of features with that of the non-finetuned visual features of inception v3 model (blue color plot in Figure 6 and 7). Note that these are features that are extracted from the last fully connected layer of the inception v3 model [18]. The features outperform the non-finetuned visual features by a large margin emphasizing the effectiveness of the strong supervision.

We have considered another baseline using the natural language descriptors. For a given image, we have predicted the text caption using the Show and Tell [1] model. After pre-processing (stop word removal and lemmatizing), we encode each of the remaining words using word2vec [22] embeddings and mean pool them to form an image representation. Note that the features perform better than this baseline also.

We also compare the performance of features against the state-of-the art Attribute graph approach [17]. The features clearly outperform the Attribute Graph approach in case of both the benchmark datasets.

3.4 Task specific fine-tuning through fusion

Figure 9: Retrieval performance of the learned image representations over rImagenet dataset.

The proposed fusion architecture222Project codes can be found at is trained with pairs of images and corresponding relevance scores . The typical pairwise training consists of binary relevance scores: simila r or dissimilar . The objective is to reduce the distance between the projections of the images if they are similar and separate them if dissimilar. Equation (1) shows the contrastive loss [23] typically used to train siamese networks.


where, is the prediction error, is the mini-batch size, is the relevance score ( or ), is the distance between the projections of the pair of images and is the margin to separate the projections corresponding to dissimilar pair of images.

However, in practice images can have non-binary relevance scores. To handle more fine grained relevances, we modified the contrastive loss function to include non-binary scores as shown in equation (



where is indicator function. Note that the modified loss function favours the nDCG measure by strongly punishing (due to the square term) the distances between images with higher relevance scores.

We train a siamese network with fully connected layers on both the wings, with tied weights. The number of units in each wing are . The representations learned at the last layer are normalized and euclidean distance is minimized according to Equation (2). We divide the queries into splits to perform fold validation and report the mean nDCG. That is, each fold contains image pairs of queries and corresponding reference images for training. The remaining queries form the evaluation set. On an average, each fold contains training pairs for rPascal and pairs for rImagenet.

Figures 8 and 9 show the performance of the task specific image representations learned via the proposed fusion. For evaluating the performance of the Densecap [2] method, we have mean pooled the encodings corresponding to top- image regions resulting a feature. feature is also vector, therefore forming an input of to the network. Note that the transfer learning and fine-tuning through fusion improves the retrieval performance on both the datasets.

4 Conclusion

In this paper, we have presented an approach to exploit the strong supervision observed in the training of caption generation systems. We have demonstrated that image understanding tasks such as retrieval can benefit from this strong supervision compared to weak label level supervision. Transfer learning followed by task specific fine-tuning is commonly observed in CNN based vision systems. However similar practice is relatively unexplored in the case of these captioning systems. Our approach can potentially open new directions for exploring other sources for stronger supervision and better learning. It can also motivate to tap the juncture of vision and language in order to build more intelligent systems.

5 Acknowledgement

This work was supported by Defence Research and Development Organization (DRDO), Government of India.


  • [1] Oriol Vinyals, Alexander Toshev, Samy Bengio, and Dumitru Erhan, “Show and tell: Lessons learned from the 2015 mscoco image captioning challenge,” IEEE PAMI, 2017.
  • [2] Justin Johnson, Andrej Karpathy, and Li Fei-Fei, “Densecap: Fully convolutional localization networks for dense captioning,” in CVPR, 2016.
  • [3] Olga Russakovsky et al., “ImageNet Large Scale Visual Recognition Challenge,” IJCV, 2015.
  • [4] Liang-Chieh Chen, George Papandreou, Iasonas Kokkinos, Kevin Murphy, and Alan L Yuille, “Semantic image segmentation with deep convolutional nets and fully connected CRFs,” in ICLR, 2015.
  • [5] Alex Krizhevsky, Ilya Sutskever, and Geoffrey E. Hinton, “Imagenet classification with deep convolutional neural networks,” in NIPS. 2012.
  • [6] Karen Simonyan and Andrew Zisserman, “Very deep convolutional networks for large-scale image recognition,” arXiv preprint arXiv:1409.1556, 2014.
  • [7] Christian Szegedy et al., “Going deeper with convolutions,” in CVPR, 2015.
  • [8] Kaiming He, Xiangyu Zhang, Shaoqing Ren, and Jian Sun, “Deep residual learning for image recognition,” in CVPR, 2016.
  • [9] Bolei Zhou, Agata Lapedriza, Jianxiong Xiao, Antonio Torralba, and Aude Oliva,

    “Learning deep features for scene recognition using places database,”

    in NIPS, 2014.
  • [10] Bolei Zhou, Aditya Khosla, Agata Lapedriza, Aude Oliva, and Antonio Torralba, “Object detectors emerge in deep scene cnns,” in ICLR, 2014.
  • [11] Tsung-Yi Lin et al., “Microsoft coco: Common objects in context,” in ECCV, 2014.
  • [12] K. R. Mopuri and R. V. Babu, “Object level deep feature pooling for compact image representation,” in

    IEEE Conference on Computer Vision and Pattern Recognition Workshops (CVPRW)

    , 2015.
  • [13] Konda Reddy Mopuri and R. Venkatesh Babu, “Towards semantic visual representation: Augmenting image representation with natural language descriptors,” in Proceedings of the Tenth Indian Conference on Computer Vision, Graphics and Image Processing, 2016.
  • [14] Oriol Vinyals, Alexander Toshev, Samy Bengio, and Dumitru Erhan, “Show and tell: A neural image caption generator,” in CVPR, 2015.
  • [15] Andrej Karpathy and Fei-Fei Li, “Deep visual-semantic alignments for generating image descriptions,” in CVPR, 2015.
  • [16] Junhua Mao, Wei Xu, Yi Yang, Jiang Wang, Zhiheng Huang, and Alan Yuille,

    “Deep captioning with multimodal recurrent neural networks (m-RNN),”

    in ICLR, 2015.
  • [17] Nikita Prabhu and R. Venkatesh Babu, “Attribute-graph: A graph based approach to image ranking,” in ICCV, 2015.
  • [18] Christian Szegedy, Vincent Vanhoucke, Sergey Ioffe, Jon Shlens, and Zbigniew Wojna, “Rethinking the inception architecture for computer vision,” in CVPR, 2016.
  • [19] Ranjay Krishna et al., “Visual genome: Connecting language and vision using crowdsourced dense image annotations,” arXiv preprint arXiv:1602.07332, 2016.
  • [20] Ali Farhadi, Ian Endres, Derek Hoiem, and David Forsyth, “Describing objects by their attributes,” in CVPR, 2009.
  • [21] Xiaochun Cao, Xingxing Wei, Xiaojie Guo, Yahong Han, and Jinhui Tang, “Augmented image retrieval using multi-order object layout with attributes,” in ACM MM, 2014.
  • [22] Tomas Mikolov et al., “Efficient estimation of word representations in vector space,” arXiv preprint arXiv:1301.3781, 2013.
  • [23] S. Chopra, R. Hadsell, and Y. LeCun, “Learning a similarity metric discriminatively, with application to face verification,” in CVPR, 2005.