# Attention-Based Mechanism and Adversarial Autoencoder for Underwater Image Enhancement
## 2 Materials and Methods
### Feature Attention Module  
Considering the distinct characteristics of the three color space models--RGB, HSV, and Lab--these features, extracted from the three distinct color spaces, are expected to contribute differently. This study employs the channel attention mechanism and the pixel attention mechanism [22] to effectively handle the color variations in underwater images and account for the impact of different water qualities on the images. The specifics of the attention mechanism module are illustrated in Figure 6. Let \(G=\text{Ser}(G1,G2,\cdots,GC)\in\mathbb{R}^{C\times H\times W}\) represent the input feature, where \(G\) denotes the nominal mapping of a certain path, \(C\) is the number of channels of the feature mapping, Ser denotes the feature concatenation, and \(H\) and \(W\) are the height and width of the input image, respectively. In the channel attention mechanism, the spatial dimension of the input feature \(G\) is initially compressed. The feature maps of each channel are then downscaled through a global average pooling operation. This operation transforms the comprehensive spatial information along the channel dimension into a channel descriptor denoted as \(m\in\mathbb{R}^{C\times 1}\), effectively minimizing the network's parameter complexity. The central function of the channel descriptor is to produce an embedded global distribution of channel features, symbolizing the holistic significance of features within the channel. The mathematical expression for the \(k\)th term of \(m\) is as follows:  
\[m_{k}=\frac{1}{H\times W}\overset{H}{\underset{i}{\sum}}\overset{W}{\underset {j}{\sum}}\overset{W}{\underset{j}{\sum}}F_{k}(i,j) \tag{2}\]  
where \(k\in[1,C]\). \(m_{k}\) represents the compressed \"squeeze\" representation of the channel, encapsulating the overarching perceptual information embedded within each channel. Moreover, \(F_{k}\) denotes the weighting coefficients employed in the attention mechanism of the channel's \"excitation\" representation, enabling the targeted amplification of distinct spatial positions within a particular channel. To fully capture individual channel dependencies, a self-gating mechanism [23] is employed to generate a set of modulation weights \(f\in\mathbb{R}^{C\times 1}\). \[f=\sigma\{W_{2}*[\delta(W_{1}*z)]\} \tag{3}\]  
In the equation, \(W_{1}\in\mathbb{R}^{\frac{C}{\tau}\times C}\) and \(W_{2}\in\mathbb{R}^{C\times\frac{C}{\tau}}\) represent the weights of the two fully connected layers. \(\sigma\) denotes the Sigmoid activation function, \(\delta\) represents the ReLU activation function, and \(*\) denotes the convolution operation. The number of output channels for \(W_{1}\) and \(W_{2}\) is equal to \(\frac{C}{\tau}\) and \(C\), respectively. The hyper-parameter \(r\) defines the dimensionality relationship between the two fully connected layers, allowing control over the proportion of dimensionality reduction for the channel weights, thus influencing the model's performance and computational efficiency. For computational purposes, \(r\) is set to 16; comprehensive details can be accessed in [23]. These weights are subsequently applied to the input features \(G\) to produce the output channel features \(G_{c}\). Moreover, to  
Figure 5: The residual enhancement network. mitigate the issue of vanishing gradients and retain valuable information about the original features, we handle the channel attention weights in a similar mapping manner:  
\[G_{c}=G\oplus G\otimes s \tag{4}\]  
where \(\oplus\) represents pixel-by-pixel addition, and \(\otimes\) denotes pixel-by-pixel multiplication. The channel attention mechanism primarily concentrates on the allocation of weights across distinct channels. As a complementary technique to the channel attention mechanism, the pixel attention mechanism is centered on weight distribution across various pixel locations within a singular feature map, enabling the network to focus on regions with varying turbidity levels underwater.