# Automatic Image Captioning Based on ResNet50 and LSTM with Soft Attention

Authors: Yan Chu; Xiao Yue; Lei Yu; Mikhailov Sergei; Zhengkui Wang
Journal: Wireless Communications and Mobile Computing
 (2020)

---

## Abstract

Captioning the images with proper descriptions automatically has become an interesting and challenging problem. In this paper, we present one joint model AICRL, which is able to conduct the automatic image captioning based on ResNet50 and LSTM with soft attention. AICRL consists of one encoder and one decoder. The encoder adopts ResNet50 based on the convolutional neural network, which creates an extensive representation of the given image by embedding it into a fixed length vector. The decoder is designed with LSTM, a recurrent neural network and a soft attention mechanism, to selectively focus the attention over certain parts of an image to predict the next sentence. We have trained AICRL over a big dataset MS COCO 2014 to maximize the likelihood of the target description sentence given the training images and evaluated it in various metrics like BLEU, METEROR, and CIDEr. Our experimental results indicate that AICRL is effective in generating captions for the images.


---

## Body

## 1. Introduction

With the rapid development of digitalization, there are a huge amount of images, accompanied with a lot of related texts [1]. Automatic image captioning has recently attracted much research interest. The objective of automatic image captioning is to generate properly formed English sentences to describe the content of an image automatically, which is of great impact in various domains such as virtual assistants, image indexing, recommendation in editing applications, and the help of the disabled [2, 3]. Although it is an easy task for a human to describe an image, it becomes very difficult for a machine to perform such a task [4]. Image captioning does not only need to detect the objects contained in an image but also capture how these objects related to each other and their attributes as well as the activities involved in. Moreover, the semantic knowledge should be expressed in a natural language, which requires a language model to be developed based on the visual understanding.Much research effort has been devoted to automatic image captioning, and it can be categorized into template-based image captioning, retrieval-based image captioning, and novel image caption generation [5]. Template-based image captioning first detects the objects/attributes/actions and then fills the blanks slots in a fixed template [1]. Retrieval-based approaches first find the visually similar images with their captions from the training dataset, and then the image caption is selected from similar images with captions [6]. These methods are able to generate syntactically correct captions but are unable to generate image-specific and semantically correct captions. Differently, the novel image caption generation approaches are to analyze the visual content of the image and then to generate image captions from the visual content using a language model [7]. Compared to the first two categories, novel caption generation can generate new captions for a given image that are semantically more accurate than previous approaches. Most of the works in this category rely on machine learning and deep learning, which is also the approach adopted in this paper. One common framework used in this category is the encoder-decoder framework for image captioning [8]. This framework was first introduced to describe a multimodal log-bilinear model for image captioning with a fixed context window by Kiros et al. [9]. Recent research works have used the deep convolutional neural network (CNN) as the encoder and the deep recurrent neural network (RNN) as the decoder, which is proven to be promising [8, 10, 11]. However, it still remains challenging to identify the proper CNN and RNN models for the image captioning.In this paper, we investigate one single-joint mode, AICRL, for automatic image generation using ResNet50 (a convolutional neural network) and LSTM (long short-term memory) with soft attention mechanism. AICRL consists of an encoder and a decoder. We adopt ResNet50 as the encoder to create an extensive representation of an input image by embedding it into a vector. Meanwhile, we utilize the LSTM with a soft attention as the decoder which selectively focuses the attention over a certain part of an image to predict the next sentences. Furthermore, we conduct extensive experiment and empirically determine the structure of the model and fine-tuned the model hyperparameters. Our experimental evaluation indicates that AICRL is effective to generate proper captions for the images.The rest of the paper is organized as follows. Section2 introduces the related work. In Section 3, we present the proposed AICRL model. Section 4 and Section 5 provide the experimental evaluation and conclusion, respectively.


## 2. Related Work

Much research has been devoted on the automatic image captioning recently. The research can be briefly categorized into three different categories including the template-based approaches, retrieval-based approaches, and novel image caption generation approaches.The template-based approach is aimed at generating captions by using fixed templates with a number of blank slots, in which way different objects, attributes, and actions are detected first and then the blank spaces in the templates are filled. For example, Farhadi et al. [1] use a triplet of scene elements to fill the template slots for generating image captions. Li et al. [12] extract the phrases related to detected objects, attributes, and their relationships for this purpose. Kulkarni et al. [13] adopt a conditional random field (CRF) method to infer the objects, attributes, and prepositions before filling in the gaps. Template-based methods can generate grammatically correct captions. However, templates are predefined and length of captions cannot be variable.The retrieval-based approach tries to generate description for an image by selecting the most semantically similar sentences from sentence pool or directly copying sentences from other visually similar images. For example, Gong et al. [6] utilize stacked auxiliary embedding method to generate image descriptions from millions of weakly annotated images. Ordonez et al. [14] find similar images in the Flickr database and return the descriptions of these retrieved images to query based on millions of images and their corresponding descriptions. Sun et al. [15] use semantic similarity and visual similarity scores to cluster similar terms and images together first and then retrieve caption of target image from captions of similar images in the same cluster. Hodosh et al. [16] establish a ranking-based framework to treat sentence-based image description as the task of ranking a set of captions for each test image. These methods generate general and syntactically correct captions. However, it is difficult for them to generate image-specific and semantically correct captions.Different from the mentioned two categories, novel caption generation approaches mainly use deep learning and machine learning to generate the new captions. A general implementation of this method is to analyze the visual content of the image first and then generate image captions from the visual content using a language model. For instance, Vinyals et al. use CNN as an encoder for image classification and LSTM as a decoder to generate sentence for the description [8]. The main drawbacks of the work are the quick model overfitting, so they use the heavy and expensive GoogLeNet with 22 hidden layers and the absence of attention layer that significantly improved the description accuracy. Karpathy et al. investigate the possibility of generating an image description in natural language [10]. Their approach uses image datasets and their description in natural language and seeks an intermodal correspondence between words from the description and visual data. The first model aligns the fragments of sentences to the visual areas, then forms a single description by multimodal embedding. This description is treated as learning data for a second model of a recurrent neural network that learned to a generate caption. Xu et al. use a convolutional neural network to extract feature maps and LSTM to describe the input image, by processing already extracted feature maps [11]. The limitation of this work is the using of obsolete and expensive Oxford VGGnet, where the quality of image classification is low in the modern CNN [7]. Some researchers have put their attention on classification as Yu et al. [17], who propose a SVM classification-based two-side cross-domain algorithm by inferring intrinsic user and item features (CTSIF-SVMs), a two-side cross-domain algorithm with expanding user and item features via the latent factor space of auxiliary domains (TSEUIF) [18].


## 3. Model

In this section, we present our proposed model, AICRL, for automatic image captioning based on ResNet50 and LSTM with software attention. The ultimate purpose of AICRL is to generate the proper description for the given images. To do so, the AICRL model is designed with an encoder-decoder architecture based on CNN and RNN. In particular, to extract visual features, we use the ResNet50 network as the encoder to generate a one-dimensional vector representation of the input images. After that, to generate the description sentences, we adopt the LSTM as the language model for the decoder to decode the vector into a sentence. Meanwhile, we utilize the soft attention in the decoder to enable the model to selectively focus the attention over a certain part of an image to predict the next sentence better. We conduct extensive experiments, empirically determine the structure of the model, and fine-tune the model hyperparameters. The whole model is fully trainable by using a stochastic gradient descent.In the encoder-decoder method, the most likely description of the image is determined by maximizing the log-likelihood function of the expressionS, considering the corresponding image I and the parameters of the model θ.
(1)θ∗=argmaxθ∑I,SlogpSI;θ,where θ is the parameter of our model, I is the input image, and S is the correct description. Since S represents a sentence of any length, therefore, a chain rule is usually used to model the joint probability over S1,⋯,SN, where N is the length of this particular example.
(2)logpSI=∑t=0NlogpStI,S0,⋯,St−1,where the dependence on θ is omitted for convenience. The network training is represented by the pair of (S,I), and we optimize the sum of the log likelihood functions, as described in Equation (2), over the entire training set using stochastic gradient descent.The likelihood logpStI,S0,⋯,St−1 is modelled by a recurrent neural network, where there is a variable number of words that we define up to t−1. The hidden state of RNN (latent memory) ht is updated after the new input xt with the nonlinear function f.
(3)ht+1=fht,xt.


### 3.1. Image Feature Extraction

To represent the image, we adopt the convolutional neural network (CNN), ResNet50, which is a very deep network that has 50 layers. The depth of the network is crucial for neural networks, but deeper networks are more difficult to train. The structure of ResNet50 facilitates the training of networks and allows them to be much deeper, which leads to increased performance in different tasks. ResNet50 is much deeper than their “simple” counterparts, but moreover, the number of parameters (weights) of such networks is much smaller. For example, Table1 indicates the number of parameter comparison between ResNet50 and VGG16. Deep convolutional neural networks have led to a series of breakthroughs for image classification. Recent evidence reveals that network depth is of crucial importance. Many other nontrivial visual recognition tasks have also greatly benefited from the deep models.Table 1
Comparison of total number of VGG16 and ResNet50 parameters.
CNNNumber of parametersVGG16138,357,544ResNet5023,587,712With the network depth increasing, the accuracy of networks increases rapidly, which is not surprising and then rapidly degrades (saturated). This degradation is not caused by overfitting, and the addition of even more layers leads to a higher learning error. In a sense, this is strange, since a deeper network has a strictly large representational power. It is possible for ResNet50 to get a deeper model trivially, which is not worse than the less deep network. It can be done by adding several identity layers, that is, levels that simply skip the signal further without changes. ResNet50’s deeper levels have to predict the difference between the output of the previous layers and the objective function. They could always drive the weights to 0 and simply skip the signal. Hence, deep residual learning is a good method that makes the network learn to predict deviations from past layers.The model takes an image and produces a caption, encoded as a sequence of1−K coded words.
(4)y=y1,y2,⋯,yc,yi∈RK,where K is the size of the dictionary and c is the caption length. We use CNN in particular, ResNet50, to obtain set annotation vectors like the feature vectors. The extractor produces L-vectors, all of which is a D-dimensional representation of the corresponding part of an image.


### 3.2. The Language Model

The choice off in Equation (3) is determined by its ability to cope with vanishing problems and exploding gradients, which are the most common problems in the design and training of RNN. LSTM networks are successfully used to accomplish the tasks of machine translation and sequence generation. In our design, we adopt LSTM as our language model to generate proper caption based on the input vector from the ResNet50 output.
(5)ft=σWf⋅ht−1,xt+bf,where the output vector of the previous cell ht−1 with the new element of the sequence xt is concatenated and passed as one vector through the layer with the sigmoid activation function.
(6)Ct=ft∗Ct−1+it∗Ct~.Two created vectors are used to update the state fromCt−1 to Ct. To do this, we multiply the past state by ft to “forget” the data recognized as unnecessary in the previous step, then add it∗Ct~.
(7)it=σWi⋅ht−1,xt+bi,C~t=tanhWc⋅ht−1,xt+bc.The input gate must determine what values will be updated, and the tanh layer creates a vector of new candidates forC~t, and values can be added to the cell state.
(8)ht=ot∗tanhCt.The obtained values ofCt and ht are transmitted to the neural network input at time t+1.
(9)ot=σWo⋅ht−1,xt+bo,pt=softmaxht.The multiplicative filters allow to effectively train LSTM, as they are good to prevent the exploding and vanishing gradients. Nonlinearity is provided by the sigmoidσ· and the hyperbolic tangent h. In the last equation, ht is fed to the softmax function to calculate the probability distribution pt over all words. This function is calculated and optimized on the entire training dataset. The word with maximum probability is selected at each time step and fed into next time step input to generate a full sentence.


### 3.3. Attention Mechanism

To better isolate the image content, we adopt the soft attention mechanism, which has been widely used to solve the problem of image classification, as there is no need to process all pixels of an image. For example, in the classification problem, the background usually plays an insignificant role. Nevertheless, convolutional neural networks, which are the most popular method for solving such a problem, spend the same amount of computational resources on all parts of the image.Soft attention is implemented by adding an additional input of attention gate into LSTM that helps to concentrate selective attention. The main drawback of the model without attention is that it tries to decode the full image from the last hidden layer ofh0 in Figure 1. It is like an analogy with machine translation in the whole process. To do a translation of the whole text is just from the “last word.” So it will lose a lot of useful information from the beginning of the text.Figure 1
Model without attention.The attention gate can be represented as an addition input for LSTM in Figure2. The soft attention depends on the previous output of LSTM pt and extracted features of input image yi. Soft attention is differentiable and can be trained by the standard method of the backpropagation algorithm. In the case of model with soft attention, we append an additional at in Equation (10).
(10)at=∑1nSjYj,where at is an attention vector, sj is a nonlinear function with softmax output, and yj is the extracted features of the input image.Figure 2
Model with attention.


## 3.1. Image Feature Extraction

To represent the image, we adopt the convolutional neural network (CNN), ResNet50, which is a very deep network that has 50 layers. The depth of the network is crucial for neural networks, but deeper networks are more difficult to train. The structure of ResNet50 facilitates the training of networks and allows them to be much deeper, which leads to increased performance in different tasks. ResNet50 is much deeper than their “simple” counterparts, but moreover, the number of parameters (weights) of such networks is much smaller. For example, Table1 indicates the number of parameter comparison between ResNet50 and VGG16. Deep convolutional neural networks have led to a series of breakthroughs for image classification. Recent evidence reveals that network depth is of crucial importance. Many other nontrivial visual recognition tasks have also greatly benefited from the deep models.Table 1
Comparison of total number of VGG16 and ResNet50 parameters.
CNNNumber of parametersVGG16138,357,544ResNet5023,587,712With the network depth increasing, the accuracy of networks increases rapidly, which is not surprising and then rapidly degrades (saturated). This degradation is not caused by overfitting, and the addition of even more layers leads to a higher learning error. In a sense, this is strange, since a deeper network has a strictly large representational power. It is possible for ResNet50 to get a deeper model trivially, which is not worse than the less deep network. It can be done by adding several identity layers, that is, levels that simply skip the signal further without changes. ResNet50’s deeper levels have to predict the difference between the output of the previous layers and the objective function. They could always drive the weights to 0 and simply skip the signal. Hence, deep residual learning is a good method that makes the network learn to predict deviations from past layers.The model takes an image and produces a caption, encoded as a sequence of1−K coded words.
(4)y=y1,y2,⋯,yc,yi∈RK,where K is the size of the dictionary and c is the caption length. We use CNN in particular, ResNet50, to obtain set annotation vectors like the feature vectors. The extractor produces L-vectors, all of which is a D-dimensional representation of the corresponding part of an image.


## 3.2. The Language Model

The choice off in Equation (3) is determined by its ability to cope with vanishing problems and exploding gradients, which are the most common problems in the design and training of RNN. LSTM networks are successfully used to accomplish the tasks of machine translation and sequence generation. In our design, we adopt LSTM as our language model to generate proper caption based on the input vector from the ResNet50 output.
(5)ft=σWf⋅ht−1,xt+bf,where the output vector of the previous cell ht−1 with the new element of the sequence xt is concatenated and passed as one vector through the layer with the sigmoid activation function.
(6)Ct=ft∗Ct−1+it∗Ct~.Two created vectors are used to update the state fromCt−1 to Ct. To do this, we multiply the past state by ft to “forget” the data recognized as unnecessary in the previous step, then add it∗Ct~.
(7)it=σWi⋅ht−1,xt+bi,C~t=tanhWc⋅ht−1,xt+bc.The input gate must determine what values will be updated, and the tanh layer creates a vector of new candidates forC~t, and values can be added to the cell state.
(8)ht=ot∗tanhCt.The obtained values ofCt and ht are transmitted to the neural network input at time t+1.
(9)ot=σWo⋅ht−1,xt+bo,pt=softmaxht.The multiplicative filters allow to effectively train LSTM, as they are good to prevent the exploding and vanishing gradients. Nonlinearity is provided by the sigmoidσ· and the hyperbolic tangent h. In the last equation, ht is fed to the softmax function to calculate the probability distribution pt over all words. This function is calculated and optimized on the entire training dataset. The word with maximum probability is selected at each time step and fed into next time step input to generate a full sentence.


## 3.3. Attention Mechanism

To better isolate the image content, we adopt the soft attention mechanism, which has been widely used to solve the problem of image classification, as there is no need to process all pixels of an image. For example, in the classification problem, the background usually plays an insignificant role. Nevertheless, convolutional neural networks, which are the most popular method for solving such a problem, spend the same amount of computational resources on all parts of the image.Soft attention is implemented by adding an additional input of attention gate into LSTM that helps to concentrate selective attention. The main drawback of the model without attention is that it tries to decode the full image from the last hidden layer ofh0 in Figure 1. It is like an analogy with machine translation in the whole process. To do a translation of the whole text is just from the “last word.” So it will lose a lot of useful information from the beginning of the text.Figure 1
Model without attention.The attention gate can be represented as an addition input for LSTM in Figure2. The soft attention depends on the previous output of LSTM pt and extracted features of input image yi. Soft attention is differentiable and can be trained by the standard method of the backpropagation algorithm. In the case of model with soft attention, we append an additional at in Equation (10).
(10)at=∑1nSjYj,where at is an attention vector, sj is a nonlinear function with softmax output, and yj is the extracted features of the input image.Figure 2
Model with attention.


## 4. Experiments and Analysis

We perform an extensive set of experiments to evaluate the effectiveness of the proposed model. We have adopted two different datasets in our experiments including the MS COCO 2014 dataset and Flickr8K dataset, which contain the images with their descriptions in English. The MS COCO 2014 dataset contains 102,739 images with their descriptions, five descriptions for each image, and 20,548 testing examples. The Flickr8K dataset is another set of images with their descriptions with 7,000 training examples and 1,000 testing examples. Similar to MS COCO 2014, it also contains five descriptions for each image, but with a much smaller volume. Consider the Flickr8K data has less data than MS COCO 2014. In the training, we first use the Flickr8K dataset to train the model and then use the fine-tuned hyperparameters on MS COCO 2014. All experiments are conducted on NVIDIA GPU GTX-1070.We evaluate the model using several popular metrics such as BLEU [19], METEOR [20], and CIDEr [21]. BLEU (Bilingual Evaluation Understudy) is an algorithm that measures the precision of an n-gram between the generated and reference captions. BLEU-N (N=1,2,3,4) scores can be calculated based on the length of the reference sentence, the generated sentence, the uniform weights, and the modified n-gram precisions.METEOR (Metric for Evaluation of Translation with Explicit Ordering) is an evaluation metric which was initially used in machine translation. Besides measuring precision, METEOR places emphasis on the recall between the generated and ground truth captions.CIDEr (Consensus-based Image Description Evaluation) measures the similarity of generated captions to their ground truth sentences for evaluating image captioning. This measurement takes into account the grammaticality and correctness.


### 4.1. Training

The first step in the process of generating comments to the image is to create a fixed-length vector that effectively summarizes the content of an image. We use CNN, in particular the ResNet50 architecture. This network is preliminarily trained for 1.2 million images of the ImageNet dataset. Therefore, ResNet50 has a reliable initialization for object recognition and allows reducing training time. For any image from the training set, we get the output vector representation from the last convolution layer. This vector is fed to the LSTM input. Since the training set is a large dataset and each image is represented as a 2048-dimensional vector, the learning will be expensive. Therefore, the principal component method is used to reduce the dimension of the image vector from 2048 to 256. Since the length of the description may differ, the model should know where to start and stop. To do this, we add two tokens< START > and < END >, which are the beginning and end of each sign.The network for generating the captions will have to capture the words between these tokens. In this paper, words are represented as the frequency of occurrence of each word in the dictionary (1-of-N, where N is the power of the dictionary). The LSTM model learns to predict the next word St in the commentary based on the vector of visual features and the previous t−1 words. pStI,S1,S2,⋯,St−1 is calculated and optimized on the whole training dataset by using stochastic gradient descent. At each time step, the context vector Zt and the ht−1 state of the previous step are fed to the LSTM together. After that, LSTM provides the next state vector ht and next word. The context vector zt is a concatenation of the feature vector and one hot vector of word representation.


### 4.2. Experimental Results

To speed up the learning process, we have adopted the method of Adam optimization with a gradual decreasing of learning rate which convergences more quickly. We use Adam optimization with regularization methods such asL2 and dropout together. Applying the dropout technique in convolutional layers with a value of 0.5 and 0.3 in the LSTM layers helps to avoid overfitting that quickly happens with a small training set like the Flickr8K dataset. A variant with two LSTM layers is selected because we do not find that additional layers improve the quality. Each of the LSTM contains 512 hidden elements in a cell. Batch size equal to 32 and the beam size 3 are empirically found out that values are optimal. The deep models, such as ResNet50, for generating comments to the image increase in efficiency of the whole model. This is especially noticeable in the BLEU metric. Using a large set of MS COCO 2014 dataset avoids the model overfitting, while the overfitting on Flickr8K is achieved very quickly with a large batch size.First, we study the impact of the soft attention mechanism in AICRL. As Table2 indicates, the integrating the soft attention mechanism improves the model performances significantly. The soft attention mechanism increases the performance in all metrics like BLEU-4, METEOR, and CIDEr. In addition, after training of the generator model, there are two questions. The first one is whether the model really generates new descriptions, and the second one is that whether they are diverse, qualitative, and understandable for humans. We have also conducted another set of experiments to involve human into the performance evaluation.Table 2
Comparison for AICRL with and without attention.
ModelBLEU-4METEORCIDErWith attention0.3260.2610.872Without attention0.2620.2090.803A questionnaire is designed with 20 images and the generated descriptions from the two different models. The participants are asked to evaluate whether the generated caption can well describe the images. Table3 presents the results based on the generated description from the MS COCO 2014 dataset. From the results, we can see that 71% of the captions are well generated for the model with soft attention, while 54% are well generated for the one without soft attention. Based on this, we will use AICRL with the soft attention in the following experiments.Table 3
Comparison for AICRL with and without attention.
ModelRight choosing of generated descriptionWith attention71%Without attention54%Next, we study the performance comparison between AICRL and other existing image captioning algorithms [22–29]. To make the evaluation complete, we also implemented another algorithm, AICRL-VGA16, by using another CNN network, namely, VGA16, in AICRL. Tables 4 and 5 show the results based on the Flick8K dataset and MS COCO 2014 dataset under six different metrics including BLEU-1, BLEU-2, BLEU-3, BLEU-4, METOER, and CIDEr. From both of the results, we can see that AICRL outperforms other systems in those metrics. The proposed model is able to generate efficient captions and fluent language. Meanwhile, ResNet50 also outperforms the VGA16 network which indicates that ResNet50 is able to capture the image features well. From these experiments, we observe that AICRL achieves good performance by integrating ResNet50, LSTM, and soft attention into a joint model.Table 4
The performance comparison in the Flick8K dataset.
ModelBLEU-1BLEU-2BLEU-3BLEU-4METEORCIDErMao et al. [22]0.580.280.23———Google NIC [28]0.630.410.27———Chen and Zitnick [23]———0.141——Log bilinear [25]0.6560.4240.2770.1770.173—DVS [26]0.5790.3830.2450.16——AICRL-ResNet500.6190.4520.3680.2620.2090.803AICRL-VGA160.6720.4360.3380.2250.1860.743Table 5
The performance comparison in the MS COCO 2014 dataset.
ModelBLEU-1BLEU-2BLEU-3BLEU-4METEORCIDErNearest neighbor [27]0.480.2810.1660.10.1570.383Google NIC [28]0.6660.4610.3290.246——LRCN [24]0.6280.4420.304———MS research [29]———0.2110.207—Chen and Zitnick [23]———0.190.2040.141Log bilinear [25]0.7080.4890.3440.2430.2—DVS [26]0.6250.450.3210.230.1950.66AICRL-ResNet500.7310.5620.410.3260.2610.872AICRL-VGA160.7020.5360.3980.2950.2360.857Furthermore, we study how the total loss changes during the training. Figure3 shows that the total loss of the model varies while the training iteration increases. From the results, we can see that the total loss quickly decreases at the beginning of training, but later, the speed of loss changing slows down.Figure 3
The total loss function.


## 4.1. Training

The first step in the process of generating comments to the image is to create a fixed-length vector that effectively summarizes the content of an image. We use CNN, in particular the ResNet50 architecture. This network is preliminarily trained for 1.2 million images of the ImageNet dataset. Therefore, ResNet50 has a reliable initialization for object recognition and allows reducing training time. For any image from the training set, we get the output vector representation from the last convolution layer. This vector is fed to the LSTM input. Since the training set is a large dataset and each image is represented as a 2048-dimensional vector, the learning will be expensive. Therefore, the principal component method is used to reduce the dimension of the image vector from 2048 to 256. Since the length of the description may differ, the model should know where to start and stop. To do this, we add two tokens< START > and < END >, which are the beginning and end of each sign.The network for generating the captions will have to capture the words between these tokens. In this paper, words are represented as the frequency of occurrence of each word in the dictionary (1-of-N, where N is the power of the dictionary). The LSTM model learns to predict the next word St in the commentary based on the vector of visual features and the previous t−1 words. pStI,S1,S2,⋯,St−1 is calculated and optimized on the whole training dataset by using stochastic gradient descent. At each time step, the context vector Zt and the ht−1 state of the previous step are fed to the LSTM together. After that, LSTM provides the next state vector ht and next word. The context vector zt is a concatenation of the feature vector and one hot vector of word representation.


## 4.2. Experimental Results

To speed up the learning process, we have adopted the method of Adam optimization with a gradual decreasing of learning rate which convergences more quickly. We use Adam optimization with regularization methods such asL2 and dropout together. Applying the dropout technique in convolutional layers with a value of 0.5 and 0.3 in the LSTM layers helps to avoid overfitting that quickly happens with a small training set like the Flickr8K dataset. A variant with two LSTM layers is selected because we do not find that additional layers improve the quality. Each of the LSTM contains 512 hidden elements in a cell. Batch size equal to 32 and the beam size 3 are empirically found out that values are optimal. The deep models, such as ResNet50, for generating comments to the image increase in efficiency of the whole model. This is especially noticeable in the BLEU metric. Using a large set of MS COCO 2014 dataset avoids the model overfitting, while the overfitting on Flickr8K is achieved very quickly with a large batch size.First, we study the impact of the soft attention mechanism in AICRL. As Table2 indicates, the integrating the soft attention mechanism improves the model performances significantly. The soft attention mechanism increases the performance in all metrics like BLEU-4, METEOR, and CIDEr. In addition, after training of the generator model, there are two questions. The first one is whether the model really generates new descriptions, and the second one is that whether they are diverse, qualitative, and understandable for humans. We have also conducted another set of experiments to involve human into the performance evaluation.Table 2
Comparison for AICRL with and without attention.
ModelBLEU-4METEORCIDErWith attention0.3260.2610.872Without attention0.2620.2090.803A questionnaire is designed with 20 images and the generated descriptions from the two different models. The participants are asked to evaluate whether the generated caption can well describe the images. Table3 presents the results based on the generated description from the MS COCO 2014 dataset. From the results, we can see that 71% of the captions are well generated for the model with soft attention, while 54% are well generated for the one without soft attention. Based on this, we will use AICRL with the soft attention in the following experiments.Table 3
Comparison for AICRL with and without attention.
ModelRight choosing of generated descriptionWith attention71%Without attention54%Next, we study the performance comparison between AICRL and other existing image captioning algorithms [22–29]. To make the evaluation complete, we also implemented another algorithm, AICRL-VGA16, by using another CNN network, namely, VGA16, in AICRL. Tables 4 and 5 show the results based on the Flick8K dataset and MS COCO 2014 dataset under six different metrics including BLEU-1, BLEU-2, BLEU-3, BLEU-4, METOER, and CIDEr. From both of the results, we can see that AICRL outperforms other systems in those metrics. The proposed model is able to generate efficient captions and fluent language. Meanwhile, ResNet50 also outperforms the VGA16 network which indicates that ResNet50 is able to capture the image features well. From these experiments, we observe that AICRL achieves good performance by integrating ResNet50, LSTM, and soft attention into a joint model.Table 4
The performance comparison in the Flick8K dataset.
ModelBLEU-1BLEU-2BLEU-3BLEU-4METEORCIDErMao et al. [22]0.580.280.23———Google NIC [28]0.630.410.27———Chen and Zitnick [23]———0.141——Log bilinear [25]0.6560.4240.2770.1770.173—DVS [26]0.5790.3830.2450.16——AICRL-ResNet500.6190.4520.3680.2620.2090.803AICRL-VGA160.6720.4360.3380.2250.1860.743Table 5
The performance comparison in the MS COCO 2014 dataset.
ModelBLEU-1BLEU-2BLEU-3BLEU-4METEORCIDErNearest neighbor [27]0.480.2810.1660.10.1570.383Google NIC [28]0.6660.4610.3290.246——LRCN [24]0.6280.4420.304———MS research [29]———0.2110.207—Chen and Zitnick [23]———0.190.2040.141Log bilinear [25]0.7080.4890.3440.2430.2—DVS [26]0.6250.450.3210.230.1950.66AICRL-ResNet500.7310.5620.410.3260.2610.872AICRL-VGA160.7020.5360.3980.2950.2360.857Furthermore, we study how the total loss changes during the training. Figure3 shows that the total loss of the model varies while the training iteration increases. From the results, we can see that the total loss quickly decreases at the beginning of training, but later, the speed of loss changing slows down.Figure 3
The total loss function.


## 5. Conclusions

In this paper, we have presented one single joint model for automatic image captioning based on ResNet50 and LSTM with software attention. The proposed model was designed with one encoder-decoder architecture. We adopted ResNet50, a convolutional neural network, as the encoder to encode an image into a compact representation as the graphical features. After that, a language model LSTM was selected as the decoder to generate the description sentence. Meanwhile, we integrated the soft attention model with LSTM such that the learning can be focused on a particular part of the image to improve the performance. The whole model is fully trainable by using the stochastic gradient descent that makes the training process easier. The experimental evaluations indicate that the proposed model is able to generate good captions for images automatically.



---

*Source: 8909458-2020-10-21.xml*