# KCFS-YOLOv5: A High-Precision Detection Method for Object Detection in Aerial Remote Sensing Images
## 3 Improvements of the KCFS-YOLOv5
### The Clustering Anchor Box Optimization  
In the conventional YOLOv5 algorithm, the detection anchor box will have a certain effect on detection results. The initial anchor boxes in the conventional algorithm are nine anchor boxes of random sizes designed and generated using the K-means clustering algorithm, it covers objects of various sizes. However, the K-means algorithm randomly selects the center points of the K pre-training marked boxes in the data set as the center of each cluster. If the location of the initial points is not selected properly, the final clustering result should be very negative. It significantly affects the mean average precision (Map) of training. We therefore propose a K-means++ algorithm-based [41] anchor framework generation mechanism for optimization.  
First, we set the number of center points K that need to be clustered, and randomly select a center point C\({}_{first}\) of a pre-training marker framework \(C\) from the graph as the initial clustering center.  
Second, we reselect all points except the initial cluster point we picked \(R_{rest}\) in the dataset and compute the IOU distance \(D(C_{first},R_{rest})\) of \(R_{rest}\) and \(C_{first}\) can be denoted by:  
\[D(C_{first},R_{rest})=1-\text{IOU}(C_{first},R_{rest}) \tag{1}\]  
Then, the probability \(P_{next~{}1}\) that each reselect point \(R_{rest}\) to become the next cluster center \(R_{next}\) in the first iteration can be expressed as:  
\[P_{next~{}1}=\frac{D^{2}\Big{(}C_{first},R_{next}\Big{)}}{\sum_{R_{rest}\in data }D^{2}\Big{(}C_{first},R_{rest}\Big{)}} \tag{2}\]  
Furthermore, using the Roulette method, the probability \(P_{next}\) of selecting the next cluster point \(C_{second}\) will be evaluated, and the process is shown in Figure 2.  
After applying a K-mean++ algorithm, two cluster centers \(C_{first}\) and \(C_{second}\) in the graph are generated. We change the probability \(P_{next~{}2}\) that each reselected point \(R_{rest}\) to become the next cluster center \(R_{next}\) in subsequent iterations which can be expressed as:  
\[P_{next~{}2}=\frac{D^{2}(C_{close},R_{next})}{\sum_{R_{rest}\in data}D^{2}(C_{ close},R_{rest})} \tag{3}\]  
where \(C_{close}\) represents the cluster center closest to each reselect point \(R_{rest}\), and the process is shown in Figure 3.  
Like the first loop, we will evaluate the probability \(P_{next~{}1}\) to select the next cluster point C\({}_{third}\) by the Roulette method. After iterating the K-means++ algorithm K times, we can generate K cluster centers such as: \(C_{first}C_{second}\cdots C_{k}\). Based on the K optimised cluster centers we have obtained, we use the traditional K-means clustering method that comes with YOLOv5 to generate anchors.  
Figure 2: The process of generating the second cluster center.  
This method ensures that there is a certain distance between the initial K cluster centers, which can effectively alleviate the problem that the cluster center points tend to local optimal solutions due to the chance of random selection, and at the same time it can improve the detection accuracy.