An Empirical Study of Language CNN for Image Captioning
Jiuxiang Gu, Gang Wang, Jianfei Cai, Tsuhan Chen
Introduction
Image caption generation is a fundamental problem that involves Computer Vision, Natural Language Processing (NLP), and Machine Learning. It can be analogous to “translating” an image to proper sentences. While this task seems to be easy for human beings, it is quite challenging for machines because it requires the model to understand the image content and express their relationships in a natural language. Also, the image captioning model should be capable of capturing implicit semantic information of an image and generating humanlike sentences. As a result, generating accurate captions for an image is not an easy task.
The recent surge of research interest in image caption generation task is due to the advances in Neural Machine Translation (NMT) and large datasets . Most image captioning models follow the encoder-decoder pipeline . The encoder-decoder framework is recently introduced for sequence-to-sequence learning based on Recurrent Neural Networks (RNNs) or Long-Short Term Memory (LSTM) networks. Both RNNs and LSTM networks can be sequence learners. However, due to the vanishing gradient problem, RNNs can only remember the previous status for a few time steps. LSTM network is a special type of RNN architecture designed to solve the vanishing gradient problem in RNNs . It introduces a new component called memory cell. Each memory cell is composed of three gates and a neuron with the self-recurrent connection. These gates allow the memory cells to keep and access information over a long period of time and make LSTM network capable of learning long-term dependencies.
Although models like LSTM networks have memory cells which aim to memorize history information for long-term, they are still limited to several time steps because long-term information is gradually diluted at every time step . Besides, vanilla RNNs-based image captioning models recursively accumulate history information without explicitly modeling the hierarchical structure of word sequences, which clearly have a bottom-up structure .
To better model the hierarchical structure and long-term dependencies in word sequences, in this paper, we adopt a language CNN which applies temporal convolution to extract features from sequences. Such a method is inspired by works in NLP which have shown CNN is very powerful for text representation . Unlike the vanilla CNN architecture, we drop the pooling operation to keep the relevant information for words representation and investigate the optimum convolutional filters by experiments. However, only using language CNN fails to model the dynamic temporal behavior. Hence, we still need to combine language CNN with recurrent networks (e.g., RNN or LSTM). Our extensive studies show that adding language CNN to a recurrent network helps model sequences consistently and more effectively, and leads to improved results.
To summarize, our primary contribution lies in incorporating a language CNN, which is capable of capturing long-range dependencies in sequences, with RNNs for image captioning. Our model yields comparable performance with the state-of-the-art approaches on Flickr30k and MS COCO .
Related Works
The problem of generating natural language descriptions for images has become a hot topic in computer vision community. Prior to using neural networks for generating descriptions, the classical approach is to pose the problem as a retrieval and ranking problem . The main weakness of those retrieval-based approaches is that they cannot generate proper captions for a new combination of objects. Inspired by the success of deep neural networks in machine translation , researchers have proposed to use the encoder-decoder framework for image caption generation . Instead of translating sentences between two languages, the goal of image captioning is to “translate” a query image into a sentence that describes the image. The earliest approach using neural network for image captioning is proposed by Vinyals et al. which is an encoder-decoder system trained to maximize the log-likelihood of the target image descriptions. Similarly, Mao et al. and Donahue et al. use the multimodal fusion layer to fuse the image features and word representation at each time step. In both cases, i.e., the models in and , the captions are generated from the full images, while the image captioning model proposed by Karpathy et al. generates descriptions based on regions. This work is later followed by Johnson et al. whose method is designed to jointly localize regions and describe each with captions.
Rather than representing an image as a single feature vector from the top-layer of CNNs, some researchers have explored the structure of networks to explicitly or implicitly model the correlation between images and descriptions . Xu et al. incorporate the spatial attention on convolutional features of an image into the encoder-decoder framework through the “hard” and “soft” attention mechanisms. Their work is followed by Yang et al. whose method introduces a review network to improve the attention mechanism and Liu et al. whose approach is designed to improve the correctness of visual attention. Moreover, a variational autoencoder for image captioning is developed by Pu et al. . They use a CNN as the image encoder and use a deep generative deconvolutional network as the decoder together with a Gated Recurrent Unit (GRU) to generate image descriptions.
More recently, high-level attributes have been shown to obtain clear improvements on the image captioning task when injected into existing encoder-decoder based models . Specifically, Jia et al. use the semantic information as the extra input to guide the model in generating captions. In addition, Fang et al. learn a visual attributes detector based on multi-instance learning (MIL) first and then learn a statistical language model for caption generation. Likewise, Wu et al. train several visual attribute classifiers and take the outputs of those classifiers as inputs for the LSTM network to predict words.
In general, current recurrent neural network based approaches have shown their powerful capability on modeling word sequences . However, the history-summarizing hidden states of RNNs are updated at each time, which render the long-term memory rather difficult . Besides, we argue that current recurrent networks like LSTM are not efficient on modeling the hierarchical structure in word sequences. All of these prompt us to explore a new language model to extract better sentence representation. Considering ConvNets can be stacked to extract hierarchical features over long-range contexts and have received a lot of attention in many tasks , in this paper, we design a language CNN to model words with long-term dependencies through multilayer ConvNets and to model the hierarchical representation through the bottom-up and convolutional architecture.
Model Architecture
We study the effect of language CNN by combining it with Recurrent Networks. Figure 1 shows a recursive framework. It consists of one deep CNN for image encoding, one CNN for sentence modeling, and a recurrent network for sequence prediction. In order to distinguish these two CNN networks, we name the first CNN for image feature extraction as , and the second CNN for language modeling as .
Models based on RNNs have dominated recent sequence modeling tasks , and most of the recent image captioning models are based on LSTM networks . However, LSTM networks cannot explicitly model the hierarchical representation of words. Even with multi-layer LSTM networks, such hierarchical structure is still hard to be captured due to the more complex model and higher risk of over-fitting.
The concatenated matrix is fed to the convolutional layer. Just like the normal CNN, has a fixed architecture with predefined maximum number of input words (denoted as ). Unlike the toy example in Figure 2, in practice we use a larger and deeper with .
Previous CNNs, including those adopted for NLP tasks , take the classic convolution-pooling strategy, which uses max-pooling to pick the highest response feature across time. This strategy works well for tasks like text classification and matching , but is undesirable for modeling the composition functionality, because it ignores the temporal information in sequence. In our network, we discard the pooling operations. We consider words as the smallest linguistic unit and apply a straightforward stack of convolution layers on top of each other. In practice, we find that deeper works better than shallow , which is consistent with the tradition of CNNs in computer vision , where using very deep CNNs is key to having better feature representation.
3 Multimodal Fusion Layer
4 Recurrent Networks
Our may miss the important temporal information because it extracts the holistic features from the whole sequence of words. To overcome this limitation, we combine it with recurrent networks. In our model, the transition equations of the recurrent network can be formulated as:
LSTM network extents the simple RNN with the gating mechanism (input gate, forget gate, and output gate) to control information flow and a memory cell to store the history information, thus it can better model the long-term dependencies than simple RNN.
5 Training
During training, given the ground truth words and corresponding image , the loss function for a single training instance is defined as a sum of the negative log likelihood of the words. The loss can be written as:
6 Implementation Details
In the following experiments, we use the 16-layer VGGNet model to compute CNN features and map the last fully-connected layer’s output features to an embedding space via a linear transformation.
As for preprocessing of captions, we transform all letters in the captions to lowercase and remove all the non-alphabetic characters. Words occur less than five times are replaced with an unknown token UNK. We truncate all the captions longer than 16 tokens and set the maximum number of input words for to be 16.
For Flickr30K and MS COCO we set the dimensionality of the image features and word embeddings as 512. All the models are trained with Adam , which is a stochastic gradient descent method that computes adaptive learning rate for each parameter. The learning rate is initialized with 2e-4 for Flickr30K and 4e-4 for MS COCO, and the restart technique mentioned in is adopted to improve the convergence of training. Dropout and early stopping are used to avoid overfitting. All weights are randomly initialized except for the CNN weights. More specifically, we fine-tune the VGGNet when the validation loss stops decreasing. The termination of training is determined by evaluating the CIDEr score for the validation split after each training epoch.
6.2 Testing
Experiments
We perform experiments on two popular datasets that are used for image caption generation: MS COCO and Flickr30k. These two datasets contain 123,000 and 31,000 images respectively, and each image has five reference captions. For MS COCO, we reserve 5,000 images for validation and 5,000 images for testing. For Flickr30k, we use 29,000 images for training, 1,000 images for validation, and 1,000 images for testing.
We choose four metrics for evaluating the quality of the generated sentences: BLEU- is a precision-based metric. It measures how many words are shared by the generated captions and ground truth captions. METEOR is based on the explicit word to word matches between generated captions and ground-truth captions. CIDEr is a metric developed specifically for evaluating image captions. It measures consensus in image caption by performing a Term Frequency-Inverse Document Frequency weighting for each -gram. SPICE is a more recent metric which has been shown to correlate better with the human judgment of semantic quality than previous metrics.
2 Models
To gain insight into the effectiveness of , we compare -based models with methods using the recurrent network only. For a fair comparison, the output dimensions of all gates are fixed to 512.
Recurrent Network-based Models. We implement Recurrent Network-based Models based on the framework proposed by Vinyals et al. , it takes an image as input and predicts words with one-layer Recurrent Network. Here we use the publicly available implementation Neuraltalk2 https://github.com/karpathy/neuraltalk2. We evaluate four baseline models: Simple RNN, RHN, LSTM, and GRU.
-based Models. As can be seen in Figure 1. The -based models employ a to obtain the bottom-up representation from the sequence of words and cooperate with the Recurrent Network to predict the next word. Image features and words representation learned from and respectively are fused with the multimodal function. We implement four -based models: +Simple RNN, +RHN, +LSTM, and +GRU.
3 Quantitative Results
We first evaluate the importance of language CNN for image captioning, then evaluate the effects of on two datasets (Flickr30K and MS COCO), and also compare with the state-of-the-art methods.
It is known that -based models have larger capacity than RNNs. To verify that the improved performance is from the developed rather than due to more layers/parameters, we set the hidden and output sizes of RNNs to 512 and 9568 (vocabulary size), and list the parameters of each model as well as their results in Table 1.
As seen in Table 1, the parameter size of the 3-layer LSTM () is close to that of the +RNN. Adding the LSTM layer () improves the performance of LSTM, but it is still lower than +RNN. Meanwhile, does not show improvements as the model experiences overfitting. This issue is even worse on Flickr30K which has relatively small number of training data. Note that (without RNNs) achieves lower performance than +RNN. We find that those predicted captions of (without RNNs) only are short, but contain primary attributes, e.g., model generates: “a person on a wave”, while +RNN provides: “a young man surfing a wave”. This finding shows that the temporal recurrence of RNNs is still crucial for modeling the short-term contextual information across words in the sentence.
We further compare language CNNs with different input words and with max-pooling operations, where those language CNNs are combined with RHN instead of RNN. Table 2 shows that larger context windows achieve better performance. This is likely because with larger window size can better utilize contextual information and learn better word embedding representation. In addition, the performance of +RHN is inferior to +RHN, which experimentally supports our opinion that max-pooling operations lose information about the local order of words.
Table 3 shows the generation performance on MS COCO. By combine , our methods clearly outperforms the recurrent network counterpart in all metrics.
Among these models, +RHN achieves the best performances in terms of B@(3,4), METEOR, and SPICE metrics, +LSTM achieves the best performance in CIDEr metric (99.1), and +GRU achieves the best performance in B@(1,2) metrics. Although the absolute gains across different B@n metrics are similar, the percentage of the relative performance improvement is increasing from B@1 to B@4. It does show the advantage of our method in terms of better capturing long-term dependency. Note that the +RNN model achieves better performance than simple RNN model and outperforms LSTM model. As mentioned in Section 3.4, LSTM networks model the word dependencies with multi-gates and the internal memory cell. However, our +RNN without memory cell works better than LSTM model. We think the reason is that our language CNN takes all history words as input and explicitly model the long-term dependencies in history words, this could be regarded as an external “memory cell”. Thus, the ’s ability to model long-term dependencies can be taken as enhancement of simple RNNs, which can solve the difficulty of learning long-term dependencies.
We also evaluate the effectiveness of language CNN on the smaller dataset Flickr30K. The results in Table 4 clearly indicate the advantage of exploiting the language CNN to model the long-term dependencies in words for image captioning. Among all models, +RHN achieves the best performances in B@(1,2,3,4) metrics, and +RNN achieves the best performances in METEOR, CIDEr, and SPICE metrics.
As for the low results (without ) on Flickr30k, we think that it is due to lack of enough training data to avoid overfitting. In contrast, our can help learn better word embedding and better representation of history words for word prediction, and it is much easier to be trained compared with LSTM due to its simplicity and efficiency. Note that the performance of LSTM and +LSTM models are lower than RHN/GRU and +RHN/GRU. This illustrates that the LSTM networks are easily overfitting on this smaller dataset.
3.4 Comparison with State-of-the-art Methods
To empirically verify the merit of our models, we compare our methods with other state-of-the-art approaches.
Performance on MS COCO. The right-hand side of Table 5 shows the results of different models on MS COCO dataset. -based models perform better than most image captioning models. The only two methods with better performance (for some metrics) than ours are Attributes-CNN+RNN and Google NICv2 . However, Wu et al. employ an attribute prediction layer, which requires determining an extra attribute vocabulary. While we generate the image descriptions only based on the image features. Google NICv2 is based on Google NIC , the results of Google NICv2 are achieved by model ensembling. All our models are based on VGG-16 for a fair comparison with . Indeed, better image CNN (e.g. Resnet ) leads to higher performanceWe uploaded the results based on Resnet-101++LSTM (named jxgu_LCNN_NTU) to the official MS COCO evaluation server (https://competitions.codalab.org/competitions/3221), and achieved competitive ranking across different metrics.. Despite all this, the CIDEr score of our +LSTM model can still achieve 99.1, which is comparable to their best performance even with a single VGG-16 model.
Performance on Flickr30K. The results on Flickr30K are reported on the left-hand side of Table 5. Interestingly, +RHN performs the best on this smaller dataset and even outperforms the Attributes-CNN+RNN . Obviously, there is a significant performance gap between +RNN/RHN/GRU and RNN/RHN/GRU/LSTM models. This demonstrates the effectiveness of our language CNN on the one hand, and also shows that our +RNN/RHN/GRU models are more robust and easier to train than LSTM networks when less training data is available.
4 Qualitative Results
Figure 3 shows some examples generated by our models. It is easy to see that all of these caption generation models can generate somewhat relevant sentences, while the -based models can predict more high-level words by jointly exploiting history words and image representations. Take the last image as an example, compared with the sentences generated by RNN/LSTM/GRU model, “a cat is looking at a dog in front of a window” generated by +RNN is more precise to describe their relationship in the image.
Besides, our -based models can generate more descriptive sentences. For instance, with the detected object “cat” in the first image, the generated sentence “a black and white cat looking at itself in a mirror” by +RHN depicts the image content more comprehensively. The results demonstrate that our model with language CNN can generate more humanlike sentences by modeling the hierarchical structure and long-term information of words.
Figure 4 shows some failure samples of our -based models. Although most of the generated captions are complete sentences. However, the biggest problem is that those predicted visual attributes are wrong. For example, “bear” in the first image is detected as “bird”, and “brown” in the second image is detected as “black and white”. This will decrease the precision-based evaluation score (e.g., B@). We can improve our model by further taking high-level attributes into account.
Conclusion
In this work, we present an image captioning model with language CNN to explore both hierarchical and temporal information in sequence for image caption generation. Experiments conducted on MS COCO and Flickr30K image captioning datasets validate our proposal and analysis. Performance improvements are clearly observed when compared with other image captioning methods. Future research directions will go towards integrating extra attributes learning into image captioning, and how to apply a single language CNN for image caption generation is worth trying.
Acknowledgements
This work is supported by the National Research Foundation, Prime Minister’s Office, Singapore, under its IDM Futures Funding Initiative, and NTU CoE Grant. This research was carried out at ROSE Lab at Nanyang Technological University, Singapore. ROSE Lab is supported by the National Research Foundation, Prime Ministers Office, Singapore, under its IDM Futures Funding Initiative and administered by the Interactive and Digital Media Programme Office. We gratefully acknowledge the support of NVAITC (NVIDIA AI Tech Centre) for our research at NTU ROSE Lab, Singapore.