# BEAC-Net: Boundary-Enhanced Adaptive Context Network for Optic Disk and Optic Cup Segmentation
## 3 Methods
### Attentional Feature Fusion  
In the decoder, to exploit the complementary spatial structure details and semantic information, we design an attentional feature fusion (AFF) module, which fuses different levels of features to address the potentially large inconsistencies in scale and semantics, as shown in Figure 5. Low-level features are rich in spatial detail, and high-level features are richer in semantic information. To this end, the AFF module selectively aggregates features at different levels based on different weights and optimizes feature maps at high levels and low levels. The whole procedure is summarized in Algorithm 1. The features obtained using the attention module are upsampled by \(4\times 4\) to obtain the high-level semantic information \(X\), which is a feature with a larger receptive field, and the low-level semantic feature \(Y\) for feature fusion to obtain feature \(Z\). \(X\) and \(Y\) first perform the initial feature fusion. After the sigmoid function, the output value is between 0 and 1. \(X\) and \(Y\) calculate the weighted average so that the group fusion weight is subtracted by 1.  
The calculation formula is  
\[A=F\Big{(}X\biguplus Y\Big{)}\bigotimes X+\Big{(}1-F\Big{(}X\biguplus Y\Big{)} \Big{)}\bigotimes Y \tag{3}\]  
Figure 4: Structure of proposed efficient boundary pixel attention (EBPA).  
Figure 5: Structure of proposed attentional feature fusion (AFF).  
where \(F(X)\) is concerned with the scale of the channel via point-by-point convolution, and the channel attention of the point convolution local features is calculated using the formula \(H(X)\):  
\[H(X)=Y(PWConv_{2}(\sigma(Y(PWConv_{1}(X))))) \tag{4}\]  
where \(PWConv_{1}1\times 1\) point-wise convolution reduces the number of input feature \(x\) channels to \(\frac{1}{r}\), \(B\) is the BatchNormalization layer, \(\sigma\) is the ReLU function that via \(PWConv_{2}1\times 1\) convolution restores the channel numbers to the same number as the input channels, and \(r\) denotes the channel reduction ratio.  
\(M(X)\) is the channel attention formula for the global feature and differs from \(H(X)\) in that a global average pooling (GAP) operation is first performed on the input \(A\). \(F(X)\) is expressed as  
\[F(X)=\sigma\Big{(}H(X)\bigoplus M(X)\Big{)} \tag{5}\]  
where \(H(X)\) is the channel attention of the local features, \(M(X)\) is the channel attention of the global feature, and \(\sigma\) denotes the ReLU function.  
```
0: Feature map X, Feature map Y, size = [B, L, C], \(B=Batchsize\), \(L=H*W\), \(C=Channels\) //X is low-level feature, Y is high-level feature
0: Feature map Z, size = [B, L, C]
1:\(input=[B,\ L,\ C]\to input=[B,\ H,\ W,\ C]\) //\(H=height\), \(W=weight\) as the height and weight of fundus image
2:x = [B, C, H, W], y = [B, C, H, W]
3:xa = x + y
4:x_local = local_att(xa) //Channel attention of local features
5:\(x1=k1*xa\)
6:\(x2=\delta(batchnormal(x1))\)
7:x_local = batchnormal(k2*x2)
8:x_global = global_att(xa) //Channel attention of global features
9:\(x1=AdaptiveAvgPool(xa)\)
10:\(x2=k3*x1\)
11:\(x3=\delta(batchnormal(x2))\)
12:\(x_global=batchnormal(k4*x3)\)
13:\(xlg=x\_local+x\_global\)
14:\(w=sigmoid(xlg)\)
15:\(z_{1}=2\times x\times w+2\times y\times(1-w)\)
16:\(Z=tail(z_{1})\)
17:return Z
18:In the above \(formulas,\delta\) refers to ReLU function, \(*\) denotes convolution operation, kidemets convolutional filters with kernel size \(3\times 3\), AdaptiveAvgPool denotes AdaptiveAvgPooling, sigmoid denotes sigmoid function.
```  
**Algorithm 1** Description of the AFF