# A Stave-Aware Optical Music Recognition on Monophonic Scores for Camera-Based Scenarios
## 3 Method Details
### Stave Detection  
Different from the general multi-stage OMR methods, our work concerns not only note detection but also staff line detection. As shown in Figure 3, stave features are fed into the stave detection model to obtain the position of staff lines. With the absolute position of the note head, we can estimate its relative position to the staff lines--i.e., which line or space it occupies--by linear interpolation.  
Figure 3: Overview of note pitch determination.  
Figure 2: Flow chart of the morphological filter.  
As for the stave detection model, we design a stave-aware network based on the YOLOX-S [41]. The complete network consists of three stages:  
1. _Feature extraction._ We choose the CSPDarknet [42] backbone to extract the features of the staff lines (sized \(576\times 576\times 3\)). The CSPDarknet adopts the structure of YOLOv5s but replaces the LeakyReLU activation function with SiLU.
2. _Feature fusion._ The output of the backbone is an image with a size of \(20\times 20\times 512\), which is then fed into PANet [43] for feature fusion. Finally, the network will obtain three feature branches with sizes of \(20\times 20\times 512\), \(40\times 40\times 256\), and \(80\times 80\times 128\).
3. _Decoupling of prediction branch._ On the fused feature map, different channel feature maps are first unified to 128 dimensions with a \(1\times 1\) convolution. Then, two branches are used to perform decoupling on the detection head, and an IOU branch is added to the regression branch. Finally, the network merges the output of the three branches. Since the spectral-aware network used in this paper has a classification number of 1, the final network will output a two-dimensional vector of size 6 \(\times\) 8400. Here, 8400 represents the number of predicted boxes, and 6 represents the regression and classification information for each predicted box.  
On the basis of the original YOLOX network, we add the YIoU loss branch to strengthen the training of the stave-aware network. When predicting the position of staff lines, we only consider the vertical location of the prediction box rather than its horizontal width. This is because the vertical position plays a crucial role in determining the pitch arrangement. To enhance the network's perception of the height position of staff lines, we design a YIoU loss to measure the rectangular boxes' overlap degree in the ordinate direction, as shown in expression (1) and Figure 4.  
\[YIoU=\frac{length(P\bigcap B)}{length(P\bigcup B)}=\frac{L1}{L2} \tag{1}\]  
To avoid the situation shown in Figure 4b, we add YIoU loss to IoU loss in the original loss function. The total loss of the network and the loss of each branch are shown in expressions (2) and (3). In the expressions, \(\alpha\) represents the weight coefficient, which controls the influence degree of IoU and YIoU loss. In our work, we set \(\alpha=5\). Both the classification branch and the regression branch use the BCE loss function.  
\[L_{total}=\alpha\times L_{IoU}+\alpha\times L_{YIoU}+L_{cls}+L_{loc} \tag{2}\]  
\[L_{YIoU}=\frac{1}{N_{pos}}\sum_{i\in pos}^{N}1-YIoU_{i}^{2} \tag{3}\]