# Image Dehazing Algorithm Based on Deep Learning Coupled Local and Global Features
## 3 Method of This Paper
### Network Structure
The main computational overhead in transformer comes from the self-attention mechanism. In traditional self-attention, the time and storage complexity of the key-query dot product interaction grows quadratically with the spatial resolution of the input, which is less suitable for certain high-resolution image restoration tasks that apply its larger computational load. To alleviate the above problem, a deep separable convolution method was used to implement the self-attentive mechanism, and the specific structure is shown in Figure 3. The key factor is the application of the self-attention mechanism across channels, rather than the spatial dimension (i.e., the calculation of cross-covariance across channels to generate an attention map that implicitly encodes the global context). A deep convolution was introduced to emphasize the local context before the feature covariance was computed to generate a global attention map. We normalized the tensor \(Y\in R^{\overset{\wedge}{H\times W}\times\overset{\wedge}{C}}\) by applying a \(1\times 1\) convolution to aggregate the cross-pixel level channel context and expand the number of channels to three times to make the tensor shape \(H\times W\times 3C\). Then, the channel-level spatial context was encoded using \(3\times 3\) deep convolution, and the resulting tensor was divided equally into three parts along the channel dimension to obtain \(W_{d}^{Q}W_{\text{P}}^{Q}\),\(W_{d}^{K}W_{\text{P}}^{K}\) and \(W_{d}^{V}W_{\text{P}}^{V}\). \(W_{\text{P}}^{(\bullet)}\) is the \(1\times 1\) point convolution, \(W_{\text{d}}^{(\bullet)}\) is the \(3\times 3\) depth convolution. The values obtained from the above operations were used to calculate the query (Q), key (K), and value (V) projections, respectively, by using the formulas \(Q=W_{d}^{Q}W_{\text{P}}^{Q}Y\),\(K=W_{d}^{K}W_{\text{P}}^{K}Y\) and \(V=W_{d}^{V}W_{\text{P}}^{V}Y\). Then, the mapping of queries and keys is reshaped so that their dot products interact to produce a transposed attention map of size \(R^{\overset{\wedge}{C}\times\overset{\wedge}{C}}\). In general, the calculation process can be expressed as the following equation:  
\[\overset{\wedge}{X}=W_{P}Attention\left(\overset{\wedge}{Q},\overset{\wedge} {K},\overset{\wedge}{V}\right)+X \tag{4}\]  
\[Attention\left(\overset{\wedge}{Q},\overset{\wedge}{K},\overset{\wedge}{V} \right)=\overset{\wedge}{V}\cdot Softmax\left(\overset{\wedge}{K}\cdot\overset{ \wedge}{Q}/\alpha\right) \tag{5}\]  
where \(X\overset{\wedge}{X}\) are the input and output feature maps, respectively. \(\overset{\wedge}{Q}\in R^{\overset{\wedge}{HW\times C}}\), \(\overset{\wedge}{K}\in R^{\overset{\wedge}{C}\times\overset{\wedge}{HW}}\) and \(\overset{\wedge}{V}\in R^{\overset{\wedge}{HW\times C}}\) are obtained by reconstructing the original size of \(R^{\overset{\wedge}{HW\times C}}\). In the case of the Softmax function, \(\alpha\) is a learnable scale parameter used to control the size of the dot product of \(\overset{\wedge}{K}\) and \(\overset{\wedge}{Q}\) before applying the Softmax function. Similar to the traditional multi-headed self-attention, the number of channels is divided into multiple heads that learn separate attention maps in parallel. In addition to the attention layer, the vision transformer contains a fully connected feedforward network that performs the same operation on each pixel location separately. It uses two \(1\times 1\) convolutions: one for expanding the feature channels (usually by a factor \(\gamma\) = 4) and the other for reducing the channels to the original input dimension. A ReLU activation function between two convolution operations was also applied in the hidden layer to incorporate nonlinear factors.