An adaptive anchor box generation method, cloth defect detection method and device
Patent Information
- Application Number
- CN202310327338.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-30
- Publication Date
- 2026-09-29
- Estimated Expiration
- 2043-03-30
AI Technical Summary
然而在布匹缺陷检测任务中,人工设计所得锚框需要不断根据经验去调整,时间成本高
[0026]本发明的一种自适应锚框生成方法、布匹检测方法及装置,基于布匹缺陷图像数据集统计得到缺陷的长宽分布,然后通过聚类分析计算若干聚类中心,并根据长宽比排序、分组,采样得到长宽比组合以进行自适应的锚框设计,综合了聚类算法、覆盖率与锚框间的相似性,自适应地设计出针对布匹缺陷数据集的预定义锚框,从而使锚框设计结果准确可靠,提高了布匹缺陷检测的精度。
Smart Images

Figure CN116452525B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of fabric defect detection, specifically relating to an adaptive anchor frame generation method, a fabric defect detection method and device. Background Technology
[0002] In the intelligent identification of fabric defects, the design of anchor frames plays a crucial role in defect detection. Current technologies have traditionally relied on manual design or clustering methods for anchor frame design. However, in fabric defect detection tasks, manually designed anchor frames require continuous adjustments based on experience, resulting in high time costs. Using clustering methods to directly design anchor frames tends to concentrate in densely populated areas, leading to less than ideal coverage.
[0003] In fabric defect detection methods, designing the optimal anchor box combination for new datasets plays a decisive role in the accuracy of the defect detection model. To design anchor boxes better suited for fabric defect detection datasets, it is necessary to consider coverage and anchor box similarity on top of traditional clustering algorithms, requiring a combination of clustering, ranking, and group sampling algorithms. Summary of the Invention
[0004] To address the shortcomings of existing technologies and achieve adaptive anchor frame design, thereby improving anchor frame coverage, reducing anchor frame similarity, and ultimately enhancing the accuracy of fabric defect detection, this invention adopts the following technical solution:
[0005] An adaptive anchor box generation method includes the following steps:
[0006] Step S1: Statistically analyze the length and width of the fabric defect dataset images to obtain the length and width distribution map of the fabric defect targets;
[0007] Step S2: Set multiple cluster centers based on the length and width distribution map of fabric defect targets;
[0008] Step S3: Obtain sampling points based on the length and width of the fabric defect target corresponding to the cluster center, and design a set of anchor frames as adaptive anchor frames for fabric defect detection based on the sampling points.
[0009] Furthermore, in step S2, the length and width cluster centers are calculated using the following formula:
[0010]
[0011] In the formula, x represents the cluster center to be calculated in the length-width distribution map of fabric defect targets, and μ i Let S = {S1, S2} represent the average value of the points surrounding the i-th cluster center. 2, …,S k} represents the calculated k cluster centers. By iteratively finding a set of cluster centers, the average distance from the surrounding points to their respective cluster centers is minimized.
[0012] Furthermore, in step S3, the sampling points are obtained by sorting the ratio of the length to the width of the fabric defect target corresponding to the cluster center, then dividing the sorted ratio into segments, with each segment forming a group, and selecting sampling points from each group.
[0013] Furthermore, in step S3, the length and width ratios are sorted in ascending order, and the first ratio of each group, as well as the first and last ratios of the last group, are used as sampling points.
[0014] A fabric defect detection method, based on the aforementioned adaptive anchor frame generation method, further includes step S4: the fabric defect detection model detects fabric defects based on the adaptive anchor frame.
[0015] An adaptive anchor frame generation device includes a statistical analysis module, a clustering module, and an anchor frame generation module;
[0016] The statistical analysis module performs statistical analysis on the length and width of the fabric defect dataset images to obtain a length and width distribution map of the fabric defect targets.
[0017] The clustering module sets multiple cluster centers based on the length and width distribution map of fabric defect targets;
[0018] The anchor frame generation module obtains sampling points based on the length and width of the fabric defect target corresponding to the cluster center, and designs a set of anchor frames as adaptive anchor frames for fabric defect detection based on the sampling points.
[0019] Furthermore, the clustering module calculates the length and width cluster centers using the following formula:
[0020]
[0021] In the formula, x represents the cluster center to be calculated in the length-width distribution map of fabric defect targets, and μ i Let S = {S1, S2} represent the average value of the points surrounding the i-th cluster center. 2, …,S k} represents the calculated k cluster centers. By iteratively finding a set of cluster centers, the average distance from the surrounding points to their respective cluster centers is minimized.
[0022] Furthermore, in the anchor frame generation module, the sampling points are obtained by sorting the ratio of the length to the width of the fabric defect target corresponding to the cluster center, then dividing the sorted ratio into segments, with each segment forming a group, and selecting sampling points from each group.
[0023] Furthermore, in the anchor frame generation module, the length and width ratios are sorted in ascending order, and the first ratio of each group, as well as the first and last ratios of the last group, are used as sampling points.
[0024] A fabric defect detection device includes a fabric defect detection model, wherein the fabric defect detection model detects fabric defects based on an adaptive anchor frame obtained by the aforementioned adaptive anchor frame generation device.
[0025] The advantages and beneficial effects of this invention are as follows:
[0026] This invention discloses an adaptive anchor frame generation method, fabric detection method, and apparatus. Based on a fabric defect image dataset, the length and width distribution of defects are statistically obtained. Then, several cluster centers are calculated through cluster analysis, and the data are sorted and grouped according to aspect ratio. Sampling is then performed to obtain aspect ratio combinations for adaptive anchor frame design. This method integrates clustering algorithms, coverage, and similarity between anchor frames to adaptively design predefined anchor frames for the fabric defect dataset, thereby making the anchor frame design results accurate and reliable, and improving the accuracy of fabric defect detection. Attached Figure Description
[0027] Figure 1 This is a flowchart of fabric defect detection based on the adaptive anchor frame generation method in an embodiment of the present invention.
[0028] Figure 2 This is a cluster center distribution diagram of the fabric defect dataset in this embodiment of the invention.
[0029] Figure 3 This is a sorting and grouping sampling diagram in an embodiment of the present invention.
[0030] Figure 4a This is an anchor diagram generated by the K-Means clustering design method.
[0031] Figure 4b It is an anchor frame diagram generated by the manual anchor frame design method.
[0032] Figure 4c This is an anchor frame diagram generated by the adaptive anchor frame design method in this embodiment of the invention. Detailed Implementation
[0033] The specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.
[0034] like Figure 1 As shown, an adaptive anchor box generation method includes the following steps:
[0035] Step S1: Statistically analyze the length and width of the fabric defect dataset images to obtain the length and width distribution map of the fabric defect targets;
[0036] according to Figure 2 As can be seen from the length and width distribution of the fabric defect dataset, the length and width distribution of fabric defects is very sparse and includes many defects with extreme aspect ratios. Manually designing anchor boxes to cover the fabric defect dataset as much as possible is time-consuming and costly. Using traditional K-Means results in cluster centers being more concentrated in dense areas.
[0037] Step S2: Set multiple cluster centers based on the length and width distribution map of fabric defect targets;
[0038] In this embodiment of the invention, to cover as many complex and varied fabric defects as possible, nine types of anchor frames need to be designed at the same location. To cover as many fabric defect targets as possible, a clustering algorithm is used to generate 72 cluster centers.
[0039] The length and width of the cluster centers are calculated using the following formula:
[0040]
[0041] In the formula, x represents the cluster center to be calculated in the length-width distribution map of fabric defect targets, and μ i Let S = {S1, S2} represent the average value of the points surrounding the i-th cluster center. 2, …,S k} represents the calculated k cluster centers. By iteratively finding a set of cluster centers, the average distance from surrounding points to their respective cluster centers is minimized.
[0042] Step S3: Obtain sampling points based on the length and width of the fabric defect target corresponding to the cluster center, and design a set of anchor frames as adaptive anchor frames for fabric defect detection based on the sampling points.
[0043] The sampling points are obtained by sorting the length-to-width ratios of the fabric defect targets corresponding to the cluster centers, then dividing the sorted ratios into segments, with each segment forming a group, and selecting sampling points from each group. The length-to-width ratios are sorted in ascending order, and the first ratio of each group, as well as the first and last ratios of the last group, are used as sampling points.
[0044] In this embodiment of the invention, the sorted aspect ratios are divided into several segments according to their ascending order, and the minimum aspect ratio value is selected as the sampling point within each segment. For the last segment, both the minimum and maximum values within the segment are used as sampling points. The sorted aspect ratios and sampling points are as follows: Figure 3 As shown, the aspect ratios are sorted from smallest to largest from top left to bottom right. Each row is a segment, and the leftmost cell in each row represents the smallest aspect ratio of that segment, i.e., the sampling point for that segment. The anchor frame designed based on the sampled aspect ratios is shown below. Figures 4a to 4c As shown.
[0045] A fabric defect detection method, based on an adaptive anchor frame generation method, further includes step S4: the fabric defect detection model detects fabric defects based on the adaptive anchor frame.
[0046] In this embodiment of the invention, a fabric defect detection model based on Cascade R-CNN is used to verify the rationality and accuracy of the adaptive anchor frame design method. The length and width of the anchor frames designed by the manual anchor frame design method, the traditional K-Means anchor frame design method, and the adaptive anchor frame design method are shown in Table 1.
[0047] Table 1 Comparison of Anchor Frame Results for Three Anchor Frame Design Methods
[0048]
[0049] from Figures 4a to 4c As can be seen from Table 1, the adaptive anchor frame design takes into account both the coverage of defect targets and minimizing the similarity between anchor frames.
[0050] As shown in Table 2, the adaptive anchor frame design method improves the average accuracy by 0.4% compared to the manual anchor frame design method and by 0.8% compared to K-Means, achieving an average accuracy of 55%.
[0051] Table 2. Statistical Table of Three Anchor Frame Design Methods
[0052]
[0053] Therefore, this invention can design anchor frames suitable for fabric defect datasets through an adaptive anchor frame design method based on clustering, sorting, and group sampling. The designed anchor frames have good accuracy and reliability, and can improve the accuracy of fabric defect detection.
[0054] An adaptive anchor frame generation device includes a statistical analysis module, a clustering module, and an anchor frame generation module;
[0055] The statistical analysis module performs statistical analysis on the length and width of the fabric defect dataset images to obtain a length and width distribution map of the fabric defect targets.
[0056] The clustering module sets multiple cluster centers based on the length and width distribution map of fabric defect targets; the clustering module calculates the length and width cluster centers using the following formula:
[0057]
[0058] In the formula, x represents the cluster center to be calculated in the length-width distribution map of fabric defect targets, and μ iLet S = {S1, S2} represent the average value of the points surrounding the i-th cluster center. 2, …,S k} represents the calculated k cluster centers. By iteratively finding a set of cluster centers, the average distance from the surrounding points to their respective cluster centers is minimized.
[0059] The anchor frame generation module obtains sampling points based on the length and width of the fabric defect targets corresponding to the cluster centers. A set of anchor frames is designed based on these sampling points as adaptive anchor frames for fabric defect detection. The sampling points are obtained by sorting the length-to-width ratio of the fabric defect targets corresponding to the cluster centers, then dividing the sorted ratios into segments, with each segment forming a group. Sampling points are selected from each group. The length-to-width ratios are sorted in ascending order, and the first ratio of each group, as well as the first and last ratios of the last group, are used as sampling points.
[0060] A fabric defect detection device includes a fabric defect detection model, which detects fabric defects based on an adaptive anchor frame obtained by an adaptive anchor frame generation device.
[0061] The above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An adaptive anchor frame generation method, characterized in that... Includes the following steps: Step S1: Statistically analyze the length and width of the fabric defect dataset images to obtain the length and width distribution map of the fabric defect targets; Step S2: Set multiple cluster centers based on the length and width distribution map of fabric defect targets; The length and width of the cluster centers are calculated using the following formula: In the formula This represents the cluster centers to be calculated in the length-width distribution map of fabric defect targets. This represents the average value of the points surrounding the i-th cluster center. This means that by iteratively finding a set of cluster centers from the calculated k cluster centers, the average distance from the surrounding points to their respective cluster centers is minimized. Step S3: Obtain sampling points based on the length and width of the fabric defect target corresponding to the cluster center, and design a set of anchor frames as adaptive anchor frames for fabric defect detection based on the sampling points. The sampling points are obtained by sorting the ratio of the length to the width of the fabric defect target corresponding to the cluster center, then dividing the sorted ratio into segments, with each segment as a group, and selecting sampling points from each group. The length and width ratios are sorted in ascending order, and the first ratio of each group, as well as the first and last ratios of the last group, are used as sampling points. Specifically, the sorted aspect ratios are divided into several segments from smallest to largest, and the smallest aspect ratio value in each segment is selected as the sampling point of that segment. For the last segment, both the minimum and maximum values in the segment are used as sampling points; the anchor frame is designed based on the sampled aspect ratios.
2. A method for detecting fabric defects, characterized in that: The adaptive anchor frame generation method according to claim 1 further includes step S4: the fabric defect detection model detects fabric defects based on the adaptive anchor frame.
3. An adaptive anchor frame generation device, comprising a statistical analysis module, a clustering module, and an anchor frame generation module, characterized in that: The statistical analysis module performs statistical analysis on the length and width of the fabric defect dataset images to obtain a length and width distribution map of the fabric defect targets. The clustering module sets multiple cluster centers based on the length and width distribution map of fabric defect targets; the clustering module calculates the length and width cluster centers using the following formula: In the formula This represents the cluster centers to be calculated in the length-width distribution map of fabric defect targets. This represents the average value of the points surrounding the i-th cluster center. This means that by iteratively finding a set of cluster centers from the calculated k cluster centers, the average distance from the surrounding points to their respective cluster centers is minimized. The anchor frame generation module obtains sampling points based on the length and width of the fabric defect target corresponding to the cluster center, and designs a set of anchor frames as adaptive anchor frames for fabric defect detection based on the sampling points. In the anchor frame generation module, the sampling points are obtained by sorting the ratio of the length and width of the fabric defect target corresponding to the cluster center, then dividing the sorted ratio into segments, with each segment as a group, and selecting sampling points from each group. In the anchor frame generation module, the length and width ratios are sorted in ascending order, and the first ratio of each group, as well as the first and last ratios of the last group, are used as sampling points. Specifically, the sorted aspect ratios are divided into several segments from smallest to largest, and the smallest aspect ratio value in each segment is selected as the sampling point of that segment. For the last segment, both the minimum and maximum values in the segment are used as sampling points; the anchor frame is designed based on the sampled aspect ratios.
4. A fabric defect detection device, comprising a fabric defect detection model, characterized in that: The fabric defect detection model is based on the adaptive anchor frame detection of fabric defects obtained by the adaptive anchor frame generation device described in claim 3.
Citation Information
Patent Citations
Leather flaw detection method and system based on improved YOLOv3
CN114022446A