# Respiratory Sound Classification by Applying Deep Neural Network with a Blocking Variable
## 3 The Architecture of the Network  
### The Block-I, Block-II, and the Self-Attention Block  
We proposed a network called the Blnet, which consists of three important blocks, the Block-I, Block-II, and the Self-attention block. The architecture of the Blnet without the blocking variable is shown in Figure 2.  
The design of the architecture was inspired by the Lung Sound Resnet with Non-Local Layer (LungRN + NL) [15]. The spectrogram (STFT) and scalogram (WT) are the input images of the network. Two channels with the same architecture were adopted to study them separately. In each channel, a 2D 1 \(\times\) 1 convolution filter was used to expand the channel size of the input image to 64, and the channel size was kept to be the same all the time. The channel size was not expanded because the total amount of ICBHI 2017 data is not large. Therefore, a smaller network could prevent overfitting. However, a smaller network does not mean the network is simple. Instead, the Blnet includes various operations in each block. The Block-I, Block-II, and Self-attention block were applied to study the deep \begin{table}
\begin{tabular}{c c c c c c c c c c c c c c c c} \hline \hline  & **Cluster1** & **Cluster2** & **Cluster3** & **Cluster4** & **Cluster5** & **Cluster6** & **Cluster7** & **Total** \\ \hline
**Before/After** & **B** & **A** & **B** & **A** & **B** & **A** & **B** & **A** & **B** & **A** & **B** & **A** & **B** & **A** \\ \hline Normal & 530 & 530 & 580 & 580 & 566 & 566 & 333 & 333 & 427 & 427 & 202 & 202 & 271 & 271 & 2910 & 2910 \\ Wheeze & 89 & 178 & 225 & 450 & 222 & 444 & 308 & 616 & 202 & 404 & 188 & 376 & 264 & 528 & 1498 & 2996 \\ Crackle & 99 & 297 & 114 & 342 & 150 & 450 & 106 & 318 & 100 & 300 & 51 & 153 & 75 & 225 & 695 & 2085 \\ Both & 20 & 20 & 87 & 87 & 65 & 65 & 69 & 69 & 80 & 80 & 38 & 38 & 56 & 56 & 415 & 415 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: The data augmentation is carried out within the clusters. The cluster1, cluster2, cluster3, cluster4, cluster5, cluster6, cluster7 represent the ’Tc’, ’AI’, ’Ar’, ’PI’, ’Pr’, ’L’, ’Lr’, respectively. features of the input image. The details of Block-I and Block-II are shown in Figure 3. In both Block-I and Block-II, we integrated the strength of the GoogleNet [18] and ResNet [17]. Convolutions with different kernel sizes and average pooling were adopted to study the features across the time and frequency domain. In both the spectrogram and scalogram, the energy shifts over the time and frequency domain. Significant features could be hidden in a small interval or a larger interval. Thus, three convolution kernels, \(3\times\ 3\), \(4\times\ 4\), and \(5\times\ 5\), were applied to ensure that those features could be captured. In addition, a \(3\times\ 3\) average pooling was adapted to store the average energy at a local place. We used the Relu [24] as our activation function and the group normalization [25] to standardize data. We found the group normalization worked better than batch normalization and instance normalization in Blnet. The image size was reduced by one-half by Block-I, as the stride was equal to two, and a one-by-one convolution layer in Block-I aims to keep the residual information [17] of the input. A Self-attention block [19] was put in the middle of the Blnet to study the connection between the channels across the time and frequency domain. This operation allows the interaction between the channels. The formula of the attention mechanism is summarized below:  
\[Attention(Q,K,V)=softmax(\frac{Q^{T}K}{\sqrt{d}})V, \tag{2}\]  
where \(V\) is the input of the self-attention layer, and \(K\) and \(Q\) are two arrays with the same shape as \(V\), generated by two \(1\times\ 1\) convolution layers, respectively, and \(d\) is equal to the channel size, which is 64. To be specific, the image of each channel is firstly stretched into a vector by transferring it from 2D to 1D before applying the self-attention mechanism.