# YOLO-OHFD: A YOLO-Based Oriented Hair Follicle Detection Method for Robotic Hair Transplantation
## 2 Materials and Methods
### Structure of YOLO-OHFD
#### 2.2.2 Feature Fusion Network Based on Feature Alignment  
After a detailed description of the YOLO-OHFD feature extraction network structure and its core component, ECA-Res2 Block, we will now focus on the construction and optimization of the feature fusion network. This section is key to understanding how the entire detection framework effectively integrates and utilizes multi-scale features.  
A feature alignment module (FAM) is proposed and integrated into the feature pyramid structure (FPN) to enhance multi-scale feature fusion.  
FPN is constructed by upsampling input image to generate a series of images with different resolutions. It can help the network to process image information better at different scales, and thus improve the performance of visual task, which plays an important role in target detection and localization tasks. The structure of the FPN is shown in Figure 5a.  
Figure 4: Structure of feature extraction network based on adaptive receptive field. **(a)** Backbone is the feature extraction network named CSPDarknet53. **(b)** Structure of ECA-Res2 Block. **(c)** Structure of ECA. ECA obtains aggregated features by global average pooling (GAP), and then generates weights by 1D convolution with a convolution kernel of k, where k is obtained adaptively from the channel dimensions.  
However, in oriented object detection, the FPN may have feature misalignment during the upsampling feature fusion process [28]. Especially in oriented hair follicle detection, the hair follicle has a large aspect ratio and can appear at any angle. If the layers of the FPN are not properly aligned, it leads to a lack of consistency in the expression of the hair follicle features at different angles, which not only makes it difficult to correctly identify the boundary information of object, but also increases the sensitivity of detection results to angle change. It may decrease the stability of follicle localization in the rotational detection.  
To solve this problem, we propose a FAM and integrate it into the upsampling process of the FPN. The structure of the FAM is shown in Figure 5b. First, the feature map \(\text{F}_{\text{i}-1}\) is upsampled to obtain \(\hat{\text{F}}_{\text{i}}\), then the offset present at each pixel point between \(\hat{\text{F}}_{\text{i}}\) and \(\text{C}_{\text{i}}\) is calculated and converted into an offset in 2D space. The calculation formula is shown in Equation (1):  
\[D_{i}=f_{o}\big{[}\hat{F}_{i},\text{C}_{i}\big{]} \tag{1}\]  
where \(\Delta_{\text{i}}\) is the offset between each prime in the two feature layers. \(f_{o}\) [\(\cdot\)] is the function that transforms the pixel offset. \(\big{[}\hat{\text{F}}_{\text{i}},\text{C}_{\text{i}}\big{]}\) denotes the stitching of the two feature layers.  
Then, the offsets are learned by proposing deformable convolution network (DCN) and acted on in the upsampled feature map for matching alignment. The calculation process is shown in Equation (2):  
\[F_{i}=f_{d}\big{[}\hat{F}_{i},D_{i}\big{]} \tag{2}\]  
where \(\text{F}_{\text{i}}\) is the aligned feature map. \(f_{d}[\cdot]\) is the deformable convolution function.