A detection and identification method, system and device for unbalanced samples
By employing a two-stage training method and a low-rank gating adapter, the problem of the difficulty in incorporating a very small number of sample categories into the recognition model is solved. This approach achieves the protection of stable class boundaries and the effective incorporation of micro-sample categories, thereby improving the stability and accuracy of the recognition system.
Patent Information
- Application Number
- CN202611628719.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-21
- Publication Date
- 2026-11-20
AI Technical Summary
In applications such as image recognition and medical image classification, existing technologies struggle to effectively incorporate categories from a small number of samples, leading to misjudgments in the recognition model or the need for retraining. Furthermore, existing methods may introduce boundary variance or compress the representation space of stable categories when dealing with extremely small sample sizes.
A two-stage training method is adopted. First, the backbone network is trained using stable class data to form a stable class feature distribution and an inter-class ambiguity buffer. Then, a low-rank gating adapter is attached to the optimal attachment layer to deform and transfer the features of the micro-sample class to the target subspace, ensuring that the stable class boundary is not destroyed.
Without disrupting stable class boundaries, it successfully incorporates micro-sample categories, reducing the number of training parameters and improving the stability and accuracy of the recognition system, while avoiding overfitting.
Smart Images

Figure CN123139040A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of deep learning pattern recognition technology, specifically relating to a detection and recognition method, system, and device for imbalanced samples. Background Technology
[0002] In open-environment applications such as image recognition, defect detection, and medical image classification, recognition models often face several challenges. For example, the known category distribution exhibits a long-tailed pattern, with most categories having only a very small number of labeled samples; and entirely new categories that were not fully explored during the training phase may still emerge during the deployment stage.
[0003] Currently, long-tail learning is employed to mitigate head class bias through methods such as resampling training data, reweighting loss functions, decoupling training, and feature enhancement. For example, prototype decoupling contrastive learning prevents bias optimization between intra-class samples, or a dual-branch decoupling classifier combined with epoch-cumulative learning dynamically adjusts classifier weights to strengthen tail class representation learning. However, these methods require a certain number of training samples for the tail classes. When some classes have only a very small number of samples, such as 5-20, directly including them in training can introduce large boundary variance and may squeeze the representation space of classes with sufficient samples.
[0004] Existing methods include rejection strategies that combine OpenMax with Weibull distribution tail fitting. These methods mainly address the rejection problem, where when a small number of newly labeled categories appear, they cannot be stably incorporated into the recognition system. They either continue to classify these categories as unknown, thus missing the opportunity to incorporate them, or require retraining the entire model. Summary of the Invention
[0005] This invention provides a detection and identification method for imbalanced samples. By estimating the inter-class ambiguity buffer and selecting the optimal mounting layer to mount a lightweight adapter, the absorption of micro-sample classes is transformed into a constrained feature space migration problem. This method achieves stable absorption of micro-sample classes and effective rejection of unknown classes while protecting the boundaries of stable classes.
[0006] The methods include: S1. Obtain training data, which includes stable class data and micro sample class data. The stable class data is known class data with a sample number that meets a preset quantity threshold. The micro sample class data is class data to be absorbed with a sample number that is lower than the preset quantity threshold. S2. The initial neural network is trained in the first stage using only the stable class data to obtain the stable class backbone network. The stable class backbone network is used to form and determine the stable class feature distribution of each stable class in the stable class data in the feature space, and the classification confidence of each stable class is output. S3. Based on the stable class feature distribution of each stable class, determine the inter-class ambiguity buffer zone between different stable classes. The inter-class ambiguity buffer zone includes the overlapping region of the stable class feature distribution and the low confidence boundary region where the classification interval is less than a preset interval threshold. The inter-class ambiguity buffer zone is used to provide a distinguishable spatial boundary for the micro-sample class data and the unknown class. S4. After completing the first stage of training, proceed to the second stage of training: For each micro-sample category, evaluate the intra-class dispersion, overlap with the inter-class ambiguity buffer and the stable class feature distribution, and separability after propagation through subsequent network layers in multiple intermediate layers of the stable class backbone network, and select the optimal mounting layer from the multiple intermediate layers based on the evaluation results. S5. In the second stage of training, a low-rank gating adapter is attached to the micro-sample category at the optimal attachment layer. The low-rank gating adapter performs feature deformation on the samples falling into the local subspace of the micro-sample category, and maps the deformed features to the reserved target subspace through the final feature transfer head, thereby completing the attachment of the micro-sample category.
[0007] According to another embodiment of this application, a detection and identification system for imbalanced samples is provided, the system comprising: The data acquisition module is used to acquire training data, which includes stable class data and micro sample class data. The stable class data is known class data whose sample number meets a preset number threshold, and the micro sample class data is class data to be absorbed whose sample number is lower than the preset number threshold. The first-stage training module is used to train the initial neural network using only the stable class data to obtain a stable class backbone network. The stable class backbone network is used to form and determine the stable class feature distribution of each stable class in the stable class data in the feature space, and output the classification confidence of each stable class. The buffer band determination module is used to determine the inter-class ambiguity buffer band between different stable categories based on the stable class feature distribution of each stable category. The inter-class ambiguity buffer band includes the overlapping region of the stable class feature distribution and the low confidence boundary region where the classification interval is less than a preset interval threshold. The inter-class ambiguity buffer band is used to provide a distinguishable spatial boundary for the micro-sample class data and the unknown class. The mounting layer selection module is used to enter the second stage of training after the first stage of training is completed. For each micro-sample category, it evaluates the intra-class dispersion, the overlap with the inter-class ambiguity buffer and the stable class feature distribution, and the separability after propagation through subsequent network layers in multiple intermediate layers of the stable class backbone network. Based on the evaluation results, it selects the optimal mounting layer from the multiple intermediate layers. The mounting module is used in the second stage of training to mount a low-rank gating adapter for the micro-sample category at the optimal mounting layer. The low-rank gating adapter performs feature deformation on samples falling into the local subspace of the micro-sample category and maps the deformed features to the reserved target subspace through the final feature transfer head, thereby completing the mounting of the micro-sample category.
[0008] According to another embodiment of this application, an electronic device is also provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method for detecting and identifying imbalanced samples.
[0009] As can be seen from the above technical solutions, the present invention has the following advantages: This invention employs a two-stage training approach: the first stage trains the backbone network using only stable class data with sufficient samples, avoiding gradient noise from micro-sample class data that could interfere with the formation of stable class feature distributions; the second stage attaches low-rank gating adapters to micro-sample classes at the optimal mounting layer, and maps them to a reserved target subspace through the final feature transfer head. Compared to directly training with all classes mixed together, this invention can incorporate micro-sample classes into the recognition system without disrupting the existing boundaries of stable classes.
[0010] This invention determines an inter-class ambiguity buffer zone based on the stable class feature distribution, including overlapping regions of feature distributions and low-confidence boundary regions where the classification interval is less than a preset threshold. This buffer zone serves as a spatial avoidance constraint when selecting subsequent micro-sample category mounting layers and a forbidden zone reference when allocating target subspaces, ensuring that feature migration of micro-sample categories does not intrude into the already ambiguous spatial regions between stable categories. In multiple intermediate layers of the stable class backbone network, this invention evaluates the intra-class dispersion, overlap with the inter-class ambiguity buffer zone and the stable class feature distribution, and separability after propagation through subsequent network layers for each micro-sample category. The optimal mounting layer is selected based on the comprehensive evaluation results. This ensures that each micro-sample category is mounted in the network layer that best separates it from the stable class, while also considering the feature quality of the current layer.
[0011] This invention mounts a low-rank gated adapter on the optimal mounting layer. Through a gating mechanism, the deformation intensity is dynamically adjusted based on the spatial distance from sample features to the micro-sample class prototype. Typical samples closer to the prototype receive larger deformations to optimize feature representation, while edge samples farther from the prototype receive smaller deformations. The low-rank structure significantly reduces the number of trainable parameters, enabling the adapter to converge stably without overfitting even with only a very small number of training samples. Attached Figure Description
[0012] To more clearly illustrate the technical solution of the present invention, the accompanying drawings used in the description will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 The flowchart shows a method for detecting and identifying imbalanced samples. Figure 2 A schematic diagram of a stable backbone network configuration; Figure 3 A flowchart illustrating an embodiment of a detection and identification method for imbalanced samples; Figure 4 This is a schematic diagram of a detection and identification system for imbalanced samples. Figure 5 This is a schematic diagram of an electronic device. Detailed Implementation
[0014] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0015] It should be noted that stable class data refers to known class data with a sample size that meets a preset threshold, such as class data containing no fewer than 50 labeled samples per class. In this invention, stable class data is the sole input for the first stage of training, used to train the backbone network and form a reliable known class feature space.
[0016] Micro-sample data refers to category data with a sample size below a preset threshold, such as category data containing only 5 to 20 labeled samples per category. In this invention, micro-sample data does not participate in the first-stage backbone network training, but is gradually incorporated into the recognition system in the second stage by attaching a lightweight adapter. By not participating in the first-stage training, micro-sample data avoids disrupting the established stable class boundaries.
[0017] The initial neural network is the network structure that has not been trained before the start of the first training phase. It is used to extract features from the input image data. The initial neural network is the starting point for the first training phase, with parameters randomly initialized or initialized using pre-trained weights. In the first phase, the initial neural network is jointly trained using four-loss methods on stable class data, optimizing it into a stable backbone network. The structural design of the initial neural network determines the hierarchical abstraction capability of feature extraction and the output dimension of the classifier, serving as the carrier for all subsequent feature operations.
[0018] The initial neural network can be, for example, an EfficientNetB0 network, which includes a convolutional stem (Stem), multiple moving inverted bottleneck convolutional modules (MBConv), and a fully connected classification layer connected in sequence. Its parameter size is relatively small, making it suitable for training scenarios with limited sample sizes. Alternatively, the initial neural network can also be a visual transducer (ViT) network based on a self-attention mechanism. This network divides the input image into multiple image patches and learns the global dependencies between these patches through multi-head self-attention layers to extract global features of the image. It is understood that those skilled in the art can also choose other convolutional neural networks or Transformer architectures with similar functions as the initial neural network according to actual application needs; this application does not specifically limit this choice.
[0019] The stable class backbone network is a neural network obtained after completing the first stage of training using only stable class data. Its parameters are frozen or weakly updated during the second stage of training. In this invention, the stable class backbone network is the core skeleton of the entire method, responsible for extracting features from the samples to be identified, outputting stable class classification confidence scores, and providing mounting locations for the micro-sample class adapters. The stable class backbone network forms a reliable stable class feature distribution in the feature space, and parameter freezing ensures that the micro-sample class mounting in the second stage does not disrupt the established stable class boundaries, thus decoupling stable class identification from micro-sample class assimilation.
[0020] The feature space refers to the high-dimensional semantic space spanned by the output features of the feature extraction layers of the stable class backbone network, where samples are represented as feature vectors. In this invention, the feature space serves as the unified stage for all class distributions, buffer band delineation, subspace mounting, and inference matching. Stable class feature distributions, inter-class ambiguity buffer bands, and micro-sample class target subspaces are all defined and manipulated within the feature space. The goal of the first stage of four-loss joint training is to construct a feature space that is compact within classes, separable between classes, and has calibrable confidence.
[0021] The stable class feature distribution refers to the feature region of each stable class in the feature space, obtained by statistically analyzing the final features of all stable class samples under that class, including three elements: feature mean, covariance matrix, and coverage radius. In this invention, the stable class feature distribution describes the position, shape, and extent of each stable class in the feature space in the form of an elliptical region. The stable class feature distribution is the basis for delineating inter-class ambiguity buffer zones and a reference for evaluating the overlap between micro-sample classes and stable classes, serving as the basis for Mahalanobis distance calculation during the inference stage. The stable class feature distribution transforms discrete sample features into continuous region descriptions, elevating the analysis and manipulation of inter-class relationships from the sample level to the distribution level.
[0022] Classification confidence refers to the numerical value output by the classifier based on the features of the input sample, representing the degree of certainty that the sample belongs to each stable category. It is obtained by normalizing the original predicted score using softmax or transforming it using an energy function. In this invention, classification confidence is the basis for the first-level determination in the inference stage. When the maximum classification confidence of the sample to be identified is higher than a preset confidence threshold, it is directly determined to be a stable class; otherwise, it enters the micro-sample class matching stage. The classification confidence is calibrable thanks to the energy calibration loss in the first-stage training, ensuring high confidence for stable class samples and low confidence for unstable class samples, thus providing a reliable thresholding basis for cascaded determination.
[0023] The inter-class ambiguity buffer zone refers to the region in the feature space where there is high classification uncertainty between adjacent stable classes. It is composed of two parts: the overlapping region of stable class feature distributions and the low-confidence boundary region where the classification interval is less than a preset interval threshold. In this invention, the inter-class ambiguity buffer zone is not simply regarded as a classification error and ignored, but rather modeled as a spatial resource that provides a distinguishable spatial boundary between micro-sample classes and unknown classes. The inter-class ambiguity buffer zone serves as a reference for overlap assessment when selecting the micro-sample class mounting layer and as an avoidance basis when allocating the target subspace. This ensures that the mounting and migration of micro-sample classes are constrained by the spatial structure of stable classes throughout the entire process, guaranteeing that micro-sample classes do not fall into the ambiguity region of stable classes.
[0024] The overlapping region refers to the intersection of the stable class feature distributions of two stable classes in the feature space, i.e., the area where the two elliptical regions overlap. In this invention, the overlapping region is determined by solving the intersection point of the elliptical boundary equations of the two stable class feature distributions simultaneously, and it is the first component of the inter-class ambiguity buffer zone. Samples within the overlapping region are close to the distribution centers of both stable classes, making it difficult for the classifier to reliably distinguish them. The area ratio of the overlapping region is an important indicator for prioritizing the inter-class ambiguity buffer zone; a larger area indicates a more severe entanglement between the two class distributions, and micro-samples should be prioritized for avoidance.
[0025] The low-confidence boundary region refers to the area in the feature space where the logit difference between two stable classes is less than a preset threshold, i.e., the area near the classifier's decision boundary where classification uncertainty is high. In this invention, the low-confidence boundary region is determined by statistically analyzing the logit difference between samples of each stable class and the two classes, and it is the second component of the inter-class ambiguity buffer zone. The low-confidence boundary region complements the overlapping region, covering the boundary area where the distributions do not overlap but the classifier is still uncertain. The average classification interval of the low-confidence boundary region is another indicator for prioritizing the inter-class ambiguity buffer zone; the smaller the interval, the more ambiguous the classifier's decision boundary, and the more the micro-sample class target subspace needs to avoid this region.
[0026] Spatial boundaries refer to the regional division function of the inter-class ambiguity buffer in the feature space, dividing the feature space into a stable class reliable identification area, an inter-class ambiguity area, and a safe area that can be used for micro-sample class mounting. In this invention, the spatial boundary is a functional attribute of the inter-class ambiguity buffer, rather than an independent physical entity. The inter-class ambiguity buffer provides distinguishable spatial boundaries for micro-sample class data and unknown classes by marking overlapping areas and low-confidence boundary areas: the target subspace of micro-sample classes is allocated to the safe area outside the buffer, while unknown class samples fall into the open space outside the buffer because they do not meet the stable class confidence and micro-sample class matching scores during the inference stage, and are ultimately rejected. Spatial boundaries ensure that stable classes, micro-sample classes, and unknown classes each occupy their respective positions in the same feature space without interfering with each other.
[0027] Please see Figure 1 The diagram shows a flowchart of a method for detecting and identifying imbalanced samples in a specific embodiment. The method includes: S1. Obtain training data, which includes stable class data and micro sample class data. The stable class data is known class data with a sample number that meets a preset quantity threshold. The micro sample class data is class data to be absorbed with a sample number that is lower than the preset quantity threshold. S2. The initial neural network is trained in the first stage using only the stable class data to obtain the stable class backbone network. The stable class backbone network is used to form and determine the stable class feature distribution of each stable class in the stable class data in the feature space, and the classification confidence of each stable class is output.
[0028] like Figure 2 As shown below, the specific implementation method of joint optimization of four types of losses in the first stage of training will be described in detail.
[0029] Acquire training data, which includes stable class data and micro-sample class data. Stable class data consists of known class data with a sample size that meets a preset threshold, such as classes with at least 50 samples per class. Micro-sample class data consists of class data to be included, with a sample size below the preset threshold, such as classes with 5 to 20 samples per class. The first phase of training uses only stable class data; micro-sample class data is not included in the first phase of training.
[0030] An initial neural network is constructed, consisting of a feature extraction layer, multiple intermediate layers, and a classifier. The feature extraction layer employs a multi-level convolutional unit cascaded structure, with each convolutional unit containing a convolutional layer, a batch normalization layer, and a non-linear activation function. The classifier uses fully connected layers to map the high-dimensional features output by the feature extraction layer to the stable class dimension. Stable class samples from the stable class data are input into the initial neural network in batches according to a preset batch size. The feature extraction layer performs layer-by-layer convolutions and non-linear transformations on each stable class sample, outputting the initial features for each stable class sample. These initial features are then fed into the classifier to obtain the raw predicted scores for each stable class sample corresponding to its respective stable class.
[0031] In the first phase of training, four types of losses are calculated simultaneously and the network parameters of the initial neural network are jointly optimized.
[0032] The first type of loss is the cross-entropy loss. For each stable class sample, the original predicted score output by the classifier is normalized using a softmax function to obtain the class probability distribution. This class probability distribution is then compared with the true class label of the stable class sample to calculate the cross-entropy loss. The cross-entropy loss constrains the classifier to output the correct class label for each stable class sample, driving the initial neural network to learn the global classification boundary of the stable class.
[0033] The second type of loss is supervised contrastive loss. Within each training batch, features from samples of the same stable class are used as positive sample pairs, and features from samples of different stable classes are used as negative sample pairs to calculate the supervised contrastive loss. Supervised contrastive loss brings the initial features of samples of the same stable class closer together and pushes the initial features of samples of different stable classes further apart in the feature space, causing similar samples to cluster together and dissimilar samples to separate in the feature space. Supervised contrastive loss compensates for the deficiency of cross-entropy loss, which only focuses on classification boundaries and not intra-class structure, thus enhancing inter-class separability at the feature structure level.
[0034] The third type of loss is the intra-class compactness loss. For each stable class, the covariance matrix of the initial features of all stable class samples under that class is calculated. The trace of the covariance matrix is taken as the intra-class dispersion measure, and the intra-class dispersion is used as the intra-class compactness loss. The intra-class compactness loss compresses the distribution variance of the initial features under each stable class, making the feature regions of each stable class more compact, reducing the overlap between the feature distributions of different stable classes, and providing a distribution basis for the accurate delineation of the inter-class ambiguity buffer zone.
[0035] The fourth type of loss is the energy calibration loss. Based on the original predicted scores output by the classifier, the energy score of each stable class sample is calculated using an energy function, which converts the log-likelihood of the original predicted scores into energy values. The energy calibration loss adjusts the energy scores of each stable class sample, ensuring that the energy scores of stable class samples are below a preset energy threshold, while simultaneously increasing the energy scores of samples far from the stable class feature distribution. The energy calibration loss provides a calibrable confidence benchmark for open set rejection, making stable class samples and unstable class samples exhibit separable statistical differences in the energy dimension.
[0036] The total training loss is obtained by summing the cross-entropy loss, supervised contrast loss, intra-class compactness loss, and energy calibration loss according to preset weights. The preset weights are set according to the number of classes and sample distribution of the stable class data. The weight of cross-entropy loss is set to 1.0, the weight of supervised contrast loss is set to 0.1 to 1.0, the weight of intra-class compactness loss is set to 0.01 to 0.1, and the weight of energy calibration loss is set to 0.1 to 1.0.
[0037] In one specific embodiment, the weights of the cross-entropy loss and the supervised contrast loss are set to 1.0, 0.5, 0.05, and 0.5 respectively. In another specific embodiment, when the number of stable classes is large (e.g., more than 20 classes), the weights of the supervised contrast loss and the intra-class compactness loss are set to 0.8, 0.1, and 0.3 respectively, to enhance inter-class separability. In yet another specific embodiment, when the number of stable classes is small (e.g., less than 10 classes), the weights of the supervised contrast loss and the intra-class compactness loss are set to 0.3, 0.02, and 0.8 respectively.
[0038] Backpropagation is performed on all network parameters of the initial neural network based on the total training loss. The gradient of each network parameter is calculated, and the network parameters are updated according to the gradient and the preset learning rate. The forward propagation, loss calculation, and backpropagation update are repeated until the change in the total training loss is lower than the preset convergence threshold. The initial neural network corresponding to the current network parameters is then determined as the stable backbone network.
[0039] After training, the stable class backbone network forms a stable class feature distribution corresponding to each stable class in the feature space, and the classifier outputs the classification confidence score for each stable class. The stable class feature distribution and classification confidence score are used to define the inter-class ambiguity buffer and to determine the stable class of the sample to be identified during the inference stage.
[0040] S3. Based on the stable class feature distribution of each stable class, determine the inter-class ambiguity buffer zone between different stable classes. The inter-class ambiguity buffer zone includes the overlapping region of the stable class feature distribution and the low confidence boundary region where the classification interval is less than a preset interval threshold. The inter-class ambiguity buffer zone is used to provide a distinguishable spatial boundary for the micro-sample class data and the unknown class. S4. After completing the first stage of training, proceed to the second stage of training: For each micro-sample category, evaluate the intra-class dispersion, overlap with the inter-class ambiguity buffer and the stable class feature distribution, and separability after propagation through subsequent network layers in multiple intermediate layers of the stable class backbone network, and select the optimal mounting layer from the multiple intermediate layers based on the evaluation results. S5. In the second stage of training, a low-rank gating adapter is attached to the micro-sample category at the optimal attachment layer. The low-rank gating adapter performs feature deformation on the samples falling into the local subspace of the micro-sample category, and maps the deformed features to the reserved target subspace through the final feature transfer head, thereby completing the attachment of the micro-sample category. In some embodiments, step S5 further includes a three-level determination during its implementation: The first level of determination is the stable class determination. The sample to be identified is input into the stable class backbone network, and the classifier outputs the classification confidence score of the sample corresponding to each stable class. If the maximum classification confidence score is higher than the preset confidence score threshold, the sample to be identified is determined to belong to the stable class corresponding to the maximum confidence score, and the inference ends.
[0041] The second level of determination involves micro-sample class matching. If the first level of determination fails (i.e., the maximum classification confidence is not higher than a preset confidence threshold), then for each attached micro-sample class, the features of the sample to be identified are captured at the corresponding optimal attachment layer. These features are then deformed using a low-rank gating adapter for that micro-sample class, and finally mapped to the target subspace of that micro-sample class via a final feature transfer head. The distance between the deformed feature and the center of the target subspace of that micro-sample class is calculated, and the inverse of this distance is normalized to obtain the matching score. If the maximum matching score is higher than a preset matching threshold, the sample to be identified is determined to belong to the micro-sample class corresponding to the maximum matching score, and the inference process ends.
[0042] The third level of determination identifies the sample as belonging to an unknown class. If the second level of determination fails (i.e., the maximum matching score is not higher than the preset matching threshold), the buffer zone index table established in step S3 is queried to determine whether the features of the sample to be identified fall within any inter-class ambiguity buffer zone. If it falls within a buffer zone, the sample to be identified is determined to be of an unknown class, an unknown class identifier is output, and the features of the sample to be identified are stored in the sample pool to be attached, for subsequent annotation and a new round of micro-sample class attachment. If it does not fall within any buffer zone, it is also determined to be of an unknown class.
[0043] In one exemplary embodiment, based on step S3, the following will provide a possible embodiment and describe its specific implementation in a non-limiting manner.
[0044] S31: Iterate through all pairwise combinations in all K stable categories.
[0045] For each pair of stable classes, denoted as class i and class j, obtain the feature mean and covariance matrix Sigma of class i. i and coverage radius r i , and the feature mean mu of class j j Covariance matrix Sigma j and coverage radius r j .
[0046] Based on the joint distribution model of class i and class j, the Mahalanobis overlap probability between them is calculated as follows: Within the union coverage area of the feature distributions of class i and class j, a set of sampling points is uniformly sampled in the feature space with a preset step size. For each sampling point, the Mahalanobis distance to the mean of the feature of class i and the Mahalanobis distance to the mean of the feature of class j are calculated. If the Mahalanobis distance of a sampling point to both class means is less than a preset multiple of their respective coverage radii, the sampling point is marked as an overlapping sampling point. The proportion of the number of overlapping sampling points to the total number of sampling points is counted, and this proportion is used as the Mahalanobis overlap probability between class i and class j. The set of overlapping sampling points between class pairs with a Mahalanobis overlap probability greater than a preset probability threshold is marked as the first type buffer sub-band, and the boundary coordinate set and spatial range of the first type buffer sub-band are recorded.
[0047] S32: Based on class i and class j, for each pair of stable classes, collect the final feature vector set and the corresponding original prediction score of all stable class samples under class i, and the final feature vector set and the corresponding original prediction score of all stable class samples under class j.
[0048] For each sample, the absolute value of the difference between its original predicted scores in class i and class j is calculated, and this absolute value is used as the classification margin label of the sample in the feature space. Using the final feature vector of all samples as the independent variable and the corresponding classification margin label as the dependent variable, a kernel regression method is used to fit an approximate distribution function of the classification margin in the feature space. This function can map any position in the feature space to a predicted classification margin value. Feature space regions in the approximate distribution function that are less than a preset margin threshold are marked as second-class buffer sub-bands, and the boundary coordinate set and spatial range of the second-class buffer sub-bands are recorded.
[0049] S33: Based on each pair of stable categories, take the union of the sampling point set of the first type of buffer sub-band obtained in S31 and the region of the second type of buffer sub-band obtained in S32, and then merge them to obtain the inter-class ambiguity buffer band between the i-th and j-th categories.
[0050] Calculate the area ratio of the overlapping region of the class pair, where the area ratio is the proportion of the number of overlapping sampling points to the total number of sampling points within the coverage area of the two stable class distributions. Calculate the average classification interval of the class pair, where the average classification interval is the arithmetic mean of the logit differences of all samples under the class pair.
[0051] Priority is calculated based on area percentage and average classification interval. The priority calculation formula is: priority equals area percentage divided by (average classification interval plus a preset minimum). All inter-class ambiguity buffers are sorted from largest to smallest priority value, and the sorting results are written into the buffer index table.
[0052] Optionally, the priority calculation formula uses the area ratio as the numerator and the average classification margin as the denominator, so that class pairs that simultaneously possess both large area overlap and low classification margin characteristics receive the highest priority. These class pairs have the largest ambiguous regions between them, are the most difficult for the classifier to distinguish, and have the highest risk of misclassification if micro-samples are attached to these regions.
[0053] S34: Traverse all inter-class ambiguity buffers after sorting in S33, and create an index record for each inter-class ambiguity buffer. Each record contains five fields: The buffer zone index includes the buffer zone number, the corresponding stable category pair identifier, the set of boundary coordinates of the buffer zone in the feature space, the priority value of the buffer zone, and a description of the spatial range of the buffer zone. All index records are arranged in descending order of priority to form the buffer zone index table.
[0054] The buffer band index table is stored in read-only mode for subsequent steps to query and access. In step S4, when evaluating the overlap between micro-sample classes and inter-class ambiguity buffer bands, the buffer band index table is queried to obtain the set of boundary coordinates for each buffer band, and the proportion of micro-sample class samples falling within the buffer band is calculated.
[0055] In step S5, when allocating the target subspace, the buffer band index table is queried to obtain the spatial range of all buffer bands, and the candidate region of the target subspace is restricted to the feature space region that has no intersection with any buffer band.
[0056] In one exemplary embodiment, such as Figure 3 As shown, based on step S4, the following will provide a possible embodiment and describe its specific implementation in a non-limiting manner.
[0057] S411: For each micro-sample category, input all micro-sample class samples under the micro-sample category into the stable class backbone network. During the forward propagation of the stable class backbone network, extract the activation values of the micro-sample class samples at multiple preset intermediate layers, which are used as the inter-layer features of the micro-sample class samples in each intermediate layer.
[0058] For each intermediate layer, collect the inter-layer features of all micro-sample class samples under the micro-sample category in that layer, calculate the covariance matrix of these inter-layer features, and take the trace of the covariance matrix as the intra-class dispersion of the micro-sample category in the intermediate layer.
[0059] The trace of the covariance matrix is equal to the sum of the variances of each feature dimension. A smaller trace indicates that the micro-sample class is more concentrated in that layer. Record the intra-class dispersion value of each micro-sample class in each intermediate layer.
[0060] S412: For each intermediate layer, obtain the inter-layer features of all micro-sample class samples under the micro-sample category in that layer. Query the buffer band index table, and determine whether the inter-layer features of each micro-sample class sample fall within the range of any inter-class ambiguity buffer band. Calculate the proportion of samples falling within the inter-class ambiguity buffer band to the total number of samples, and use this as the buffer band overlap.
[0061] For each stable class feature distribution, calculate the Mahalanobis distance from the inter-layer features of each micro-sample class to the stable class feature distribution. Calculate the proportion of samples with a Mahalanobis distance less than a preset threshold to the total number of samples, using this proportion as the stable class overlap. Weight the buffer zone overlap and the stable class overlap according to preset weights and sum them to obtain the overlap of the intermediate layer. Record the overlap value of each micro-sample class in each intermediate layer.
[0062] S413: For each intermediate layer, take the inter-layer features of all micro-sample class samples under the micro-sample category in the layer, input the inter-layer features into the remaining network layers after the intermediate layer, and perform forward propagation to obtain the propagation features after propagation through subsequent network layers.
[0063] Simultaneously, the inter-layer features of each stable class sample in the intermediate layer are extracted and input into the remaining network layers to obtain the propagation features of the stable class samples. The average inter-class distance between micro-sample class samples and stable class samples in the propagation features is calculated, as well as the average intra-class distance within each micro-sample class sample in the propagation features. The ratio of the average inter-class distance to the average intra-class distance is used as the separability of the intermediate layer. A larger ratio indicates that the micro-sample class and the stable class are more easily distinguished after subsequent propagation. The separability value of each micro-sample class in each intermediate layer is recorded.
[0064] It should be noted that since the features after the adapter is attached are further transformed by subsequent network layers, evaluating only the features of the attaching layer itself is insufficient. Only by evaluating the final features after subsequent propagation can we reflect the actual separability of the transformed features in the final classification space. The depth of the remaining network layers after different intermediate layers varies, and the degree of feature transformation also varies. Therefore, separability varies with the layer level; shallower layers have longer remaining network layers with larger transformations, while deeper layers have shorter remaining network layers with smaller transformations.
[0065] S414: For each intermediate layer, obtain the intra-class dispersion, overlap, and separability of the micro-sample category in the intermediate layer.
[0066] The intra-class dispersion is negative and then weighted by a first preset weight; the overlap is negative and then weighted by a second preset weight; and the separability is weighted by a third preset weight. The three weighted sums are used to obtain the mounting adaptation score of the intermediate layer.
[0067] The first, second, and third preset weights are preset based on the number of samples in the micro-sample class; the smaller the sample size, the higher the first preset weight. Record the mounting and adaptation score for each intermediate layer.
[0068] Thus, the three indicators correspond to the feasibility, safety, and effectiveness of the mounting, respectively. Their weighted sum comprehensively reflects the suitability of the layer as a mounting location. The weights are adjusted based on the sample size of each micro-sample class. Fewer samples require greater intra-class concentration to ensure the stability of the deformation learning; therefore, the intra-class dispersion weight increases as the sample size decreases.
[0069] S415: Sort the mounting adaptation scores of the micro-sample category across all intermediate layers from high to low, and select the intermediate layer with the highest mounting adaptation score as the candidate mounting layer. Obtain the mounting adaptation score of the candidate mounting layer and compare it with a preset scoring threshold. If the mounting adaptation score of the candidate mounting layer is higher than the preset scoring threshold, it is determined that the candidate mounting layer meets the mounting requirements, and the candidate mounting layer is determined as the optimal mounting layer for the micro-sample category. Record the layer number and corresponding mounting adaptation score of the optimal mounting layer.
[0070] The preset scoring threshold here is used to set the minimum acceptable standard to prevent forced mounting in cases where there is high overlap between micro-sample classes and stable classes or extreme dispersion within classes. A score higher than the threshold indicates that the layer meets the basic requirements in terms of intra-class concentration, low overlap, and good separability, making it suitable for mounting a low-rank gating adapter.
[0071] S416: When all intermediate layer scores fail to meet the standard, it indicates that the micro-sample class cannot find a suitable mounting position under the original strict conditions. The possible reasons are that the micro-sample class itself is scattered within the class or highly overlaps with the stable class. In this case, mounting is not rejected directly, but the conditions are relaxed by adjusting the weights or thresholds, prioritizing the most critical indicator of intra-class dispersion, or relaxing the tolerance for overlap, to find the relatively optimal mounting layer within an acceptable range.
[0072] Increasing the weight of intra-class dispersion makes the scoring more focused on sample concentration, since the adapter's learning of unified deformation requires intra-class concentration. Increasing the distance threshold makes the overlap judgment more lenient, tolerating some similarity between micro-sample classes and stable classes. The parameter adjustment label records the category as a relaxed condition attachment, and stronger stable class maintenance constraints can be imposed on the category during subsequent training. Higher matching scores can be required for the category during the inference phase, compensating for the problems brought about by the relaxed conditions.
[0073] In one exemplary embodiment, based on step S5, the following will provide a possible embodiment and describe its specific implementation in a non-limiting manner.
[0074] S511: Insert a low-rank gated adapter at the optimal mounting layer. The low-rank gated adapter consists of two learnable parameters: a low-rank projection matrix and gate weights.
[0075] A low-rank projection matrix is formed by multiplying two low-rank matrices, and its parameter count is much smaller than that of a full-rank projection matrix. Micro-sample classes are input into the stable backbone network. Inter-layer features of the micro-sample classes are extracted at the optimal mounting layer, and the average of the inter-layer features of all micro-sample classes is calculated as the micro-sample class prototype. The micro-sample class prototype is used as the center of the local subspace. The range of the local subspace is defined by the similarity between sample features and the micro-sample class prototype; regions with similarity higher than a preset similarity threshold are included in the local subspace.
[0076] S512: For each sample of the input optimal mounting layer, calculate the similarity between the sample features and the micro-sample class prototype. The similarity is expressed as cosine similarity or negative Euclidean distance.
[0077] Gating coefficients are generated based on similarity. The gating coefficients map the similarity to the interval between zero and one using the sigmoid function. The gating coefficients are positively correlated with similarity, and the closer a sample is to the prototype of the micro-sample class, the larger the gating coefficients are.
[0078] Low-rank transformation is performed on the sample features using a low-rank projection matrix. This low-rank transformation projects the sample features onto a low-rank subspace and then maps them back to the original dimension, yielding the low-rank transformation result. The gating coefficients are then multiplied element-wise with the low-rank transformation result to obtain the deformed features. Samples closer to the micro-sample class prototype receive larger gating coefficients and significant deformation, while samples farther from the micro-sample class prototype receive near-zero gating coefficients and minimal deformation.
[0079] S513: Add the deformed features to the original interlayer features to obtain the adapter output features. The residual connection ensures that the initial state of the adapter is transparent to the network.
[0080] Calculate the target alignment loss, constrain the adapter output features to cluster towards the micro-sample class prototype, and reduce the distance between the micro-sample class adapter output features and the micro-sample class prototype.
[0081] Calculate the stable class preservation loss, constraining the difference between the adapter output features of stable class samples and the original inter-layer features to be less than a preset difference threshold, while constraining the gating coefficients to remain close to zero for stable class samples. Update the low-rank projection matrix and gating weights in reverse based on the weighted sum of the target alignment loss and the stable class preservation loss, iterating until the loss converges.
[0082] S514: Input the adapter output features into the final feature transfer head. The final feature transfer head includes a learnable transfer matrix and a bias. The transfer matrix maps the adapter output features from the feature dimension of the optimal mounting layer to the feature dimension of the target subspace. The bias provides a translation amount to position the target subspace at a reserved position in the feature space.
[0083] The adapter output features are mapped to a reserved target subspace in the feature space using a transfer matrix and bias. The stable class separation loss is calculated, and the Mahalanobis distance between the micro-sample class features in the target subspace and the distribution of each stable class feature is constrained to be greater than a preset separation threshold. At the same time, the target subspace is constrained not to intersect with the inter-class ambiguity buffer zone.
[0084] The augmentation consistency loss is calculated by applying different data augmentations to samples of the same micro-sample class and then inputting them into the network to constrain the consistency of features mapped to the target subspace in both cases.
[0085] S515: Based on the weighted sum of target alignment loss, stable class separation loss, stable class preservation loss and enhanced consistency loss, jointly update the low-rank projection matrix, gating weights, and the transfer matrix and bias of the final feature transfer head of the low-rank gated adapter in reverse.
[0086] Iterative training continues until the change in the weighted sum falls below a preset convergence threshold. After training convergence, all parameters of the low-rank gating adapter and the final feature transfer head are frozen. The micro-sample categories are then associated and stored with the center coordinates and range of the corresponding target subspace, as well as the parameter indices of the low-rank gating adapter and the final feature transfer head. This completes the mounting of the micro-sample categories, which can then be identified during the inference phase.
[0087] In this embodiment, the target alignment loss ensures intra-class compactness, the stable class preservation loss protects the stable class, and the stable class separation loss ensures the safety of the target subspace. These four losses cover all critical constraints in the mounting process. After convergence, the parameters are frozen to fix the mounting result, preventing further changes during the inference phase. After mounting, the micro-sample class is incorporated into the identifiable class space, while the stable class boundary remains intact, achieving a balance between micro-sample class inclusion and stable class protection.
[0088] Furthermore, as a refinement of the specific implementation of the above embodiments, the following is a specific example of implementing the method of the present invention: a PCB board appearance inspection line in a 3C electronic product manufacturing plant has deployed a vision inspection system. Tens of thousands of PCB boards flow through the production line every day, and quality inspection cameras capture high-definition images of each board. The system determines in real time whether defects exist and the type of defects.
[0089] The current system faces three practical difficulties: There are four common defects—short circuits, cold solder joints, component misalignment, and missing components. Each type has accumulated more than 300 labeled samples, which are sufficient and the characteristics are stable, belonging to the stable category. However, two rare defects have recently appeared on the production line—solder joint bubbles and solder pad scratches, with only 8 and 12 labeled samples respectively, belonging to the micro-sample category.
[0090] Engineers tried training the system with all 20 types of defects together. However, due to the small number of samples, the gradient of solder joint bubbles was dominated by the noise of individual samples, and the classification boundary was extremely unstable. Normal solder pads were often misclassified as bubbles. At the same time, the feature space of the cold solder joint category was squeezed, and the false negative rate of cold solder joints increased by 3 percentage points.
[0091] Furthermore, the system needs to be able to identify unique defects introduced by a new packaging process, rather than forcibly classifying them into existing categories. The method of this invention is described below step by step.
[0092] S101: Organize historical defect data and categorize it by sample size: short circuits, cold solder joints, component misalignment, and missing components, each with more than 50 images, are classified as stable data; solder joint bubbles (8 images) and solder pad scratches (12 images), below the 50-image threshold, are classified as micro-sample data. Micro-sample data will not be included in the first stage of training.
[0093] S102: The initial neural network was trained using only four stable classes of data (more than 1200 images in total). The training employed a four-class loss joint optimization: cross-entropy loss to ensure correct classification of the four types of defects, supervised contrast loss to cluster features of similar defects and separate features of dissimilar defects, intra-class compactness loss to compress the feature distribution volume of each type of defect, and energy calibration loss to make the energy scores of stable class samples low and the energy scores of unstable class samples high.
[0094] After training convergence, a stable backbone network is obtained. In the feature space, short circuits, cold solder joints, offsets, and missing parts each occupy a compact elliptical region, with clear intervals between the regions. The classifier outputs a classification confidence score for each image, indicating whether it belongs to one of the four defect types.
[0095] S103: A small overlap was identified between the feature regions of cold solder joints and short circuits. Some images resembled both cold solder joints and minor short circuits, and the classifier's logit margin in this region was very small. The system merged this overlapping region with the low-confidence boundary region where the classification margin was less than the threshold, marking it as an inter-class ambiguity buffer zone between cold solder joints and short circuits.
[0096] Similarly, there is a buffer zone between offsets and missing parts. These buffer zones are not considered classification errors, but are recorded as space that must be avoided when attaching subsequent microsample classes.
[0097] S104: For solder joint bubbles (8 samples), input the 8 bubble images into the stable backbone network, extract features from the four intermediate layers (layers 3, 6, 9, and 12) of the network, and evaluate three metrics: Intra-class dispersion: Whether the features of the 8 bubble charts are concentrated in the layer. The dispersion is lowest in layer 6, and the bubble features are best clustered in this layer.
[0098] Overlap: The proportion of overlap between bubble features and stable class features, and between inter-class ambiguity buffer bands. The bubble features in layer 6 fall outside the short-circuit buffer band of poor solder joints, resulting in the lowest overlap.
[0099] Separability: After the bubble features propagate through subsequent network layers to the final layer, can they still be distinguished from the stable class? The highest separability is achieved after propagation through the 6th layer.
[0100] After weighting the three factors, layer 6 scored the highest, and the system selected layer 6 as the optimal mounting layer for solder joint bubbles. Pad scratches were evaluated in the same way, and layer 9 was selected as the optimal mounting layer. The two micro-sample types are mounted on different layers and do not interfere with each other.
[0101] S105: Insert a lightweight low-rank gating adapter at layer 6. The adapter first calculates the average features of the 8 bubble images at layer 6 as the bubble class prototype, and delineates a local subspace centered on the prototype. For each image input to layer 6, the adapter calculates the similarity between the image features and the bubble prototype, generating a gating coefficient: the more similar the image is to a bubble, the larger the gating coefficient, and the stronger the deformation; for stable class samples unrelated to bubbles, the gating coefficient is close to zero, and there is almost no deformation.
[0102] The deformed bubble features are mapped to a reserved independent target subspace in the feature space via the final feature transfer head. This subspace is constrained through training to avoid intersecting with stable regions such as short circuits and cold solder joints, as well as cold solder joint and short circuit buffer zones. Similarly, pad scratches are migrated into another independent target subspace after the adapter is mounted on layer 9.
[0103] After training, bubbles and scratches each occupy an independent small area, while the four stable areas remain completely still.
[0104] S106: Based on a PCB board flowing through the production line, a camera takes a picture and inputs it into the system. Level 1: Stability Classification. The classifier outputs the confidence score of the image belonging to one of the four stable defect categories. The maximum score is 0.92 (cold solder joint), which is higher than the threshold of 0.85, so it is directly classified as a cold solder joint, triggering the cold solder joint repair process. Most boards are processed at this level.
[0105] On the other board, the maximum stable class confidence score was only 0.41, below the threshold, so it entered the second level. The system sequentially called the bubble adapter and scratch adapter to calculate the matching score of the graph features in the bubble target subspace and scratch target subspace. The bubble matching score was 0.87, higher than the threshold of 0.7, so it was determined to be a solder joint bubble, triggering the bubble repair process.
[0106] The third board had a stable class confidence score of 0.38, a bubble match score of 0.21, and a scratch match score of 0.15, all of which failed to meet the standards. The system classified it as an unknown class and sent it to the manual re-inspection area. The re-inspection revealed a coating discoloration defect caused by a new process. Engineers collected 10 annotations and re-entered the system into the S4S5 process, adding it as a new micro-sample class to the network. The system's recognizable categories expanded from 6 to 7, and the entire process did not require retraining the stable class backbone network.
[0107] It can be seen that bubbles and scratches are directly included in the training. However, resampling 8 samples is equivalent to repeatedly viewing the same few images, leading to severe overfitting; after reweighting, the gradient noise of bubbles will impact the stable boundary of the faulty solder joints, resulting in an increased false negative rate for faulty solder joints. In this embodiment, the micro-sample class is not included in the backbone training at all, but is processed in the second stage as a lightweight adapter, the backbone network parameters are frozen, and the stable class boundary is zero-perturbation.
[0108] This embodiment identifies routes based on open sets, rejecting bubbles and scratches as unknown categories. However, the production line already has labels for these two categories, requiring system identification and routing to corresponding repair stations. Rejecting all labels would mean abandoning the value of a small number of labels. This embodiment uses a small number of labels to drive adapter mounting and target subspace migration, separating new categories with a small number of labels from the unknown categories and transforming them into identifiable categories, while still retaining the ability to reject truly unknown categories.
[0109] The distance between the sample and various prototypes is calculated at the final feature layer. However, the few-sample method does not consider the structural conflict between the new class and the already trained stable class space. The bubble prototype may fall into the overlapping area of the cold solder joint and short circuit, causing the bubble and the cold solder joint to be misjudged. This embodiment defines an inter-class ambiguity buffer zone and actively avoids it when selecting the mounting layer. Then, the micro-sample class is moved to an independent target subspace through the final migration head, isolating the micro-sample class from the stable class in terms of spatial structure. While protecting the boundary of the stable class, it continuously absorbs the micro-sample class and rejects the truly unknown class, thus addressing the problem of long-tail open scenarios such as PCB defect detection.
[0110] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0111] The following are embodiments of the imbalanced sample detection and identification system provided in this disclosure. The system and the imbalanced sample detection and identification methods in the above embodiments belong to the same inventive concept. For details not described in detail in the embodiments of the imbalanced sample detection and identification system, please refer to the embodiments of the imbalanced sample detection and identification methods described above.
[0112] like Figure 4 As shown, the data acquisition module 201 is used to acquire training data, which includes stable class data and micro sample class data. The stable class data is known class data with a sample number that meets a preset number threshold, and the micro sample class data is class data to be absorbed with a sample number that is lower than the preset number threshold. The first-stage training module 202 is used to perform a first-stage training on the initial neural network using only the stable class data to obtain a stable class backbone network, and to form and determine the stable class feature distribution of each stable class in the stable class data in the feature space through the stable class backbone network, and to output the classification confidence of each stable class. The buffer band determination module 203 is used to determine the inter-class ambiguity buffer band between different stable categories based on the stable class feature distribution of each stable category. The inter-class ambiguity buffer band includes the overlapping region of the stable class feature distribution and the low confidence boundary region where the classification interval is less than a preset interval threshold. The inter-class ambiguity buffer band is used to provide a distinguishable spatial boundary for the micro-sample class data and the unknown class. The mounting layer selection module 204 is used to enter the second stage of training after completing the first stage of training. For each micro-sample category, it evaluates the intra-class dispersion, overlap with the inter-class ambiguity buffer and the stable class feature distribution, and separability after propagation through subsequent network layers in multiple intermediate layers of the stable class backbone network. Based on the evaluation results, it selects the optimal mounting layer from the multiple intermediate layers. The mounting module 205 is used to mount a low-rank gating adapter for the micro-sample category at the optimal mounting layer during the second stage of training. The low-rank gating adapter performs feature deformation on samples falling into the local subspace of the micro-sample category and maps the deformed features to the reserved target subspace through the final feature transfer head, thereby completing the mounting of the micro-sample category.
[0113] like Figure 5 As shown, this application also provides an electronic device, including a display module 103, a memory 102, a processor 101, a communication module 104, and a computer program stored in the memory and executable on the processor 101. When the processor 101 executes the program, it implements the steps of a detection and identification method for imbalanced samples.
[0114] In embodiments of the present invention, electronic devices include, but are not limited to, laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. Electronic devices can also refer to various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the embodiments described and / or claimed herein.
[0115] In this embodiment, processor 101 may be implemented using at least one of an application-specific integrated circuit, a programmable logic device, a field-programmable gate array, a processor, a controller, a microcontroller, a microprocessor, or an electronic unit designed to perform the functions described herein. In some cases, such an implementation may be implemented within a controller. For software implementation, implementations such as processes or functions may be implemented with separate software modules that allow the performance of at least one function or operation. Software code may be implemented by a software application (or program) written in any suitable programming language, and the software code may be stored in memory and executed by the controller.
[0116] The display module 103 is used to display information input by the user or information provided to the user. The display module 103 may include a display panel, which may be configured in the form of a liquid crystal display, an organic light-emitting diode, or the like.
[0117] The memory 102 can be used to store software programs and various data. The memory 102 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0118] The communication module 104 transmits radio signals to and / or receives radio signals from at least one of a base station, an external terminal, and a server. Such radio signals may include voice call signals, video call signals, or various types of data sent and / or received according to text and / or multimedia messages.
[0119] The above description of the disclosed embodiments enables those skilled in the art to make or use the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for detecting and identifying imbalanced samples, characterized in that, The methods include: S1. Obtain training data, which includes stable class data and micro sample class data. The stable class data is known class data with a sample number that meets a preset quantity threshold. The micro sample class data is class data to be absorbed with a sample number that is lower than the preset quantity threshold. S2. The initial neural network is trained in the first stage using only the stable class data to obtain the stable class backbone network. The stable class backbone network is used to form and determine the stable class feature distribution of each stable class in the stable class data in the feature space, and the classification confidence of each stable class is output. S3. Based on the stable class feature distribution of each stable class, determine the inter-class ambiguity buffer zone between different stable classes. The inter-class ambiguity buffer zone includes the overlapping region of the stable class feature distribution and the low confidence boundary region where the classification interval is less than a preset interval threshold. The inter-class ambiguity buffer zone is used to provide a distinguishable spatial boundary for the micro-sample class data and the unknown class. S4. After completing the first stage of training, proceed to the second stage of training: For each micro-sample category, evaluate the intra-class dispersion, overlap with the inter-class ambiguity buffer and the stable class feature distribution, and separability after propagation through subsequent network layers in multiple intermediate layers of the stable class backbone network, and select the optimal mounting layer from the multiple intermediate layers based on the evaluation results. S5. In the second stage of training, a low-rank gating adapter is attached to the micro-sample category at the optimal attachment layer. The low-rank gating adapter performs feature deformation on the samples falling into the local subspace of the micro-sample category, and maps the deformed features to the reserved target subspace through the final feature transfer head, thereby completing the attachment of the micro-sample category.
2. The method for detecting and identifying imbalanced samples according to claim 1, characterized in that, In step S2, the step of using only the stable class data to perform the first stage training of the initial neural network to obtain the stable class backbone network specifically includes: The stable class samples in the stable class data are input into the initial neural network. The initial features of each stable class sample are output through the feature extraction layer, and the original prediction scores of each stable class sample corresponding to each stable class are output through the classifier. The cross-entropy loss is calculated to constrain the classifier to output the correct class label for each of the stable class samples; the supervised contrast loss is calculated to bring the initial features of the same stable class sample closer together and push the initial features of different stable class samples further apart within each training batch; the intra-class compactness loss is calculated to compress the distribution variance of the initial features under each stable class; and the energy calibration loss is calculated to adjust the energy score of each stable class sample according to the original prediction score output by the classifier. The network parameters of the initial neural network are updated based on the cross-entropy loss, the supervised contrast loss, the intra-class compactness loss, and the energy calibration loss to obtain the stable class backbone network.
3. The method for detecting and identifying imbalanced samples according to claim 1, characterized in that, Step S3 specifically includes: S31. For each pair of stable categories, calculate the Mahalanobis overlap probability based on the feature mean and covariance matrix of the two stable categories, and mark the feature space region where the Mahalanobis overlap probability is greater than a preset probability threshold as the first type of buffer sub-band. S32. Fit a classification interval distribution function with the final features of stable class samples as independent variables and the absolute value of the difference between the original predicted scores of the two stable classes as dependent variables, and mark the feature space regions in the classification interval distribution function that are less than the preset interval threshold as the second type of buffer sub-band. S33. Take the union of the first type of buffer sub-band and the second type of buffer sub-band in the feature space to obtain the inter-class ambiguity buffer band. Calculate the priority and sort them according to the area ratio of the overlapping region and the average classification interval. The higher the priority, the greater the avoidance weight when evaluating the micro-sample class overlap and the higher the exclusion priority when allocating the target subspace. S34. The position, range and priority of each inter-class ambiguity buffer are associated and stored, and a buffer index table is established for micro-sample class overlap evaluation and target subspace allocation query.
4. The method for detecting and identifying imbalanced samples according to claim 1, characterized in that, In step S4, the intra-class dispersion of the micro-sample category, its overlap with the inter-class ambiguity buffer and the stable class feature distribution, and its separability after propagation through subsequent network layers are evaluated in multiple intermediate layers of the stable class backbone network, including: S411. Extract the inter-layer features of the micro-sample class samples in each of the intermediate layers, and take the trace of the covariance matrix of the inter-layer features as the intra-class scatter. S412. Query the buffer zone index table, and calculate the percentage of samples in which the inter-layer features fall into the inter-class ambiguity buffer zone as the buffer zone overlap. Calculate the percentage of samples in which the Mahalanobis distance from the inter-layer features to the distribution of each stable class feature is less than a preset distance threshold as the stable class overlap. Calculate the overlap by weighted summation of the buffer zone overlap and the stable class overlap. S413. Input the inter-layer features into the remaining network layers after the intermediate layer to obtain the propagation features, and take the ratio of the average inter-class distance between the micro-sample class samples and the stable class samples in the propagation features to the average intra-class distance within the micro-sample class samples as the separability.
5. The method for detecting and identifying imbalanced samples according to claim 4, characterized in that, In step S4, selecting the optimal mounting layer from the plurality of intermediate layers based on the evaluation results includes: S414. After taking negative values for the intra-class dispersion and the overlap, weight them according to the first preset weight and the second preset weight respectively, and weight the separability according to the third preset weight. The sum of the three items is used to obtain the mount adaptation score. The first preset weight, the second preset weight and the third preset weight are preset according to the number of samples in the micro-sample class. S415. Sort the mounting adaptation scores of all the intermediate layers, select the intermediate layer with the highest score as the candidate mounting layer, and if the mounting adaptation score of the candidate mounting layer is higher than the preset score threshold, then determine it as the optimal mounting layer. S416. If the mounting adaptation score of the candidate mounting layer is not higher than the preset score threshold, then increase the first preset weight ratio or increase the preset distance threshold, recalculate the mounting adaptation score and select the optimal mounting layer, and record the layer number and parameter adjustment mark of the optimal mounting layer.
6. The method for detecting and identifying imbalanced samples according to claim 1, characterized in that, In step S5, a low-rank gating adapter is attached to the micro-sample category at the optimal attachment layer. The low-rank gating adapter performs feature deformation on samples falling into the local subspace of the micro-sample category, including: S511. Insert a low-rank gated adapter, including a low-rank projection matrix and gate weights, at the optimal mounting layer. Extract the inter-layer features of the micro-sample class samples at the optimal mounting layer. Take the average value of the inter-layer features as the micro-sample class prototype. Define the range of the local subspace with the micro-sample class prototype as the center and the similarity between the sample features and the micro-sample class prototype. S512. Calculate the similarity between the features of the input sample and the prototype of the micro-sample class and generate a gating coefficient that is positively correlated with the similarity. Perform low-rank deformation on the sample features through the low-rank projection matrix and multiply the gating coefficient with the low-rank deformation result to obtain the deformed features. S513. Add the deformed features to the original interlayer features to obtain the adapter output features. Constrain the adapter output features to cluster towards the micro-sample class prototype through the target alignment loss. Constrain the difference between the adapter output features and the original interlayer features of the stable class samples to be less than a preset difference threshold and the gating coefficient to be close to zero for the stable class samples through the stable class maintenance loss. Update the low-rank projection matrix and the gating weights until convergence.
7. The method for detecting and identifying imbalanced samples according to claim 6, characterized in that, In step S5, the deformed features are mapped to the reserved target subspace using the final feature transfer head, completing the mounting of the micro-sample category, including: S514. The adapter output features are input into the final feature transfer head, which includes the transfer matrix and the bias, and mapped to the reserved target subspace in the feature space. The stable class separation loss constrains the Mahalanobis distance between the micro-sample class features in the target subspace and the distribution of each stable class feature to be greater than a preset separation threshold and the target subspace to not intersect with the inter-class ambiguity buffer. The enhanced consistency loss constrains the features of the same micro-sample class sample mapped to the target subspace to be consistent after different enhancements. S515. Based on the weighted sum of the target alignment loss, the stable class separation loss, the stable class preservation loss, and the enhanced consistency loss, jointly update the low-rank projection matrix, the gate weights, the migration matrix, and the bias to convergence, freeze all parameters, and associate and store the micro-sample category with the center coordinates, range, and parameter index of the corresponding target subspace to complete the mounting of the micro-sample category.
8. The method for detecting and identifying imbalanced samples according to claim 1, characterized in that, Step S5 also includes: The sample to be identified is input into the stable class backbone network. If the maximum classification confidence of the sample to be identified is higher than the preset confidence threshold, it is determined to be the stable class. Otherwise, the matching score between the sample to be identified and the target subspace of each loaded micro-sample category is calculated through the low-rank gating adapter and the final feature transfer head. If the maximum matching score is higher than the preset matching threshold, it is determined to be the corresponding loaded micro-sample category. If none of them are higher than the specified value, then it is determined to be an unknown category.
9. A detection and identification system for imbalanced samples, characterized in that, The system is used to implement the imbalanced sample detection and identification method as described in any one of claims 1 to 8; the system includes: The data acquisition module is used to acquire training data, which includes stable class data and micro sample class data. The stable class data is known class data whose sample number meets a preset number threshold, and the micro sample class data is class data to be absorbed whose sample number is lower than the preset number threshold. The first-stage training module is used to train the initial neural network using only the stable class data to obtain a stable class backbone network. The stable class backbone network is used to form and determine the stable class feature distribution of each stable class in the stable class data in the feature space, and output the classification confidence of each stable class. The buffer band determination module is used to determine the inter-class ambiguity buffer band between different stable categories based on the stable class feature distribution of each stable category. The inter-class ambiguity buffer band includes the overlapping region of the stable class feature distribution and the low confidence boundary region where the classification interval is less than a preset interval threshold. The inter-class ambiguity buffer band is used to provide a distinguishable spatial boundary for the micro-sample class data and the unknown class. The mounting layer selection module is used to enter the second stage of training after the first stage of training is completed. For each micro-sample category, it evaluates the intra-class dispersion, the overlap with the inter-class ambiguity buffer and the stable class feature distribution, and the separability after propagation through subsequent network layers in multiple intermediate layers of the stable class backbone network. Based on the evaluation results, it selects the optimal mounting layer from the multiple intermediate layers. The mounting module is used in the second stage of training to mount a low-rank gating adapter for the micro-sample category at the optimal mounting layer. The low-rank gating adapter performs feature deformation on samples falling into the local subspace of the micro-sample category and maps the deformed features to the reserved target subspace through the final feature transfer head, thereby completing the mounting of the micro-sample category.
10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method for detecting and identifying imbalanced samples as described in any one of claims 1 to 8.
