Asymmetric hard negative sample penalty loss optimization method for extremely fine defect detection, electronic device and storage medium
By using an asymmetric hard negative sample penalty loss optimization method, high-confidence false detection samples are screened and the penalty weight is increased. At the same time, positive sample compensation is introduced, which solves the problems of high false detection rate and low recall rate in microfluidic chip detection and achieves the technical effect of detecting minute defects.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHANGZHOU UNIV
- Filing Date
- 2026-05-18
- Publication Date
- 2026-07-14
Smart Images

Figure CN122391786A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of machine vision inspection and deep learning target detection technology, and particularly to the field of microfluidic chip inspection technology, specifically to an asymmetric hard negative sample penalty loss optimization method, electronic device and storage medium for the detection of extremely subtle defects. Background Technology
[0002] Microfluidic chips, with their advantages of low reagent consumption, fast analysis speed, and high integration, are widely used in biomedical detection, flexible sensing, chemical analysis, and environmental monitoring. However, due to factors such as processing technology, bonding precision, packaging conditions, and transportation vibration, microfluidic chips are prone to minor defects during fabrication and transfer, such as residual bubbles, channel defects, bonding misalignment, contaminant adhesion, and dimensional deviations, which directly affect the chip's accuracy and detection reliability.
[0003] Microfluidic chip defects have significant scene-specific characteristics: the defect target size is extremely small and the pixel ratio is extremely low; the chip background channels are dense, the edges are complex, and the textures are varied, and the channel boundaries, normal process traces and real defects are highly similar in visual features; the number of defect samples is scarce, and there is a serious class imbalance problem; the detection model is prone to high response to complex background areas, outputting a large number of high-confidence false detection boxes (the macroscopic rectangular result finally output by the detection model is obtained by integrating a large number of detection positions), forming a significant "falsely high confidence" phenomenon.
[0004] Existing deep learning-based object detection methods typically employ standard binary cross-entropy loss or its conventional variants for classification branch optimization. However, these methods have significant limitations in detecting extremely subtle defects in microfluidic chips: they fail to differentiate between training samples and a large number of ordinary negative samples and a small number of high-risk negative samples; they struggle to accurately and selectively suppress high-confidence false positives; and they are prone to over-reacting to background pseudo-defect structures, resulting in a persistently high false positive rate. Furthermore, simply increasing the global penalty for negative samples can excessively suppress the response of real, minute defects, leading to a significant decrease in defect recall. Summary of the Invention
[0005] The technical problem to be solved by this invention is: in order to selectively enhance the penalty for high-confidence false positive negative samples (hard negative samples) while taking into account the response capability of real small defects, this invention provides an asymmetric hard negative sample penalty loss optimization method, electronic device and storage medium for the detection of extremely small defects, which controls false detections while taking into account the response capability of real defects.
[0006] The technical solution adopted by this invention to solve its technical problem is: an optimization method for asymmetric hard negative sample penalty loss for detecting extremely subtle defects, comprising the following steps: Step 1: Based on the improved target detection network, output the classification prediction value of each detection area to obtain the defect classification prediction probability.
[0007] Step 2: Construct a basic binary cross-entropy classification loss based on the true labels and defect classification prediction probabilities of each detection area.
[0008] Step 3: Select detection areas where the defect classification prediction probability is higher than the preset trigger threshold and the true label is a negative sample, and generate a hard negative sample mask.
[0009] Step four: For the hard negative samples obtained by filtering with the hard negative sample mask, introduce an asymmetric weighted penalty weight into the negative sample loss of the basic binary cross-entropy classification loss to increase the additional penalty corresponding to the hard negative samples.
[0010] Step 5: Introduce a positive sample compensation coefficient into the positive sample loss of the basic binary cross-entropy classification loss to increase the weight of real defect samples with positive labels in the total loss.
[0011] Step 6: Using the main classification loss with asymmetric weighted penalty and positive sample compensation, the target detection network is iteratively trained to obtain a target detection model suitable for detecting extremely subtle defects.
[0012] It should be noted that this scheme does not apply a uniform fixed weight to all samples. Instead, it constructs a hard negative sample mask through a threshold-triggered mechanism, activating additional penalties only for high-confidence false positives that meet certain conditions; for ordinary negative samples, the base loss weight remains unchanged. Meanwhile, the positive sample compensation coefficient is not set in isolation but is used in conjunction with the hard negative sample asymmetric penalty to mitigate the recall decline caused by enhanced negative sample suppression in the detection of extremely subtle defects. Therefore, the weight design in this application is a "condition-triggered sample-level asymmetric weighting," not the ordinary fixed weight adjustment used in existing technologies for difficult samples or class imbalance problems. This scheme enhances the response to real small defects through the positive sample compensation coefficient, strengthens the hard negative sample correction at the gradient level, effectively suppresses high-confidence false positives and avoids suppressing small target defects, significantly improving the detection accuracy and stability of extremely subtle defects in complex backgrounds.
[0013] In some embodiments, in step one, the improved object detection network is built based on a regression-driven existing object detection framework (an existing single-stage object detection framework).
[0014] The target detection network includes at least a backbone feature extraction network, a feature fusion network, and a multi-scale detection head.
[0015] This regression-driven, single-stage target detection framework balances detection speed and accuracy, addressing the technical challenge of balancing real-time performance and accuracy in detecting extremely subtle defects. It is well-suited for the high-efficiency detection needs of microfluidic chips, precision devices, and other applications. The collaborative setup of a backbone feature extraction network, a feature fusion network, and multi-scale detection heads effectively extracts weak texture features of extremely subtle defects and fuses feature information from different levels, preventing these features from being drowned out by background noise and improving the detection rate. The multi-scale detection heads can be specifically adapted to extremely subtle defects of different sizes (such as tiny scratches and tiny bubbles), solving the problem of missed or false detections of small targets by single-scale detection heads and broadening the network's detection adaptability.
[0016] In some embodiments, in step two, let the first The true classification label for each detection area is: ,in When, it indicates a positive sample; when When, it indicates that the detection area is background or negative sample; let the first... The defect classification prediction probability for each detection area is: The basic binary cross-entropy classification loss is then:
[0017] The basic classification loss over all detection regions can then be expressed as:
[0018] Where N is the total number of detection regions participating in classification training (classification training refers to the learning process of distinguishing positive and negative sample categories for each detection region on the feature map during the training phase of improving the object detection network).
[0019] It should be noted that by clearly defining the mathematical form of the basic binary cross-entropy loss, a clear and unified calculation benchmark is provided for the subsequent introduction of asymmetric hard negative sample penalty terms and positive sample compensation terms, making the design and derivation process of the improved loss function rigorous and controllable. At the same time, the loss calculation method based on the detection region is perfectly matched with the screening granularity of the hard negative sample mask, providing a direct and efficient calculation basis for the subsequent targeted weighted penalty for high-confidence false detection regions, ensuring that the improved loss function can accurately act on the target region without affecting the normal training of ordinary background samples.
[0020] In some embodiments, in step three, the hard negative sample mask The construction method is as follows: When the Each detection region satisfies the condition that its true label is a negative sample and its defect classification prediction probability is [missing information]. Greater than the trigger threshold If the condition is met, it is marked as a hard negative sample; otherwise, it is not marked as a hard negative sample (it is marked as other, such as background or ordinary negative sample). The hard negative sample mask satisfies:
[0021] By constructing the hard negative sample mask as described above, we can achieve accurate, localizable, and conditional screening of high-confidence false negative samples. This is different from the global reselection of the sample set in traditional online hard sample mining, and also different from the uniform weight modulation of hard samples by the general loss function.
[0022] This hard negative sample mask uses "the true label is a negative sample and the predicted probability is higher than the trigger threshold" as the trigger condition. It can dynamically lock the background region that is easily misjudged as a defect by the improved object detection network during the training process. It provides a clear target and calculation basis for subsequent targeted application of asymmetric weighted penalties, and realizes a differentiated optimization mechanism of "ordinary negative samples have no additional constraints, and high-confidence false positive negative samples are accurately strengthened and penalized".
[0023] In some embodiments, in step four, an asymmetric weighted penalty weight is introduced into the negative sample loss for the hard negative samples. At that time, the first The improved negative sample loss corresponding to each detection region is:
[0024] in, It is the negative sample loss based on the binary cross-entropy loss; For the first The hard negative sample mask value corresponding to each detection area; Add a penalty coefficient to hard negative samples.
[0025] The improved negative sample loss directly achieves the asymmetric mechanism of "no additional constraints on ordinary negative samples and enhanced penalties for hard negative samples," solving the pain point that "global penalties easily suppress small defects." The weighted operation is directly embedded in the calculation of the basic classification loss, without the need for additional sample screening or resampling steps, resulting in low computational overhead and easy deployment in object detection networks.
[0026] In some embodiments, in step five, a positive sample compensation coefficient is applied to the positive sample loss to obtain the compensated improved positive sample loss as follows:
[0027] in, It is the positive sample loss based on the binary cross-entropy loss; This is the compensation coefficient for positive samples.
[0028] The above approach enhances the target detection network's response to real, small defects by increasing the weight of positive samples, preventing the missed detection of small target defects due to excessive background suppression, and effectively resolving the optimization contradiction in class imbalance scenarios.
[0029] In some embodiments, after combining the asymmetric weighted penalty for hard negative samples with compensation for positive samples, the... The classification loss for each detection region is:
[0030] The primary classification loss is:
[0031] The above approach, by introducing a positive sample compensation coefficient and combining it with the asymmetric weighted penalty weight of hard negative samples, achieves a balance between the optimization intensity of positive and negative samples in the micro-defect detection scenario, avoiding the loss of one for the other, and realizing bidirectional guidance at the gradient level.
[0032] In some embodiments, the trigger threshold The range is: , Within this range, it can effectively screen out false positive negative samples with "artificially high confidence" while avoiding the inclusion of a large number of ordinary negative samples into the hard negative sample set, thus achieving a better balance between false positive suppression capability and real defect recall capability.
[0033] In some of these embodiments, The value can be dynamically updated using an adaptive adjustment method. This update method is calculated based on detection precision and recall to achieve a better balance between false positive rate control and recall maintenance; specifically: Set the initial value of the trigger threshold. ; In improving the training process of the object detection network, let the first... The trigger threshold after one round of training is The balance criterion is defined as follows:
[0034] in, For the first Improve the recall rate of the object detection network on the validation set after training rounds; For the first Improve the accuracy of the object detection network on the validation set after training rounds; The reference recall rate is the level of recall that the target detection network is expected to achieve. The reference accuracy is the level of accuracy that the target detection network is expected to achieve. This is a balancing factor used to adjust the relative weights of insufficient precision and decreased recall in triggering threshold updates.
[0035] Based on the aforementioned balance criterion, the trigger threshold is updated as follows:
[0036] in, For the first The hard negative sample trigger threshold used during round training; This is the trigger threshold updated based on the current performance status and used for the next round of training. The threshold update step size is used to control the magnitude of each adjustment; and These are the lower and upper limits of the allowed change of the trigger threshold, respectively, to ensure that the trigger threshold is always within a reasonable range; To stabilize the trigger threshold, it is used to determine whether the current performance deviation has reached a level that requires adjustment of the trigger threshold.
[0037] The beneficial effects of this invention are: 1. Compared with the prior art, the present invention is not a general prediction score screening, threshold judgment or overall weight adjustment of loss items. Instead, it constructs a triggered hard negative sample mask for high confidence false detection samples in negative samples, and only applies sample-level asymmetric weighting penalty to hard negative samples. At the same time, positive sample compensation is introduced to alleviate the problem of decreased recall rate that may be caused by the reinforcement of negative samples in the detection of extremely subtle defects. 2. Differentiated Optimization Mechanism: This invention can further reduce interference from complex backgrounds by combining a dynamic region constraint auxiliary mechanism. Compared with the existing object detection methods that uniformly constrain all negative samples, this invention can selectively strengthen and suppress high-confidence hard negative samples, so that the training focus of the improved object detection network changes from average background suppression to targeted correction of false detection risk samples. Through this asymmetric loss design, hard negative samples obtain a larger gradient update intensity during backpropagation, thereby improving the ability of the improved object detection network to suppress false defects in complex backgrounds and high-confidence false detection responses. 3. Performance advantages of bidirectional balance: This invention combines positive sample compensation coefficient and dynamic region constraint auxiliary mechanism to reduce false detections while maintaining the ability to respond to real minute defects. It significantly improves accuracy and overall detection performance while keeping recall within an acceptable range, effectively solving the inherent contradiction between "false detection suppression" and "defect recall" in the detection of extremely minute defects. Attached Figure Description
[0038] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0039] Figure 1 This is an overall flowchart of the method of the present invention.
[0040] Figure 2 This is a performance comparison chart of different versions of the lightweight target detection framework in the method of this invention.
[0041] Figure 3 This is a schematic diagram of the improved target detection network framework in the method of this invention.
[0042] Figure 4 This is a block diagram of the existing lightweight target detection framework.
[0043] Figure 5 This is a schematic diagram of the hard negative sample mask construction process in the method of the present invention.
[0044] Figure 6 This is a block diagram of the improved target detection network structure in the method of this invention.
[0045] Figure 7 It is the region supervision mask in the method of this invention. A schematic diagram of the generation module. Detailed Implementation
[0046] The present invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.
[0047] For ease of understanding, the inventive concept will be described in its entirety before a detailed description of the embodiments of the present invention: To address the problems of extreme imbalance between positive and negative samples, high false detection rates in complex backgrounds, and difficulty in effectively suppressing high-confidence hard negative samples in existing technologies, this paper proposes a three-pronged asymmetric loss design: "trigger-based screening of hard negative samples - targeted penalty for hard negative samples - introduction of positive sample compensation to achieve bidirectional balance." This design overcomes the limitations of existing technologies by upgrading from "averaging background suppression" to "targeted correction of false detection risk samples," significantly improving the model's ability to suppress false defects in complex backgrounds. Furthermore, it upgrades from "global weight modulation" to "mask-triggered conditional penalty + positive sample compensation," significantly improving detection precision while effectively controlling the decline in recall. The overall solution requires no additional sample screening or resampling steps, is computationally efficient, easy to deploy, and can be directly embedded into the classification branch of existing target detection networks, adapting to the practical engineering needs of detecting extremely fine defects in microfluidic chips.
[0048] Example 1: like Figure 1 , Figure 3 The image shows an embodiment of the present invention, which describes an optimization method for asymmetric hard negative sample penalty loss in the detection of extremely subtle defects. The method includes the following steps: S1, Construct an improved target detection network and obtain classification prediction output: Based on the classification prediction value of each detection area output by the improved target detection network, obtain the defect classification prediction probability.
[0049] The specific implementation is as follows: Constructing an improved object detection network and obtaining classification prediction output: Based on the existing single-stage object detection framework, an improved object detection network (improved object detection network) suitable for detecting extremely fine defects in microfluidic chips is constructed. The improved object detection network is a deep learning-based single-stage object detection framework, specifically employing a lightweight convolutional neural network with a multi-scale feature fusion structure (e.g., the YOLO series and its evolutions, including but not limited to YOLOv8, YOLOv10, YOLOv11, or their subsequent optimized versions). For example, the performance comparison results of different versions of lightweight object detection frameworks (existing single-stage object detection frameworks) are as follows: Figure 2 As shown in the figure, the accuracy-efficiency comparison results of different versions of lightweight object detection frameworks on the MS COCO dataset are presented. The left figure shows the relationship between inference latency (latency) and detection accuracy (mAP) of the object detection framework, while the right figure shows the relationship between computational cost (FLOPs) and detection accuracy (mAP). A smaller horizontal axis indicates faster inference speed or lower computational cost, while a larger vertical axis indicates higher detection accuracy. Therefore, the closer the curve is to the upper left region, the better the overall performance of the object detection framework. Figure 2 It can be seen that the target detection framework exhibits a better accuracy-efficiency trade-off overall under different scales, and can achieve high detection accuracy under similar time delay or similar computational load conditions.
[0050] Considering the comprehensive performance of metrics such as accuracy, recall, and mAP, a lightweight evolved version (YOLO series) was selected as the lightweight target detection framework for this invention. Based on this framework, an improved target detection network suitable for detecting extremely fine defects in microfluidic chips was constructed. This lightweight target detection framework is as follows: Figure 4 As shown.
[0051] The improved target detection network retains the core feature extraction network, feature fusion network, and multi-scale detection head of the target detection framework. The core feature extraction network is responsible for extracting features from the input image layer by layer, gradually obtaining semantic features at different levels through convolutional layers and feature enhancement. The feature fusion network integrates shallow detail information with deep semantic information at multiple scales through upsampling, feature concatenation, and feature fusion to enhance the representation ability of targets of different sizes, especially small defects. The multi-scale detection head outputs three detection branches, Detect-P3, Detect-P4, and Detect-P5, based on the fused multi-scale features, to classify and predict the location of defects at different scales. This structure features lightweight design, multi-scale feature fusion, and hierarchical detection output, providing good target representation ability while maintaining computational efficiency. Therefore, it is suitable as a target detection framework for further introducing hard negative sample penalty, positive sample compensation, and region-assisted supervision mechanisms in this invention.
[0052] The improved target detection network, based on a multi-scale detection head, introduces a region response auxiliary branch in the small target main feature layer of the feature fusion network. This branch learns the spatial response differences between defect-related regions and invalid background regions, and implements dynamic spatial constraints for the classification optimization process. The region response auxiliary branch outputs single-channel region response logits (ROI logits) through convolution operations, and obtains a dynamic region response probability map through a sigmoid function. This map can be further combined with cropping and upsampling operations to construct dynamic region response results corresponding to the spatial location of the original microfluidic chip image. The dynamic region response results output by the region response auxiliary branch are used to construct a dynamic region constraint auxiliary mechanism in subsequent steps to reduce the interference of complex background regions on the classification optimization process and improve the stability of hard negative sample recognition and penalty processes.
[0053] The microfluidic chip image is fed into an improved target detection network. After passing through a backbone feature extraction network, a feature fusion network, and a multi-scale detection head, the classification prediction value logits for each detection region is obtained. The defect classification prediction probability is then obtained by mapping using the Sigmoid function.
[0054] in, For the first The classification output logit for each detection region; For the first The defect classification prediction probability is the probability that each detected region belongs to a defective target. The defect classification prediction probability reflects the confidence level of the improved target detection network in that each detected region belongs to a defective target, and is the basis for subsequent construction of the basic classification loss, screening of high-risk misclassified samples, and implementation of asymmetric reinforcement penalty.
[0055] S2, Constructing the basic classification loss: Based on the true label and defect classification prediction probability of each detection area, construct the basic binary cross-entropy classification loss.
[0056] The specific implementation is as follows: In the improved object detection network's classification branch (a sub-network branch within the multi-scale detection head specifically used to output classification prediction values logits), let the... The true label for each detection area is ,in:
[0057] when When the detection area corresponds to a real defect target, it indicates that the detection area is a positive sample; when When the value is specified, it indicates that the detected area is either background or a negative sample area. The defect classification prediction probability is based on the result obtained in step S1. The basic binary cross-entropy classification loss is constructed as follows:
[0058] The basic classification loss over all detection regions can then be expressed as:
[0059] Where N is the total number of detection regions participating in classification training.
[0060] The above classification loss function is the most commonly used classification optimization form in existing improved object detection networks. Its advantages are simple expression and stable optimization, but it has significant shortcomings in the task of detecting extremely fine defects in microfluidic chips. Since the background area is much larger than the real defect area, the number of ordinary negative samples is extremely large. However, what truly affects detection accuracy is often not all negative samples, but rather a small number of falsely detected negative samples (hard negative samples) that are given high confidence by the improved object detection network. The basic binary cross-entropy classification loss ( Applying a uniform penalty to all negative samples fails to highlight the training weights for these "hard negative samples," thus easily leading to high false positive responses in detection areas with complex textures, channel edge structures, and contamination spots. It satisfies the optimization logic of "uniform sample weighting", but does not meet the actual need of "high-confidence false negative samples should be severely punished" in the scenario of detecting minor defects.
[0061] S3, Construct a hard negative sample mask with a threshold triggering mechanism: Filter out detection areas where the defect classification prediction probability is higher than the preset triggering threshold and the true label is a negative sample, and generate a hard negative sample mask.
[0062] The specific implementation is as follows: To filter out truly high-risk negative samples (hard negative samples) that are likely to cause false positives from a large number of negative samples, a hard negative sample mask with a threshold triggering mechanism is introduced. Its definition is as follows:
[0063] in, This is the hard negative sample trigger threshold, used to determine whether the current negative sample belongs to the "high confidence false positive negative sample". The meaning of this definition is: only when the first... Each detection area itself is a true negative sample, that is... Furthermore, the improved target network resulted in values exceeding the trigger threshold. Higher defect prediction probability Only then is the detection area marked as a hard negative sample, i.e. Otherwise, the detection area will not be treated as a hard negative sample.
[0064] Hard negative sample mask The construction process is as follows Figure 5 As shown, the hard negative sample mask is only used to label high-confidence false positive negative samples that meet the conditions, and does not apply to true defect positive samples. The hard negative sample mask can further distinguish negative samples into ordinary negative samples and hard negative samples, providing a basis for subsequently constructing a differentiated classification loss.
[0065] For example, hard negative sample trigger threshold A pre-set fixed trigger threshold is preferably set between 0.50 and 0.70. This range is chosen because the hard negative sample mask is used to filter out high-confidence negative samples with a significant tendency to falsely detect from the real negative samples; therefore, the trigger threshold cannot be too low or too high. Below 0.50, some ordinary background locations may be included in the hard negative sample set due to slight fluctuations in the defect classification prediction probability. This leads to a significant increase in the number of negative samples with enhanced penalties, causing the improved object detection network to over-suppress background regions during training. Consequently, it weakens the network's ability to respond to truly minute defects, resulting in a decrease in recall. Above 0.70, only a very small number of negative samples are identified as hard negative samples. Some high-risk negative samples, while prone to false detection, whose defect classification prediction probability has not yet reached a higher level, cannot be included in the enhanced penalty range in a timely manner, thus reducing the suppression effect on false defects in complex backgrounds and resulting in a negligible decrease in the false detection rate. In contrast, when... When the value is between 0.50 and 0.70, it can effectively screen out falsely detected negative samples with "artificially high confidence" while avoiding the inclusion of a large number of ordinary negative samples into the hard negative sample set. Therefore, it can achieve a better balance between false detection suppression capability and real defect recall capability.
[0066] S4. Construct an asymmetric hard negative sample penalty function to achieve more than 2 times gradient penalty: For hard negative samples obtained by screening by hard negative sample mask, introduce asymmetric weighted penalty weights into the basic binary cross-entropy classification loss to increase the penalty weights corresponding to hard negative samples.
[0067] The specific implementation is as follows: After constructing the hard negative sample mask, a sample-level asymmetric weighted penalty is introduced into the negative sample loss of the basic binary cross-entropy classification loss. Ordinary negative samples retain their basic loss weights, while hard negative samples labeled by the hard negative sample mask receive higher loss weights. "Sample-level" means that the asymmetric weighted penalty is applied to each negative sample according to the detection region, and "asymmetric" means that different negative samples do not receive a uniform penalty intensity; instead, additional penalties are applied only to hard negative samples labeled by the hard negative sample mask. This approach not only increases the loss contribution of hard negative samples but also amplifies their reverse update intensity during gradient propagation, thus forming an asymmetric gain at the gradient level.
[0068] First, the positive sample loss and negative sample loss in the basic binary cross-entropy classification loss are expressed as follows:
[0069]
[0070] This can be written as the sum of the two above. To enhance the penalty capability for high-confidence false positives, this invention introduces an asymmetric weighted penalty weight into the negative sample loss. :
[0071] in, Add a penalty coefficient to hard negative samples.
[0072] For example, Pre-set coefficient values can be used; It does not have a uniform and constant effect on all negative samples, but only on high-confidence false positive negative samples marked with hard negative sample masks.
[0073] No. The improved negative sample loss corresponding to each detection region is:
[0074] Therefore, the asymmetric classification loss over a single detection region can be expressed as:
[0075] The main classification loss for all detection regions is:
[0076] As the core of this method, this step aims to address the problem of the basic binary cross-entropy classification loss "indiscriminately penalizing" different types of negative samples. For the task of detecting extremely fine defects in microfluidic chips, although the number of negative samples in the background region is large, what truly affects the detection accuracy is not all of the negative samples, but rather a small number of negative samples that are mistakenly assigned high defect confidence by the network. These negative samples typically correspond to channel edges, local contamination textures, light-dark boundary regions, bonding traces, or uneven structures on the material surface, possessing local morphological features similar to real defects, and are therefore easily misidentified as defect targets by existing conventional detection models. Applying the same loss form to all negative samples results in easily classifiable backgrounds and high-risk false detection backgrounds being subject to approximately the same constraints during training. This "average penalty" mechanism fails to highlight the importance of high-confidence false detection samples. Especially in scenarios with extremely subtle defects, if a conventional detection model generates a high prediction probability in a locally complex background region, it is prone to forming false detection boxes, which are then retained in subsequent non-maximum suppression or candidate box selection processes, ultimately affecting the overall detection accuracy. Therefore, relying solely on conventional negative sample supervision is insufficient to effectively suppress such "artificially high confidence" false detection responses.
[0077] Therefore, this method further divides negative samples into two categories: ordinary negative samples and hard negative samples, and uses hard negative sample masks. The system differentiates between different types of negative samples. For ordinary negative samples, the base loss weights remain unchanged to maintain training stability; however, for hard negative samples that meet the triggering conditions, an additional penalty coefficient is introduced. This amplifies the corresponding loss term proportionally. Essentially, this design constitutes an asymmetric weighting mechanism, meaning it doesn't uniformly enhance all negative samples, but rather focuses on suppressing only the negative samples with the highest false detection risk. This avoids overwhelming truly noteworthy false detection samples with a large number of simple background samples, and allows the updated parameters of the improved object detection network to more effectively serve the goal of reducing false detections in complex backgrounds.
[0078] Furthermore, from a training perspective, the asymmetric classification loss does not simply increase the overall negative sample loss. Instead, it shifts the optimization focus from "suppressing all negative samples" to "prioritizing the suppression of high-response negative samples that have already resulted in errors" through a "threshold filtering + targeted amplification" approach. This method better aligns with the practical needs of microfluidic chip defect detection, because in such tasks, what truly affects detection reliability is often not the generally low response of the background region, but rather the abnormally high response of a few localized regions.
[0079] Explanation of "more than 2 times gradient penalty": For example, when a gradient penalty of more than 2 times is required for high-confidence false positive boxes, the aforementioned asymmetric weighted penalty weights can be used. Direct implementation. When a detection region is not a hard negative sample. ,but: ; At this point, its negative sample loss is Consistent; when a certain detection area is determined to be a hard negative sample. ,but: ; As long as You can then obtain: ; Hard negative samples selected by the hard negative sample mask have their asymmetric weighted penalty weights amplified to at least twice that of ordinary negative samples.
[0080] Loss on negative samples In this regard, its gradient with respect to the classification output logit satisfies:
[0081] After introducing the asymmetric weighted penalty for hard negative samples, we have:
[0082] satisfy season We can obtain:
[0083] It should be noted that the "more than twice the gradient penalty" in this example is not an empirical description, but can be directly derived from the improved form of the negative sample loss function. For negative samples selected by the hard negative sample mask, the weight of their negative sample loss is increased from 1 to... .when This means that such negative samples (hard negative samples) exert at least twice the effect on improving the parameter updates of the target detection network during backpropagation as ordinary negative samples.
[0084] S5, Introducing a positive sample compensation coefficient: A positive sample compensation coefficient is introduced into the positive sample loss in the basic binary cross-entropy classification loss to increase the weight of real defect samples with positive labels in the total loss.
[0085] The specific implementation is as follows: Because microfluidic chips have extremely small and few minute defects, simply enhancing the negative sample penalty, while effectively reducing false positives, may also lead to a decrease in the improved target detection network's response to real defects, resulting in a reduced recall rate. Therefore, this method further introduces a positive sample compensation coefficient into the positive sample loss. This is used to improve the contribution of real defect samples in classification training. It should be noted that the positive sample compensation coefficient is not an isolated fixed weighting to address the sample imbalance problem, but rather is set in conjunction with the hard negative sample asymmetric weighting penalty in step S4. This is used to alleviate the contradiction between "enhanced false detection suppression" and "preservation of real defect response" in the detection of extremely subtle defects, thereby reducing false detections while maintaining recall. The improved positive sample loss after compensation is defined as:
[0086] in, The positive sample compensation coefficient can be a pre-set value; then, after combining the hard negative sample penalty and the positive sample compensation, the... The classification loss for each detection region is:
[0087] The primary classification loss is:
[0088] Set positive sample compensation coefficient The aim is to alleviate the training bias problem caused by the severe imbalance between positive and negative samples in the detection of extremely small defects in microfluidic chips. Since real defects are typically small in size and few in number, their proportion of pixels and detection area in the entire image is significantly lower than that of the background area. Therefore, if optimization relies solely on conventional classification loss, the improved object detection network is more susceptible to the dominance of a large number of negative samples during training, thus tending to learn a "conservative prediction" strategy—that is, more likely to classify uncertain areas as background to reduce the overall loss value. While this trend can reduce some false positives to some extent, it may also weaken the improved object detection network's ability to respond to real small defects, leading to increased false negatives or decreased recall.
[0089] Step S4 has already imposed an additional penalty on the hard negative samples. If only the negative sample constraints are strengthened without simultaneously increasing the importance of positive samples, the classification branch may become further biased towards background suppression during the improvement of the target detection network parameter update process, making it even more difficult for small-sized defect targets, which are already in a weak response state, to be fully learned. To avoid this problem, this method introduces a positive sample compensation coefficient into the positive sample loss. By increasing the loss contribution of real defect samples, the improved target detection network can maintain its ability to focus on valid defect signals while suppressing false detections. From the perspective of loss composition, The introduction of this method is equivalent to weighting and amplifying the positive sample loss, making the prediction error corresponding to the real defect account for a higher proportion of the overall optimization objective. When the improved target detection network fails to predict a particular real defect sample, i.e. When it is too low, multiply by Subsequently, the loss value generated in the detection area and the backpropagation gradient will increase synchronously, thereby prompting the improved target detection network to correct the classification output of this type of sample more quickly and improve the sensitivity to the identification of subtle defects. Steps S5 and S4 work together to form an asymmetric classification optimization mechanism for extremely subtle defect detection scenarios.
[0090] S6 employs a main classification loss with introduced asymmetric weighted penalty and positive sample compensation to iteratively train the target detection network, resulting in a target detection model suitable for detecting extremely subtle defects.
[0091] The specific implementation is as follows: S61, optionally introduces a dynamic region constraint auxiliary mechanism: In this invention, the ROI (effective defect region / high interference background region represented by the dynamic region response probability map output by the region response auxiliary branch) is not a preset static region, but is dynamically predicted by the region response auxiliary branch based on the input features (feature map of the small target master feature layer output by the feature fusion network); the region supervision mask generated by the Ground Truth annotation information (complete ground truth data annotated manually, including target boxes, category labels and region supervision masks) is only used to supervise the learning of the region response auxiliary branch and is not directly used as the classification loss weight.
[0092] An improved region response auxiliary branch in the target detection network is used to learn the spatial distribution differences between defect-related regions and invalid background regions. Its structure is as follows: Figure 6 As shown, this can further reduce the interference of invalid background areas, image edge areas, and non-critical texture areas in microfluidic chip images on classification training.
[0093] For example, the region response auxiliary branch can be derived from the P3 feature layer. The region response auxiliary branch first performs channel compression and local spatial information extraction on the features through convolutional layers, outputting single-channel ROI logits. Then, it is mapped using the Sigmoid function to obtain a dynamic region response probability map. As a region-assisted supervision, the region response auxiliary branch serves two purposes: firstly, it learns the spatial response differences between defect-related regions and complex background regions; secondly, it provides region constraint information for classification loss in subsequent loss construction, thereby reducing the interference of invalid background on training. The improved object detection network achieves a collaborative structure of "main detection (backbone feature extraction network, feature fusion network, and multi-scale detection head) + region-assisted supervision" by introducing the region response auxiliary branch, providing network-level support for subsequent hard negative sample penalty, positive sample compensation, and dynamic region constraint assistance mechanisms.
[0094] Let the first The predicted regional response value corresponding to each detection area is Then we have: ; in, Indicates the area response auxiliary branch in the th The ROI logits of a single channel output for each detection region. Characterizing the first The confidence level of a detection area belonging to a defect-related valid region / high-interest region (i.e., the target region in the region supervision mask generation process, which is the ground truth region containing the real defects and their extended range, obtained by spatial expansion of the original target box labels).
[0095] To ensure that the regional response auxiliary branch has a clear basis for supervision, a regional supervision mask is generated based on the Ground Truth annotation information (which refers to the ground truth data generated manually by domain annotators / annotation systems for the microfluidic chip image to be inspected according to preset annotation specifications, including key information such as the location and type of defects). Area surveillance mask The generation process is as follows Figure 7As shown, firstly, the original target bounding box (the labeled bounding rectangle of the defect, used to divide the positive and negative sample regions) is used as input. The target region is spatially expanded according to actual supervision needs to appropriately increase the coverage of the defect-related region. Based on this, a binary mask can be generated to distinguish the defect-related region from the irrelevant background region. Alternatively, a continuous value mask can be generated through Gaussian mapping, giving higher response weights (weights refer to the supervision intensity value of each spatial location in the continuous value mask generated by Gaussian mapping) to locations near the target center and relatively lower weights to edge regions, thus obtaining a smoother spatial supervision signal. Finally, depending on the implementation method, a region supervision mask in binary or continuous value form can be output. This is used for supervised learning of the regional response auxiliary branch; where detection regions located in defect-related regions or predefined valid interest regions are labeled as 1, and other detection regions are labeled as 0. Therefore, the supervised loss of the regional response auxiliary branch can be constructed as follows:
[0096] Where N is the total number of detection areas participating in regional auxiliary supervision; For the first The region supervision labels for each detection area. The aforementioned supervision loss is used to constrain the region response auxiliary branch to learn spatial response patterns related to real defects, enabling it to distinguish between high-interest regions and invalid background regions, thus providing a reliable basis for the region modulation of subsequent classification loss.
[0097] Based on the supervised learning of the auxiliary branch for the region response, the classification loss weights (i.e., region weight coefficients) are constructed using the dynamic region response results output by the auxiliary branch. This allows high-response regions to maintain high supervision intensity, while low-response regions are assigned relatively low classification loss weights, thereby reducing the interference of obviously invalid background regions on the classification optimization process. Preferably, the first... The region weight coefficient corresponding to each detection region It can be represented as:
[0098] in, This represents the basic retention weight, used to ensure that low-response regions still retain a certain loss contribution, avoiding the impact on training stability due to excessively low regional weight coefficients; This indicates stopping the gradient operation, used to truncate the gradient path of the classification loss back to the region response auxiliary branch via the region weight coefficients during the weighting of the classification loss. The introduction of a gradient-stopping operation during classification loss calculation has the core significance of cutting off the backpropagation of gradients from the detection branch to the region response auxiliary branch, ensuring that the region response auxiliary branch is only subject to the region supervision mask. Independent supervision is provided to decouple the detection task from the spatial constraint task, thereby avoiding the detection noise in the early stage of training from misleading the learning of the auxiliary branch.
[0099] Furthermore, the regional weighting coefficients After introducing classification loss, the first The region-assisted modulation classification loss for each detection region can be written as:
[0100] Therefore, the dynamic region weight coefficient only assists in modulating the classification loss of the detection region, while the asymmetric weighted penalty mechanism for hard negative samples remains the core of classification loss optimization.
[0101] To ensure the self-consistency of the dynamic region constraint auxiliary mechanism in its training logic, this invention explicitly stipulates that: the region response auxiliary branch, on the one hand, accepts the region supervision mask generated by the Ground Truth annotation information for supervised learning, and on the other hand, uses the region supervision loss... The parameters are updated; on the other hand, the dynamic region response results output are only used to construct auxiliary weights for the classification loss after the stopping gradient processing is performed. Thus, the learning of the region response auxiliary branch originates from independent region supervision signals, while the classification loss of the region response auxiliary branch is only modulated using the dynamic region response results. The two responsibilities are separated, thereby avoiding the training logic loop problem of "the current dynamic region response result directly determining the current region weight coefficient, multiplying it by the current classification loss, and then using this classification loss to update the same region response auxiliary branch in reverse." Based on this, the total loss function can be expressed as:
[0102] in, This is the weighting coefficient for the regional auxiliary loss, used to adjust the contribution ratio of the regional response auxiliary branch supervision term to the overall optimization objective. By setting this weighting coefficient, the strength of the dynamic regional constraint auxiliary mechanism can be flexibly controlled according to different dataset characteristics and background complexity.
[0103] It should be noted that the dynamic region constraint auxiliary mechanism is only an optional enhancement method of this invention. Its purpose is to further reduce the interference of complex background regions on classification training and improve the stability of the error sample identification and punishment process. The core of this invention is still to screen error samples such as high-confidence false detection samples and implement selective reinforcement punishment through asymmetric weighting, rather than simply relying on region response branches to improve detection performance.
[0104] S62, Training and Validating the Model: The preprocessed microfluidic chip defect dataset is input into the aforementioned improved target detection network for training. The preprocessing includes unifying the size and format of the original defect images, organizing and verifying the ground truth annotation information, dividing the training set and validation set, and generating a configuration file adapted to the target detection training.
[0105] The improved target detection network retains the original backbone feature extraction network, feature fusion network, and multi-scale detection head, while incorporating basic classification loss, hard negative sample mask, asymmetric hard negative sample penalty, and positive sample compensation.
[0106] The improved target detection network training process includes data input, feature extraction, feature fusion, detection head prediction, classification loss calculation, parameter backpropagation, and parameter update. Multiple rounds of iterative optimization are performed on various microfluidic chip image samples (a defect dataset including positive and negative samples), such as bubble residue, channel defects, chip alignment errors, contaminant introduction, and cracks, to finally obtain a target detection model suitable for detecting extremely fine defects in microfluidic chips.
[0107] It should be noted that the image sample is the collective term for all original images acquired by the microfluidic chip, including images with defects and images without defects in the background; the defective image is an image sample with imperfections such as residual bubbles, channel defects, cracks, and contaminants, and belongs to the positive sample subset of the defect dataset.
[0108] In some implementation examples, the improved object detection network can optionally set a region response auxiliary branch in the main feature layer of small objects, and construct a dynamic region constraint auxiliary mechanism by combining the region supervision mask generated by the Ground Truth annotation information, so as to further reduce the interference of invalid background regions on classification training and improve the stability of the error sample identification and punishment process under complex background conditions.
[0109] It should be noted that the regional response auxiliary branch and the dynamic regional constraint auxiliary mechanism are only optional enhancement methods and do not constitute a necessary limitation for the establishment of this invention.
[0110] For example: The experimental environment is configured as follows: Deep learning framework: The object detection framework based on Ultralytics YOLO is adopted and implemented in the PyTorch2.9.1+CUDA 13.0 (cu130) deep learning environment.
[0111] Programming language and compiler version: Python 3.12.10 Hardware acceleration: GPU: NVIDIA GeForce RTX 5070 Laptop GPU (8GB VRAM) cuDNN: 9.12.0 (GPU-accelerated deep neural network library for accelerating convolution operations) Development environment: PyCharm In the training process of the improved object detection network, the Ultralytics YOLO framework supports synchronous use of the validation set to evaluate the performance of the current improved object detection network during training mode. Specifically, after each round or stage of training, the detection performance of the improved object detection network is automatically statistically analyzed based on the validation set, and the optimal weight file (best.pt) of the improved object detection network is saved accordingly. The validation set is defined by the dataset configuration file (data.yaml) and describes the validation set path and various defect category information; the optimal weight file (best.pt) contains all the parameter information of the improved object detection network after training. The input image size is kept consistent with that of the training stage to ensure consistency in feature extraction and detection inference processes. During the validation process, the improved object detection network performs forward inference on the input image, outputting the category, location, and confidence information of each detected defect target, and automatically calculates core evaluation metrics such as precision, recall, and mean average precision (mAP) to measure the comprehensive performance of this method in the scenario of detecting extremely fine defects in microfluidic chips. Training and validation are performed within the same framework, which facilitates real-time monitoring of performance changes and automatic retention of optimal weights during the iterative improvement of the object detection network, and enhances the consistency and efficiency of the training and evaluation processes. Table 1 below compares the parameters of the improved object detection network, with the table corresponding to the baseline model of this invention. Figure 2 The best-performing single-stage object detection network (i.e., the improved object detection network) is the YOLOv12 or other equivalent versions.
[0112] Table 1 Parameter Comparison Table
[0113] As shown in the table above, compared to directly using a lightweight evolution of YOLOv8 as the improved object detection network, the accuracy of the baseline model in this invention, after introducing only hard negative sample penalty, increased from 81.8% to 87.1%, indicating that this mechanism has a strong inhibitory effect on high-confidence false positives. However, the recall rate decreased to 73.2%, indicating that simply strengthening the negative sample penalty weakens the response capability to real subtle defects to some extent. After introducing only positive sample compensation, the recall rate increased from 77.1% to 80.5%, and mAP50 and mAP50-95 also improved, indicating that this mechanism helps to enhance the object detection model's attention to real defect samples. Furthermore, when hard negative sample penalty and positive sample compensation are used in combination, the precision reaches 89.2% and the mAP50-95 is improved to 45.5%, which is the best overall performance. This indicates that the two mechanisms have a good synergistic effect: the former is mainly used to suppress high-confidence false detections in complex backgrounds, while the latter is used to alleviate the problem of decreased recall after strengthening negative sample constraints, thus achieving a good balance between false detection control and maintaining the response to real defects.
[0114] Example 2: An optimization method for the asymmetric hard negative sample penalty loss for detecting extremely subtle defects, based on Example 1: Hard negative sample trigger threshold Instead of always remaining fixed, an adaptive adjustment method can be used. The specific process of the adaptive adjustment method is as follows: First, set the initial trigger threshold. The initial trigger threshold can be set to 0.60, and its variation range is limited to [0.50, 0.70]. Subsequently, during training, the trigger threshold is dynamically updated based on the validation set performance to achieve a better balance between controlling the false positive rate and maintaining the recall rate. Specifically, let the first... The trigger threshold after one round of training is The corresponding validation set precision and recall are respectively and The equilibrium criterion is defined as follows:
[0115] in, For the first Improve the recall rate of the object detection network on the validation set after training rounds; For the first Improve the accuracy of the object detection network on the validation set after training rounds; The reference recall rate is the level of recall that the target detection network is expected to achieve. The reference accuracy is the level of accuracy that the target detection network is expected to achieve. This is a balancing factor used to adjust the relative weights of insufficient precision and decreased recall in triggering threshold updates.
[0116] It should be noted that the above balance decision formula indicates a balance criterion for measuring the direction of performance deviation in current improved target detection networks: when A larger value indicates a more pronounced decline in recall, suggesting that the range of hard negative samples may be too large and the trigger threshold too low; when When the threshold is small, it indicates that the current accuracy improvement is insufficient or false positive suppression is still inadequate, suggesting that the hard negative sample screening range may be too small or the trigger threshold may be too high; when When the threshold is close to zero, it indicates that there is a relative balance between false positive suppression and recall maintenance. Therefore, the function of this formula is to transform the qualitative basis mentioned above, which states that "too low a trigger threshold will affect recall, too high a trigger threshold will weaken false positive suppression, and a moderate trigger threshold is conducive to achieving a better balance," into a quantitative criterion that can be used to dynamically adjust the trigger threshold.
[0117] Based on the balance criterion, the trigger threshold is updated as follows:
[0118] in, For the first t The hard negative sample trigger threshold used during round training; This is the trigger threshold updated based on the current performance status and used for the next round of training. The threshold update step size is used to control the magnitude of each adjustment; and These are the lower and upper limits of the allowed change of the trigger threshold, respectively, to ensure that the trigger threshold is always within a reasonable range; To stabilize the trigger threshold, it is used to determine whether the current performance deviation has reached a level that requires adjustment of the trigger threshold. The threshold can be set based on the normal fluctuation range of precision and recall on the validation set. The setting principle is: when the performance change of the improved object detection network between adjacent training rounds is only a small fluctuation, the threshold is not updated; when the performance deviation exceeds the normal fluctuation range, the threshold is adjusted. In a preferred embodiment, the performance of the network in the first few training rounds can be statistically analyzed. The natural fluctuation range is considered, and a value slightly higher than this fluctuation range is selected as the range. .
[0119] It should be noted that the meaning of this update formula is: when When the current recall rate decline is more pronounced, increasing the trigger threshold can reduce the number of negative samples selected as hard negative samples, thereby alleviating the suppression of the response capability to true subtle defects by excessive negative sample penalty; when When this occurs, it indicates that the current accuracy improvement is insufficient or false positive suppression is still inadequate. In this case, lowering the trigger threshold expands the screening range of the hard negative sample mask, thereby enhancing the penalty for high-risk false positive negative samples; when This indicates that the current false positive suppression and recall maintenance are in a relatively stable equilibrium, therefore the trigger threshold should remain unchanged. The above presents a dynamic update rule for the hard negative sample trigger threshold, enabling the trigger threshold to adaptively adjust according to the current performance state of the improved target detection network.
[0120] Example 3: An optimization method for the asymmetric hard negative sample penalty loss for detecting extremely subtle defects, based on Example 1 or Example 2: The positive sample compensation coefficient can be adaptively adjusted based on the training status or validation performance, replacing the fixed value setting. The specific process of adaptive adjustment is as follows: First, an initial positive sample compensation coefficient is set, which can be a constant greater than 1, and the range of variation of the positive sample compensation coefficient is limited to [1, 1.80]. Subsequently, during the training process, the positive sample compensation coefficient is dynamically updated based on the performance of the validation set to achieve a better balance between controlling the false positive rate and maintaining the recall rate.
[0121] Specifically: Let the first The positive sample compensation coefficient after training rounds is The compensation criterion is defined as follows:
[0122] in, This is a balancing coefficient used to adjust the relative weights of decreased recall and insufficient precision in the positive sample compensation coefficient update.
[0123] It should be noted that the above compensation criterion formula indicates an adjustment basis for measuring whether the current improved target detection network's response capability to real defects is insufficient: when When the value is large, it indicates that the current decline in recall is more prominent, suggesting that the contribution of positive samples to the classification loss may be insufficient, and positive sample compensation needs to be enhanced; when When the value is small, it indicates that the current accuracy improvement is insufficient or false positive suppression is still inadequate, suggesting that it is not advisable to continue enhancing positive sample compensation at this time; when When the value is close to zero, it indicates that there is a relative balance between false detection suppression and the maintenance of the true defect response. Therefore, the function of this formula is to transform the qualitative basis mentioned above, which states that "excessive positive sample compensation will weaken the effect of false detection suppression, and moderate positive sample compensation is conducive to achieving a better balance," into a quantitative criterion that can be used to dynamically adjust the positive sample compensation coefficient.
[0124] Based on the compensation criterion, the compensation coefficient for positive samples is updated as follows:
[0125] in, For the first The positive sample compensation coefficient used during round training; These are the positive sample compensation coefficients updated based on the current performance status and used for the next round of training. The step size for updating the compensation coefficients for positive samples is used to control the magnitude of each adjustment; and These are the lower and upper limits of the allowable variation of the positive sample compensation coefficient, respectively, to ensure that the positive sample compensation coefficient is always within a reasonable range; To stabilize the determination of the compensation threshold, it is used to determine whether the current performance deviation has reached the point where the positive sample compensation coefficient needs to be adjusted. The settings can be based on the normal fluctuation range of precision and recall on the validation set. The setting principle is: when the performance change of the improved object detection network between adjacent training rounds is only a small fluctuation, the positive sample compensation coefficient update is not triggered; only when the performance deviation exceeds the normal fluctuation range is the positive sample compensation coefficient adjustment triggered. In a preferred embodiment, the performance of the network in the first few training rounds can be statistically analyzed first. The natural fluctuation range is considered, and a value slightly higher than this fluctuation range is selected as the range. .
[0126] It should be noted that the meaning of this update formula is: when When the current recall rate decline is more pronounced, increasing the positive sample compensation coefficient can enhance the contribution of positive samples to the classification loss, thereby compensating for the weakening of the true defective response caused by the reinforcement penalty for high-risk negative samples; when When this occurs, it indicates that the current accuracy improvement is insufficient or false detection suppression is still inadequate. In this case, reducing the positive sample compensation coefficient can prevent over-compensation of positive samples, thereby maintaining the constraint strength of negative samples. This indicates that the current false positive suppression and recall maintenance are in a relatively stable equilibrium, therefore the positive sample compensation coefficient should be kept unchanged. The above provides a dynamic update rule for the positive sample compensation coefficient, enabling it to adaptively adjust according to the current performance state of the improved target detection network.
[0127] Example 4: An optimization method for the asymmetric hard negative sample penalty loss for detecting extremely subtle defects, based on Example 1, Example 2, or Example 3: It can also be adaptively adjusted based on the training epochs, predicted probability distribution, or validation performance to replace the fixed value setting. The specific process of adaptive adjustment is as follows: First, set the initial hard negative sample penalty coefficient, which can be set to 1.00, and limit the variation range of the hard negative sample penalty coefficient to [1.00, 2.00]. It should be noted that, due to the asymmetric weighting of the hard negative sample penalty in this invention... Therefore when When the hard negative samples selected by the hard_neg mask are selected, the asymmetric weighted penalty weight is: To ensure that hard negative samples always meet the additional penalty requirement of 2 times or more compared to ordinary negative samples, the following should be satisfied: Subsequently, during training, the penalty coefficient for hard negative samples is dynamically updated based on the validation set performance to achieve a better balance between controlling the false positive rate and maintaining the recall rate. Specifically, let the... The hard negative sample penalty coefficient after one round of training is The penalty adjustment criterion is defined as follows:
[0128] in, and This is a balancing coefficient used to adjust the relative weights of insufficient precision and decreased recall in the update of the hard negative sample penalty coefficient.
[0129] It should be noted that the above penalty adjustment criterion formula indicates an adjustment basis for measuring the strength of the current improved object detection network's need for hard negative sample suppression: when When the value is large, it indicates that the current accuracy improvement is insufficient, suggesting that the penalty for hard negative samples may be inadequate, and it is necessary to strengthen the additional penalty for hard negative samples; when When the value is small, it indicates that the current decline in recall is more pronounced, suggesting that it is not advisable to further increase the penalty for hard negative samples at this time; when When the value is close to zero, it indicates that there is a relative balance between false detection suppression and the maintenance of the response to true defects. Therefore, the function of this formula is to transform the qualitative basis mentioned above, which states that "too small an additional penalty coefficient will weaken false detection suppression, too large an additional penalty coefficient will affect recall, and a moderate additional penalty coefficient is conducive to achieving a better balance," into a quantitative criterion that can be used to dynamically adjust the additional penalty coefficient for hard negative samples.
[0130] Based on the penalty adjustment criterion, the penalty coefficient for hard negative samples is updated as follows:
[0131] in, For the first The hard negative samples used in each round of training are subject to additional penalty coefficients; The penalty coefficient is added to the hard negative samples used for the next round of training after updating according to the current performance status; v is the update step size of the hard negative sample penalty coefficient, which is used to control the magnitude of each adjustment; and These are the lower and upper limits of the allowable variation of the penalty coefficient for hard negative samples, used to ensure that the penalty coefficient for hard negative samples is always within a reasonable range; To stabilize the determination of the penalty threshold, it is used to determine whether the current performance deviation has reached the point where the additional penalty coefficient for hard negative samples needs to be adjusted. The settings can be based on the normal fluctuation range of precision and recall on the validation set. The setting principle is: when the performance change of the improved object detection network between adjacent training rounds is only a small fluctuation, the hard negative sample penalty coefficient update is not triggered; only when the performance deviation exceeds the normal fluctuation range is the hard negative sample penalty coefficient adjustment triggered. In a preferred embodiment, the performance of the network in the first few training rounds can be statistically analyzed first. The natural fluctuation range is considered, and a value slightly higher than this fluctuation range is selected as the range. .
[0132] It should be noted that the meaning of this update formula is: when When this occurs, it indicates that the current accuracy improvement is insufficient. In this case, increasing the penalty coefficient for hard negative samples enhances the penalty for hard negative samples, thereby further suppressing high-confidence false detections in complex backgrounds. When the recall rate decline is more pronounced, the excessive negative sample penalty can be reduced to alleviate the suppression of the response capability to real subtle defects. However, the reduced negative sample penalty coefficient should still not be lower than 1.00 to ensure that the selected negative samples always maintain a penalty intensity of 2 times or more. This indicates that the current false positive suppression and recall maintenance are in a relatively stable equilibrium, therefore the hard negative sample penalty coefficient should be kept unchanged. The above provides a dynamic update rule for the hard negative sample penalty coefficient, enabling it to adaptively adjust according to the current performance state of the improved target detection network.
[0133] Example 5: An electronic device includes a processor and a memory, the memory storing a computer program that, when executed by the processor, implements the method described above.
[0134] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method.
[0135] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined according to the scope of the claims.
Claims
1. A method for optimizing asymmetric hard negative sample penalty loss for detecting extremely subtle defects, characterized in that, Includes the following steps: Step 1: Based on the single-stage target detection network, an improved target detection network for detecting extremely subtle defects outputs the classification prediction values for each detection region, thus obtaining the defect classification prediction probability. ; Step 2: Predict the probability based on the actual labels and defect classifications of each detection area. Construct a basic binary cross-entropy classification loss; Step 3: Filter the defect classification prediction probability Higher than the preset trigger threshold For detection regions where the true label is a negative sample, a hard negative sample mask is generated. ; Step four, apply the hard negative sample mask... The hard negative samples obtained through screening represent the negative sample loss in the basic binary cross-entropy classification loss. By introducing asymmetric weighted penalties, an improved negative sample loss is obtained. ; Step 5: Positive Sample Loss in Basic Binary Cross-Entropy Classification Loss By introducing positive sample compensation, we obtain the improved positive sample loss. ; Step 6: Apply the main classification loss after introducing asymmetric weighted penalties and positive sample compensation. The improved target detection network is iteratively trained to obtain a target detection model suitable for detecting extremely subtle defects.
2. The asymmetric hard negative sample penalty loss optimization method for detecting extremely subtle defects according to claim 1, characterized in that, In step four, the asymmetric weighted penalty is to apply a higher asymmetric weighted penalty weight to the hard negative sample than to the ordinary negative sample. and based on The improved negative sample loss is obtained. : in, For the first The hard negative sample mask value corresponding to each detection area; Add a penalty coefficient to hard negative samples.
3. The asymmetric hard negative sample penalty loss optimization method for detecting extremely subtle defects according to claim 1, characterized in that, In step five, the positive sample compensation is to apply a positive sample compensation coefficient to the positive samples. and based on The improved positive sample loss is obtained. : 。 4. The asymmetric hard negative sample penalty loss optimization method for detecting extremely subtle defects according to claim 1, characterized in that, In step six, the main classification loss for: Where N is the number of detection areas.
5. The method for optimizing asymmetric hard negative sample penalty loss for detecting extremely subtle defects according to claim 1, characterized in that, In step three, the hard negative sample mask for: in, For the first The true classification label of each detection area, among which When, it indicates a positive sample; when When the value is 0, it indicates that the detection area is either background or a negative sample.
6. The asymmetric hard negative sample penalty loss optimization method for detecting extremely subtle defects according to claim 1, characterized in that, The trigger threshold The range of values is ; The trigger threshold of the hard negative sample The adaptive adjustment method is as follows: Set the initial value of the trigger threshold. ; During the training process of the improved object detection network, let the first... The trigger threshold after one round of training is The corresponding validation set precision and recall are respectively and The equilibrium criterion is defined as follows: in, For reference recall rate; For reference accuracy; This is the balance coefficient; Based on the aforementioned balance criterion, the trigger threshold is updated as follows: in, This is the trigger threshold updated based on the current performance status and used for the next round of training. To trigger the threshold update step size; and These are the lower and upper limits of the trigger threshold, respectively. To ensure stable determination of the trigger threshold.
7. The asymmetric hard negative sample penalty loss optimization method for detecting extremely subtle defects according to claim 1, characterized in that, The improved target detection network includes a backbone feature extraction network, a feature fusion network, and a multi-scale detection head, which are used to jointly represent and predict defect targets of different scales in the input image. The improved target detection network also includes a regional response auxiliary branch; The regional response auxiliary branch outputs a regional response probability map, and regional weights are generated based on the regional response probability map. : in, Retain weights based on the baseline; To stop the gradient operation; For the first Predicted regional response values corresponding to each detection area; based on The main classification loss is modulated to obtain the first... Region-assisted modulation classification loss in each detection area : Total loss function for: in, For regional auxiliary loss weighting coefficients; The supervisory loss for the regional response auxiliary branch.
8. The asymmetric hard negative sample penalty loss optimization method for detecting extremely subtle defects according to claim 7, characterized in that, The supervisory loss of the regional response auxiliary branch for: Where N is the total number of detection areas participating in regional auxiliary supervision; For the first Regional supervision labels for each detection area.
9. An electronic device, characterized in that, It includes a processor and a memory, wherein the memory stores a computer program that, when executed by the processor, implements the method as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 8.