A YOLOv5 garden abnormal target recognition method based on anchor box optimal clustering

By adopting the optimal clustering method based on anchor boxes in YOLOv5, the problem of low recall rate and accuracy rate of small target recognition in gardens is solved, efficient identification of garden waste is achieved, and the investment of manpower and material resources is reduced.

CN114913438BActive Publication Date: 2024-10-11NANJING UNIV OF POSTS & TELECOMM
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210313455.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-03-28
Publication Date
2024-10-11
Estimated Expiration
2042-03-28

AI Technical Summary

Technical Problem

The existing technology has low recall and accuracy rates when identifying small targets in gardens, resulting in poor garbage identification in drone monitoring.

Method used

The YOLOv5 method based on optimal clustering of anchor boxes is used to perform anchor box clustering on the garden garbage image data set through the improved K-means algorithm, and the optimal 9 anchor boxes are obtained, and the anchor box size of the YOLOv5 network model is set. Improve recognition accuracy.

Benefits of technology

It improves the accuracy and recall rate of garden garbage identification, reduces manual inspection work, and is suitable for accurate identification of garbage in videos and picture information captured by drones in smart garden scenes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114913438B_ABST
    Figure CN114913438B_ABST
Patent Text Reader

Abstract

The present invention discloses a YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering, comprising: collecting garden garbage sample images, annotating the garden garbage sample images, and constructing a garden garbage image data set; using an improved K-means algorithm to perform anchor frame clustering on the garden garbage image data set to obtain the optimal 9 anchor frames; setting the anchor frame size of the YOLOv5 network model according to the optimal 9 anchor frames, and training the YOLOv5 network model to obtain a trained YOLOv5 network model, and using the trained YOLOv5 network model to realize garden garbage recognition. In the smart garden scene, using the method of the present invention, the adhered garbage in the video and picture information taken by the drone can be accurately identified, the recall rate and accuracy of garbage recognition are improved, the investment of manpower and material resources in the garden is greatly reduced, and the work of manual inspection is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering, and belongs to the field of target recognition and computer vision. Background Art

[0002] In order to ensure the environment of the garden and improve the tourists' experience, the garden needs to be maintained and managed. However, there are too many links in the existing garden management system that rely on manual operation. For example, for garbage disposal in the garden, cleaning staff generally conduct uninterrupted inspections of the responsible area, clean up the garbage, and ensure the cleanliness of the garden environment. However, due to the large area of ​​the garden, it takes a lot of manpower and material resources to ensure that the garden environment is always clean. In order to reduce the waste of manpower and material resources, most smart gardens now use drones to dynamically monitor the situation in the garden, and then use algorithms such as target recognition to intelligently analyze the monitoring information. With the rapid development of deep learning in the field of computer vision, target recognition technology as a part of the field of computer vision has also achieved breakthrough development. However, in the image information collected by the drone, the size of the garbage is very small compared to the size of the entire image. When annotating, there is a certain gap between the manually marked box and the real target in the picture. However, since the target is very small, the original clustering method (that is, the distance is calculated by IOU) is still used to cluster the anchor box. The small gap during annotation will have a great impact on the clustering result, so the recognition effect is not good. When the anchor box is too large, it will cause the adhered objects to be recognized as one object. Even when two objects with large size differences are adhered, the smaller object will not be recognized at all, resulting in low recall and precision.

[0003] In summary, how to accurately identify small targets in gardens based on existing technologies has become an urgent problem to be solved by people in the industry. Summary of the invention

[0004] The technical problem to be solved by the present invention is to provide a YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering, which solves the problem of low recall rate and accuracy of the prior art for identifying garbage stuck in gardens.

[0005] The present invention adopts the following technical solutions to solve the above technical problems:

[0006] A YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering includes the following steps:

[0007] Step 1: Collect and annotate garden waste sample images to construct a garden waste image dataset;

[0008] Step 2: Use the improved K-means algorithm to cluster the garden waste image dataset into anchor frames and obtain the optimal 9 anchor frames;

[0009] Step 3, setting the anchor frame size of the YOLOv5 network model according to the optimal 9 anchor frames, and training the YOLOv5 network model to obtain a trained YOLOv5 network model, and using the trained YOLOv5 network model to realize garden waste recognition.

[0010] As a preferred solution of the present invention, in the step 1, before labeling the garden waste sample image, the garden waste sample image is pre-processed by translation, rotation and filtering, and then labeled by LabelImg.

[0011] As a preferred solution of the present invention, the specific process of step 2 is as follows:

[0012] Step 2.1, perform background removal operation on each image in the garden waste image dataset;

[0013] Step 2.2, for any image q after background removal m , find the first cluster center of the image according to the following formula:

[0014]

[0015] Where P represents the number of all pixels in the image after removing the background; H i Represents the i-th pixel p i The hue component value of It represents the average value of the hue components of all pixels in the image obtained by converting the color space of each image before background removal;

[0016] Step 2.3, find the next cluster center, as follows:

[0017] Calculate image q m Each pixel p i The shortest multidimensional fusion distance to all the cluster centers selected so far is calculated as follows:

[0018]

[0019]

[0020] Among them, D(p i ) represents pixel p i The shortest multidimensional fusion distance of all cluster centers selected so far, D k (p i ) represents pixel p iTo cluster center c k The multi-dimensional fusion distance of K represents the number of all cluster centers currently selected; H i , H k Represents pixel point p i The hue component and cluster center c k The hue component, (x i ,y i ) represents pixel p i Relative to the coordinates of the entire image, (x k ,y k ) represents the cluster center c k Relative to the coordinates of the entire image, the entire image takes the upper left corner as the coordinate origin, the width is the x-axis, the length is the y-axis, and one pixel is one unit;

[0021] Calculate each pixel p i The probability of becoming the next cluster center is expressed as P(p i ) indicates that the calculation formula is as follows:

[0022]

[0023] The size of the probability range is determined according to the size of the probability, and all probability ranges are randomly distributed between 0 and 1 in sequence. A random number is generated within the range of 0 to 1, and the pixel point corresponding to the probability range where the random number is located is selected as the next cluster center;

[0024] Step 2.4, judging whether it is necessary to select a new cluster center according to the iterative termination condition based on the cluster evaluation coefficient, and repeating step 2.3 if necessary;

[0025] Define the clustering evaluation coefficient f, and determine the number of cluster centers based on the clustering evaluation coefficient. The formula for the clustering evaluation coefficient is as follows:

[0026]

[0027]

[0028]

[0029] Among them, f(K) represents the clustering evaluation coefficient when K cluster centers have been selected; μ K Represents each pixel p i The mean of the shortest multidimensional fusion distance to the current existing cluster centers; Represents each pixel p i The variance of the shortest multidimensional fusion distance to the current existing cluster center;

[0030] The iterative termination conditions based on the clustering evaluation coefficient are divided into the following three cases:

[0031] Case 1: add a cluster center according to the process of step 2.3. The number of cluster centers after the increase is K+1, and the cluster evaluation coefficient after the increase is f(K+1). The aggregation degree of pixels after the increase increases, indicating that the clustering effect is better after the increase. When the increase exceeds ε, that is, f(K)-f(K+1)≥ε, it is necessary to continue to increase, where ε is a threshold greater than 0;

[0032] Case 2: Add a cluster center according to the process of step 2.3. The number of cluster centers after the increase is K+1, and the cluster evaluation coefficient after the increase is f(K+1). When the aggregation degree of the added pixels increases within the range of (0, ε), that is, 0<f(K)-f(K+1)<ε, stop adding, and the final number of cluster centers is K+1;

[0033] Case 3: add a cluster center according to the process of step 2.3. The number of cluster centers after the increase is K+1, and the cluster evaluation coefficient after the increase is f(K+1). When f(K)-f(K+1)<0, stop adding, and the final number of cluster centers is K;

[0034] Step 2.5, after finding all the cluster centers, calculate the multidimensional fusion distance from a certain pixel point in the image to each cluster center, and classify the pixel point into the category of the cluster center corresponding to the shortest multidimensional fusion distance;

[0035] Step 2.6, recalculate the cluster center for the newly added pixel category, specifically: Assume the size of the largest garbage mark in the garden garbage image dataset S is W max , L max , then the length of its diagonal is The cluster center of the newly added pixel category is currently c. If the Euclidean distance from the newly added pixel to the current cluster center c is greater than R max , then the updated cluster center is still c. If the Euclidean distance from the newly added pixel to the current cluster center is less than R max , then the updated cluster center is are the average values ​​of the horizontal and vertical coordinates of all pixels in this category, respectively. The formula is as follows:

[0036]

[0037] Among them, N represents the number of current pixels in this category, x n ,y n They are the horizontal and vertical coordinate values ​​of the nth pixel in this category respectively;

[0038] Step 2.7, repeat steps 2.5 and 2.6 until the position of the cluster center no longer changes;

[0039] Step 2.8, according to the coordinate value x of all pixels in each category min 、x max ,y min ,y max , determine the upper, lower, left, and right boundaries of the anchor box to obtain the anchor box;

[0040] Step 2.9, perform steps 2.2 to 2.8 on each image in the background-removed dataset Q to obtain all anchor boxes;

[0041] In step 2.10, the optimal 9 anchor frames are obtained based on the optimal selection of multi-frame anchor frames based on the 0-1 model.

[0042] As a preferred solution of the present invention, the specific process of step 2.1 is as follows:

[0043] The garden waste image dataset S = {s1, s2, ..., s M Each image s in m Convert the RGB color components into HSV color components to obtain the image after the color space conversion, and calculate the average value of the hue components of all pixels in each image after the color space conversion. The image after the color space conversion is operated with the mask to obtain the region of interest, that is, the hue component in the image after the color space conversion is extracted. The pixels outside the range are obtained to obtain the background-removed data set Q = {q1, q2, ..., q M}, m=1,…,M, where M is the number of images in the garden waste image dataset.

[0044] As a preferred embodiment of the present invention, the specific process of step 2.10 is as follows:

[0045] Arrange the anchor boxes obtained from all images in the background-removed dataset Q into a set E = {E1, E2, ..., E T}, E t represents the tth anchor box, T represents the number of all anchor boxes, and a coordinate system is established with each anchor box as the unit, the upper left corner of each anchor box as the origin, the y-axis downward, and the x-axis to the right to obtain the coordinates of all clustered pixels in the box; a 0-1 model is established based on the aggregation degree of the pixels in the box and the uniformity of the anchor box area size to obtain the optimal anchor box to be selected. The formula of the 0-1 model is as follows:

[0046]

[0047]

[0048] Among them, S t represents the area of ​​the tth anchor box; a t There are only two possible values: 0 and 1; γ represents the adjustment coefficient; d t It represents the distance from all clustered pixels in the tth anchor box to the center point of the anchor box. The formula is as follows:

[0049]

[0050]

[0051]

[0052] Among them, (x j ,y j )、(x c ,y c ) represent the coordinates of the jth pixel point in the anchor box and the coordinates of the center point of the anchor box respectively; L t and W t represents the length and width of the tth anchor box; L represents the number of all clustered pixels in the anchor box.

[0053] Compared with the prior art, the present invention adopts the above technical solution and has the following technical effects:

[0054] 1. The present invention aims at the single background of garden scenes, removes redundant background, reduces iterations and improves clustering speed.

[0055] 2. The present invention proposes an optimal clustering method to cluster the anchor box size of the YOLOv5 model to improve the accuracy and recall rate of garbage identification.

[0056] 3. The method of the present invention can accurately identify garbage in the video and picture information taken by drones in the smart garden scene, greatly reducing the investment in manpower and material resources in the garden and reducing the work of manual inspections. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] Figure 1 It is a flow chart of the YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering of the present invention;

[0058] Figure 2 This is the YOLOv5-s network structure diagram. DETAILED DESCRIPTION

[0059] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and cannot be interpreted as limiting the present invention.

[0060] The flowchart of the YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering proposed in this invention is as follows: Figure 1 As shown, the specific process is as follows:

[0061] Step 1: Collect garden waste sample images through drones, annotate the garden waste sample images, and build a garden waste image dataset;

[0062] Step 1 also includes preprocessing such as translation, rotation, and filtering of the images in the dataset before labeling the dataset; and then labeling the dataset using LabelImag.

[0063] Step 2: Use the improved K-means algorithm to perform anchor frame clustering on the garden waste dataset; the details are as follows:

[0064] (1) Background removal. Before clustering, we first remove the background of each image in the dataset. M}The RGB color components of each image are converted into HSV color components, and then the average value of the hue component (H) of all pixels in each image is calculated. The size of the images in the dataset is W p ×L p ; The image after color space conversion is operated with the mask to obtain the region of interest, and the H component of the pixel in the image is extracted. The pixels outside the range are processed to obtain the data set Q = {q1, q2, ..., q M};

[0065] (2) Select the first cluster center. Select the first cluster center point c1 of the image. The cluster center is calculated by the following formula:

[0066]

[0067] Where P represents the number of all pixels in the image after removing the background; H i Represents the H component value of the i-th pixel.

[0068] (3) Find the next cluster center. Calculate the p of each pixel in the image i The shortest multidimensional fusion distance of all cluster centers selected so far is calculated as follows:

[0069]

[0070]

[0071] Among them, D(p i) represents the pixel p in the image i The shortest multidimensional fusion distance of all cluster centers has been selected so far, and K represents the number of existing cluster center points. k (p i ) represents pixel p i To cluster center c k The multi-dimensional fusion distance, H i , H k Represents pixel point p i The hue H component and cluster center c k The hue H component, (x i ,y i ), (x k ,y k ) represent pixel points p i Relative to the coordinates of the entire image, the cluster center c k Relative to the coordinates of the entire image, the entire image has the upper left corner as the coordinate origin, the width as the x-axis, the length as the y-axis, and one pixel as one unit.

[0072] The probability of each pixel becoming the next cluster center is calculated based on the shortest multidimensional fusion distance of all pixels in the image, and its probability is expressed as P(p i ) indicates that the calculation formula is as follows:

[0073]

[0074] The size of the probability range is determined according to the size of the probability, and it is randomly distributed between 0 and 1 in sequence. Then a random number is generated within the range of 0-1. The pixel point corresponding to the probability within which the random number falls is selected as the new cluster center.

[0075] (4) Determine whether a new cluster center needs to be selected based on the iterative termination condition based on the clustering coefficient, and repeat (3) to find all cluster center points based on the condition. The iterative termination condition based on the clustering coefficient is as follows:

[0076] Define a clustering evaluation coefficient f, and determine the number of cluster centers based on the clustering evaluation coefficient. The formula for the cluster center evaluation coefficient is as follows:

[0077]

[0078]

[0079]

[0080] Where f(K) represents the clustering evaluation coefficient when there are K cluster centers; μ K Represents each pixel p iThe mean of the shortest multidimensional fusion distance to the current existing cluster centers; Represents each pixel p i The variance of the shortest multidimensional fusion distance to the current existing cluster center; when the mean and variance are smaller, it means that the aggregation degree of the pixel points is higher and the clustering effect is better.

[0081] According to the cluster center evaluation coefficient, an iterative termination condition based on the clustering coefficient is proposed. According to the clustering effect, the number of cluster centers is determined. The iterative termination conditions are divided into the following three cases:

[0082] 1) According to the K-means-based anchor box optimal clustering method proposed in the present invention, a cluster center is added. The number of cluster centers after the increase is K+1. The aggregation degree of pixels after the increase increases, indicating that the clustering effect after the increase is better. When the increase exceeds ε, it indicates that iteration needs to be continued, where ε is a threshold greater than 0.

[0083] f(K)-f(K+1)≥ε

[0084] 2) According to the optimal clustering method of anchor boxes based on K-means proposed by the present invention, a cluster center is added. The number of cluster centers after the addition is K+1. After the addition, the aggregation degree of pixels increases, but the increase is not large, that is, when the increase range is between (0, ε), it means that even if cluster centers continue to be added, the clustering effect will not change significantly. At this time, the iteration is stopped and the number of cluster centers is K+1.

[0085] 0<f(K)-f(K+1)<ε

[0086] 3) According to the optimal clustering method of anchor boxes based on K-means proposed by the present invention, a cluster center is added. The number of cluster centers after the addition is K+1. After the addition, the aggregation degree of the pixel points is reduced, and the clustering effect becomes worse. This means that when there are K cluster centers, the aggregation degree of the pixel points has reached the best effect. Then the iteration is stopped when there are K cluster centers, and the number of cluster centers is K.

[0087] f(K)-f(K+1)<0

[0088] (5) After finding all the cluster centers, the multidimensional fusion distance from each pixel in the image to each cluster center is calculated, and the pixel is classified into the category of the cluster center corresponding to the shortest multidimensional fusion distance.

[0089] (6) Recalculate the cluster center for each category. Calculation method: Assume the size of the largest garbage mark in the data set S is W max , L max , then its diagonal is If the Euclidean distance between the pixel currently assigned to the cluster center c and the current cluster center is greater than R max , then the updated cluster center is still c. If the Euclidean distance between the pixel currently assigned to the cluster center c and the current cluster center is less than R max , then the updated cluster center is are the average values ​​of the horizontal and vertical coordinates of the current pixel point of this category, respectively. The formula is as follows:

[0090]

[0091]

[0092] Among them, N represents the number of current pixels of a certain category.

[0093] (7) Repeat (5) and (6) until the position of the cluster center no longer changes.

[0094] (8) According to the coordinate maximum value x of all pixels in each category min 、x max ,y min ,y max Determine the top, bottom, left, and right boundaries of the box to get the anchor box.

[0095] (9) Perform operations (2) to (8) on each image in the dataset Q to obtain all anchor boxes.

[0096] (10) According to the optimal selection of multi-frame anchor frames based on the 0-1 model, the optimal 9 anchor frames are obtained. The optimal selection steps of multi-frame anchor frames based on the 0-1 model are as follows:

[0097] The number of anchor boxes selected in each image is different. Data processing is performed before building the 0-1 model. First, the anchor boxes selected from all images are arranged into a set E = {E1, E2, ..., E T}, then take each anchor box as a unit, take the upper left corner of each anchor box as the origin, downward as the y-axis, and rightward as the x-axis to establish a coordinate system, and obtain the coordinates of all clustered pixels in the box. According to the aggregation degree of the pixels in the box and the uniformity of the size of the anchor box area, a 0-1 model is established to obtain the optimal anchor box to be selected. The formula of the 0-1 model is as follows:

[0098]

[0099]

[0100]

[0101]

[0102]

[0103] Among them, d t represents the distance from all clustered pixels in the tth anchor box to the center of the anchor box; (x j ,y j )、(x c ,y c ) represent the coordinates of the i-th pixel point in the anchor box and the coordinates of the center point of the anchor box respectively; L t and W t represents the length and width of the tth anchor box; S t represents the area of ​​the tth anchor box; γ represents the adjustment coefficient; a t There are only two values: 0 and 1; L represents all pixels in the anchor box.

[0104] Step 3: Set the anchor frame size of the YOLOv5 model according to the clustering results, train the network model, and perform garden waste recognition.

[0105] Set the anchor frame size of the YOLOv5 network model and train the network model. YOLOv5 has four levels of network structures, namely YOLOv5-s, YOLOv5-m, YOLOv5-l and YOLOv5-x. YOLOv5-s is the network with the shallowest network depth and the fastest training speed among the four structures. The number of network layers of other structures increases successively. Therefore, the present invention selects YOLOv5-s for training. The network structure model is shown in the figure Figure 2 shown.

[0106] The above embodiments are only for illustrating the technical idea of ​​the present invention, and cannot be used to limit the protection scope of the present invention. Any changes made on the basis of the technical solution in accordance with the technical idea proposed by the present invention shall fall within the protection scope of the present invention.

Claims

1. A YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering, characterized in that: The steps include: Step 1: Collect and annotate garden waste sample images to construct a garden waste image dataset; Step 2: Use the improved K-means algorithm to cluster the garden waste image dataset into anchor frames and obtain the optimal 9 anchor frames. The specific process is as follows: Step 2.1, perform background removal operation on each image in the garden waste image dataset; Step 2.2, for any image q after background removal m , find the first cluster center of the image according to the following formula: Where P represents the number of all pixels in the image after removing the background; H i Represents the i-th pixel p i The hue component value of It represents the average value of the hue components of all pixels in the image obtained by converting the color space of each image before background removal; Step 2.3, find the next cluster center, as follows: Calculate image q m Each pixel p i The shortest multidimensional fusion distance to all the cluster centers selected so far is calculated as follows: Among them, D(p i ) represents pixel p i The shortest multidimensional fusion distance of all cluster centers selected so far, D k (p i ) represents pixel p i To cluster center c k The multi-dimensional fusion distance of K represents the number of all cluster centers currently selected; H i , H k Represents pixel point p i The hue component and cluster center c k The hue component, (x i ,y i ) represents pixel p i Relative to the coordinates of the entire image, (x k ,y k ) represents the cluster center c k Relative to the coordinates of the entire image, the entire image takes the upper left corner as the coordinate origin, the width is the x-axis, the length is the y-axis, and one pixel is one unit; Calculate each pixel p i The probability of becoming the next cluster center is expressed as P(p i ) indicates that the calculation formula is as follows: The size of the probability range is determined according to the size of the probability, and all probability ranges are randomly distributed between 0 and 1 in sequence. A random number is generated within the range of 0 to 1, and the pixel point corresponding to the probability range where the random number is located is selected as the next cluster center; Step 2.4, judging whether it is necessary to select a new cluster center according to the iterative termination condition based on the cluster evaluation coefficient, and repeating step 2.3 if necessary; Define the clustering evaluation coefficient f, and determine the number of cluster centers based on the clustering evaluation coefficient. The formula for the clustering evaluation coefficient is as follows: Among them, f(K) represents the clustering evaluation coefficient when K cluster centers have been selected; μ K Represents each pixel p i The mean of the shortest multidimensional fusion distance to the current existing cluster centers; Represents each pixel p i The variance of the shortest multidimensional fusion distance to the current existing cluster center; The iterative termination conditions based on the clustering evaluation coefficient are divided into the following three cases: Case 1: add a cluster center according to the process of step 2.

3. The number of cluster centers after the increase is K+1, and the cluster evaluation coefficient after the increase is f(K+1). The aggregation degree of pixels after the increase increases, indicating that the clustering effect is better after the increase. When the increase exceeds ε, that is, f(K)-f(K+1)≥ε, it is necessary to continue to increase, where ε is a threshold greater than 0; Case 2: Add a cluster center according to the process of step 2.

3. The number of cluster centers after the increase is K+1, and the cluster evaluation coefficient after the increase is f(K+1). When the aggregation degree of the added pixels increases within the range of (0, ε), that is, 0<f(K)-f(K+1)<ε, stop adding, and the final number of cluster centers is K+1; Case 3: add a cluster center according to the process of step 2.

3. The number of cluster centers after the increase is K+1, and the cluster evaluation coefficient after the increase is f(K+1). When f(K)-f(K+1)<0, stop adding, and the final number of cluster centers is K; Step 2.5, after finding all the cluster centers, calculate the multidimensional fusion distance from a certain pixel point in the image to each cluster center, and classify the pixel point into the category of the cluster center corresponding to the shortest multidimensional fusion distance; Step 2.6, recalculate the cluster center for the newly added pixel category, specifically: Assume the size of the largest garbage mark in the garden garbage image dataset S is W max , L max , then the length of its diagonal is The cluster center of the newly added pixel category is currently c. If the Euclidean distance from the newly added pixel to the current cluster center c is greater than R max , then the updated cluster center is still c. If the Euclidean distance from the newly added pixel to the current cluster center is less than R max , then the updated cluster center is are the average values ​​of the horizontal and vertical coordinates of all pixels in this category, respectively. The formula is as follows: Among them, N represents the number of current pixels in this category, x n ,y n They are the horizontal and vertical coordinate values ​​of the nth pixel in this category respectively; Step 2.7, repeat steps 2.5 and 2.6 until the position of the cluster center no longer changes; Step 2.8, according to the coordinate value x of all pixels in each category min 、x max ,y min ,y max , determine the upper, lower, left, and right boundaries of the anchor box to obtain the anchor box; Step 2.9, perform steps 2.2 to 2.8 on each image in the background-removed dataset Q to obtain all anchor boxes; Step 2.10, according to the optimal selection of multi-frame anchor frames based on the 0-1 model, the optimal 9 anchor frames are obtained; Step 3, setting the anchor frame size of the YOLOv5 network model according to the optimal 9 anchor frames, and training the YOLOv5 network model to obtain a trained YOLOv5 network model, and using the trained YOLOv5 network model to realize garden waste recognition.

2. The YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering according to claim 1, characterized in that: In the step 1, before labeling the garden waste sample image, the garden waste sample image is pre-processed by translation, rotation and filtering, and then labeled by LabelImg.

3. The YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering according to claim 1, characterized in that: The specific process of step 2.1 is as follows: The garden waste image dataset S = {s1, s2, ..., s M Each image s in m Convert the RGB color components into HSV color components to obtain the image after the color space conversion, and calculate the average value of the hue components of all pixels in each image after the color space conversion. The image after the color space conversion is operated with the mask to obtain the region of interest, that is, the hue component in the image after the color space conversion is extracted. The pixels outside the range are obtained to obtain the background-removed data set Q = {q1, q2, ..., q M }, m = 1,…,M, M is the number of images in the garden waste image dataset.

4. The YOLOv5 garden abnormal target recognition method based on anchor frame optimal clustering according to claim 1, characterized in that: The specific process of step 2.10 is as follows: Arrange the anchor boxes obtained from all images in the background-removed dataset Q into a set E = {E1, E2, ..., E T }, E t represents the tth anchor box, T represents the number of all anchor boxes, and a coordinate system is established with each anchor box as the unit, the upper left corner of each anchor box as the origin, the y-axis downward, and the x-axis to the right to obtain the coordinates of all clustered pixels in the box; a 0-1 model is established based on the aggregation degree of the pixels in the box and the uniformity of the anchor box area size to obtain the optimal anchor box to be selected. The formula of the 0-1 model is as follows: Among them, S t represents the area of ​​the tth anchor box; a t There are only two possible values: 0 and 1; γ represents the adjustment coefficient; d t It represents the distance from all clustered pixels in the tth anchor box to the center point of the anchor box. The formula is as follows: Among them, (x j ,y j )、(x c ,y c ) represent the coordinates of the jth pixel point in the anchor box and the coordinates of the center point of the anchor box respectively; L t and W t represents the length and width of the tth anchor box; L represents the number of all clustered pixels in the anchor box.