# Visual Sentiment Analysis Using Deep Learning Models with Social Media Data
## 4 Methodology
### DenseNet121 Architecture  
The DenseNet deep learning model was introduced to overcome the problem of vanishing gradients and to improve the system's accuracy. It needs a lower number of parameters as well as a lower number of filters (12 filters/layer) compared to the ResNet model. It has a default input image size of 224 \(\times\) 224 and its weights are trained on the ImageNet dataset. The DenseNet-121 model has 121 layers, 4 dense blocks, and transition layers in between them. Inside the dense blocks, there are certain numbers of convolutional layers that generate different feature maps. The transition layer's job is to perform downsampling, which is done through a batch normalizing procedure. It aims to keep the feature maps generated by the max-pooling process as small as possible. The feature maps in each dense block in the DenseNet model have the same dimensions, and it concatenates the feature maps derived from prior layers, as shown by the following expression:  
\[x_{l}=H_{l}([x_{0},x_{1},\ldots\ldots x_{l-1}]) \tag{3}\]  
where  
\([x_{0},x_{1},\ldots\ldots x_{l-1}]\) represent the concatenated feature maps obtained from the earlier layers, that is, from the 0 to L1 layers.  
\(H_{l}\) represents the non-linear transformation function, with \"l\" indicating the layer number.  
The DenseNet121 model has initial convolutional layers with output sizes of 112 \(\times\) 112 \(\times\) 64 and a max-pooling layer with output sizes of 56 \(\times\) 56 \(\times\) 64. This produced output is used as the first dense layer's input. One important parameter is the growth rate \"k\", which decides the dimensions of the channel at each layer. The different layers present in the basic DenseNet-121 architecture and the output size of the layers are presented in Table 3 below.  
For positive and negative classification, we added additional layers, such as a global average pooling layer, a dropout layer, a dense layer (512 units) with an L2 regularizer, and a final dense layer (2 units). By freezing the layers of Block 1 and Block 2 of the network and unfreezing the remaining layers (Block 3 and Block 4) that were trained on the Crowdflower image sentiment dataset, we were able to fine-tune the network. The fine-tuned ResNet50 network architecture that we used in our research is illustrated in Figure 5 below.  
\begin{table}
\begin{tabular}{l c c} \hline \hline
**Name of the Layer** & **Size of the Output** & **DenseNet-121** \\ \hline Convolution & \(112\times 112\) & 7 \(\times\) 7 convolution with a stride of 2 \\ \hline Pooling & 56 \(\times\) 56 & 3 \(\times\) 3 max pooling with a stride of 2 \\ \hline Dense Block 1 & 56 \(\times\) 56 & [1 \(\times\) 1 and 3 \(\times\) 3 conv] \(\times\) 6 \\ \hline Transition Layer 1 & 28 \(\times\) 28 & [1 \(\times\) 1] convolution with [2 \(\times\) 2] average pooling layer \\ \hline Dense Block 2 & 28 \(\times\) 28 & [1 \(\times\) 1 and 3 \(\times\) 3 conv] \(\times\) 12 \\ \hline Transition Layer 2 & 14 \(\times\) 14 & [1 \(\times\) 1 and 3 \(\times\) 3 conv] \(\times\) 6 \\ \hline Dense Block 3 & 14 \(\times\) 14 & [1 \(\times\) 1 and 3 \(\times\) 3 conv] \(\times\) 24 \\ \hline Transition Layer 3 & 7 \(\times\) 7 & [1 \(\times\) 1 and 3 \(\times\) 3 conv] \(\times\) 6 \\ \hline Dense Block 4 & 7 \(\times\) 7 & [1 \(\times\) 1 and 3 \(\times\) 3 conv] \(\times\) 16 \\ \hline Classification & 1 \(\times\) 1 & Global average pooling [7 \(\times\) 7] with 1000 fully connected Softmax layers \\ \hline \hline \end{tabular}
\end{table}
Table 3: Layers in DenseNet121 architecture.  
Figure 5: Architecture of fine-tuned DenseNet121 network.