A model training method based on an adaptive attention weighting contrast loss function
By adjusting the sample weights using an adaptive attention-weighted contrastive loss function, the model bias problem caused by the imbalance between positive and negative samples in satellite and UAV remote sensing is solved, and the model's accuracy in identifying minority class samples is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING GUOYAO STAR AVIATION TECHNOLOGY CO LTD
- Filing Date
- 2026-02-10
- Publication Date
- 2026-05-29
AI Technical Summary
In the field of satellite and UAV remote sensing technology, the imbalance between positive and negative samples causes the model to favor the majority class, resulting in insufficient learning of minority class features, degradation of the model's feature representation ability, gradient imbalance during training, and model optimization getting stuck in local optima.
An adaptive attention-weighted contrastive loss function is adopted, which adjusts the sample weights by calculating the spatial distribution features of the samples, introduces an adaptive attention mechanism, and uses a contrastive learning framework to strengthen the semantic boundaries of categories and optimize the model training process.
To improve the model's recognition accuracy in scenarios with imbalanced positive and negative samples, avoid the majority class samples from over-dominating the loss gradient, and enhance the model's ability to recognize minority class samples.
Smart Images

Figure CN122116034A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of model training technology, and in particular to a model training method based on an adaptive attention-weighted contrastive loss function. Background Technology
[0002] In the field of satellite and UAV remote sensing technology, the extreme imbalance between positive and negative samples (such as small target segmentation, medical image segmentation, road extraction, etc.) is a common problem in semantic segmentation of collected remote sensing data. Ordinary cross-entropy loss will cause the model to be biased towards the majority class due to the difference in the proportion of samples, which will lead to insufficient learning of minority class features, degradation of the model's feature representation ability, and even gradient imbalance during training, causing the model optimization to get stuck in a local optimum.
[0003] Therefore, how to improve the recognition accuracy of the model during model training in scenarios with imbalanced positive and negative samples has become an urgent problem for those skilled in the art. Summary of the Invention
[0004] In view of this, this application proposes a model training method based on an adaptive attention-weighted contrastive loss function, which can improve the recognition accuracy of the model when training the model in a scenario with imbalanced positive and negative samples.
[0005] According to a first aspect of this application, a model training method based on an adaptive attention-weighted contrastive loss function is provided. This method is used to train a model to be trained, including: Obtain a training sample set and the pre-constructed model to be trained; wherein the training sample set includes positive samples as target regions and negative samples as background regions; The training sample set is input into the target region of the model to be trained, and the current loss function of the model to be trained is calculated. The parameters of the model to be trained are adjusted according to the current loss function. The above training process is repeated based on the adjusted model to be trained, and the model training ends when the loss function converges. Specifically, when calculating the current loss function of the model to be trained, it is obtained by calculating the weights of each sample; and the weights of each sample are calculated based on the spatial distribution characteristics of each sample.
[0006] In one possible implementation, obtaining the spatial distribution characteristics of each of the samples includes: The training sample set is clustered to obtain positive sample class and negative sample class; Based on the positive sample class and the negative sample class, the positive sample cluster center and the negative sample cluster center are determined; Based on the positive sample cluster centers and the negative sample cluster centers, calculate the intra-class distance between each positive sample and its cluster center, and the intra-class distance between each negative sample and its cluster center; the calculated intra-class distance is the spatial distribution feature of each sample.
[0007] In one possible implementation, when calculating the weights of each sample based on the spatial distribution characteristics of each sample, it includes calculating at least one of the weights of each positive sample and the weights of each negative sample.
[0008] In one possible implementation, the calculation of the weights of the positive samples based on the aforementioned spatial distribution characteristics can be expressed by the following formula: in, This represents the adaptive attention weight for the i-th positive sample. For the first Spatial distribution characteristics of positive samples This is the weighting adjustment coefficient. To avoid the minimum value where the denominator is 0.
[0009] In one possible implementation, the calculation of the weights of the negative samples based on the aforementioned spatial distribution characteristics can be expressed by the following formula: in, This represents the adaptive attention weight for the i-th negative sample. For the first Spatial distribution characteristics of negative samples This is the weighting adjustment coefficient. To avoid the minimum value where the denominator is 0.
[0010] In one possible implementation, calculating the current loss function of the model to be trained based on the weights of each of the samples includes: The weights of each sample are obtained, and the values of the positive sample guiding term and the negative sample constraint term are calculated respectively. The current loss function is calculated based on the values of the positive sample guiding term and the negative sample constraint term.
[0011] In one possible implementation, when calculating the values of the positive sample guiding term and the negative sample constraint term respectively by obtaining the weights of each of the samples, the following is included: The weights of each positive sample and each negative sample are extracted from the weights of each sample. The value of the positive sample guiding term is calculated based on the weight of each positive sample; The value of the negative sample constraint term is calculated based on the weight of each negative sample.
[0012] According to a second aspect of this application, a model training apparatus based on an adaptive attention-weighted contrastive loss function is provided for training a model to be trained, comprising: The data acquisition module is used to acquire a training sample set and a pre-built model to be trained; wherein, the training sample set includes positive samples as target regions and negative samples as background regions; The model training module is used to input the training sample set into the target region segmented by the model to be trained, calculate the current loss function of the model to be trained, and adjust the parameters of the model to be trained according to the current loss function. An iterative module is used to repeat the above training process based on the adjusted model to be trained, and the model training ends when the loss function converges. Specifically, when calculating the current loss function of the model to be trained, it is obtained by calculating the weights of each sample; and the weights of each sample are calculated based on the spatial distribution characteristics of each sample.
[0013] According to a third aspect of this application, a model training device based on an adaptive attention-weighted contrastive loss function is provided, comprising: a processor; a memory for storing processor-executable instructions; wherein the processor is configured to execute the method described in the first aspect of this application.
[0014] According to a fourth aspect of this application, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, wherein the computer program instructions, when executed by a processor, implement the method described in the first aspect of this application.
[0015] This application provides a model training method based on an adaptive attention-weighted contrastive loss function for training a model to be trained. The method includes: acquiring a training sample set and a pre-built model to be trained; wherein the training sample set includes positive samples as target regions and negative samples as background regions; inputting the training sample set into the target region segmented by the model to be trained, calculating the current loss function of the model to be trained, and adjusting the parameters of the model to be trained based on the current loss function; repeating the above training process based on the adjusted model to be trained, and ending model training when the loss function converges; wherein, when calculating the current loss function of the model to be trained, it is calculated using the weights of each sample; and the weights of each sample are calculated based on the spatial distribution characteristics of each sample. This application proposes a novel loss function for model training, namely, an adaptive attention-weighted contrastive loss function. This loss function incorporates the spatial distribution characteristics of each sample into the calculation of sample weights when positive and negative samples are imbalanced, allowing the weights of samples to be adaptively adjusted based on the spatial distribution characteristics of each sample when positive and negative samples are imbalanced. This enables the model to avoid excessive dominance of the loss gradient by the majority class samples, thereby improving the model's recognition accuracy.
[0016] Other features and aspects of this application will become clear from the following detailed description of exemplary embodiments with reference to the accompanying drawings. Attached Figure Description
[0017] The accompanying drawings, which are included in and form part of this specification, illustrate exemplary embodiments, features, and aspects of this application together with the specification and serve to explain the principles of this application.
[0018] Figure 1 A schematic flowchart of a model training method based on an adaptive attention-weighted contrastive loss function according to an embodiment of this application is shown. Figure 2 A schematic block diagram of a model training apparatus based on an adaptive attention-weighted contrastive loss function according to an embodiment of this application is shown. Figure 3 A schematic block diagram of a model training device based on an adaptive attention-weighted contrastive loss function according to an embodiment of this application is shown. Detailed Implementation
[0019] Various exemplary embodiments, features, and aspects of this application will now be described in detail with reference to the accompanying drawings. The same reference numerals in the drawings denote elements that have the same or similar functions. Although various aspects of the embodiments are shown in the drawings, they are not necessarily drawn to scale unless specifically indicated otherwise.
[0020] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments.
[0021] Furthermore, to better illustrate this application, numerous specific details are provided in the following detailed embodiments. Those skilled in the art should understand that this application can be implemented without certain specific details. In some instances, methods, means, components, and circuits well-known to those skilled in the art have not been described in detail in order to highlight the main points of this application.
[0022] <Method Implementation> Figure 1 This diagram illustrates a model training method based on an adaptive attention-weighted contrastive loss function according to an embodiment of this application. Figure 1 As shown, this method is used to train a model to be trained, and includes steps S1100-S1300. S1100: Obtain a training sample set and a pre-built model to be trained; wherein the training sample set includes positive samples as target regions and negative samples as background regions; S1200: Input the training sample set into the target region segmented by the model to be trained, calculate the current loss function of the model to be trained, and adjust the parameters of the model to be trained according to the current loss function; S1300: Repeat the above training process based on the adjusted model to be trained, and the model training ends when the loss function converges; wherein, when calculating the current loss function of the model to be trained, it is calculated using the weights of each sample; and the weights of each sample are calculated based on the spatial distribution characteristics of each sample.
[0023] This application proposes a novel loss function for model training: the Adaptive Attention-Weighted Contrastive Loss (AAWCL). This loss function incorporates the spatial distribution characteristics of each sample into the calculation of sample weights when positive and negative samples are imbalanced. This allows the model to adaptively adjust the sample weights based on the spatial distribution characteristics of each sample, thereby preventing the majority class samples from excessively dominating the loss gradient and improving the model's recognition accuracy.
[0024] In one possible implementation, the training sample set is obtained by acquiring remote sensing data from satellites or drones. It should be noted that the training sample set includes positive samples representing target regions and negative samples representing background regions. The target region refers to the area in the remote sensing image data that needs to be segmented and labeled, while the background region refers to the unlabeled area in the remote sensing image data.
[0025] After obtaining the training sample set, the model to be trained needs to be pre-constructed. The model to be trained can be any neural network model, such as an image segmentation model or a change detection model. Furthermore, any construction method can be used to construct each model; there are no specific limitations.
[0026] After obtaining the pre-built model to be trained and the training sample set, each sample in the labeled training sample set is input into the model to be trained. The model to be trained outputs the target regions after segmentation of each sample and calculates the current loss function of the model to be trained. The parameters of the model to be trained are adjusted according to the current loss function.
[0027] In one possible implementation, the current loss function is calculated using the weights of each sample, and the weights of each sample are calculated based on the spatial distribution characteristics of each sample.
[0028] In one possible implementation, obtaining the spatial distribution characteristics of each sample includes: clustering the training sample set to obtain positive sample classes and negative sample classes; identifying positive sample cluster centers and negative sample cluster centers based on the positive sample classes and negative sample classes; calculating the intra-class distance between each positive sample and its cluster center, and the intra-class distance between each negative sample and its cluster center, based on the positive sample cluster centers and negative sample cluster centers, respectively; the calculated intra-class distances are the spatial distribution characteristics of each sample.
[0029] In this process, clustering of the training sample set is achieved through classification based on the labels of each sample in the training sample set. That is, each sample in the training sample set is labeled with positive and negative sample labels (such as target region and background region), and the positive and negative sample classes obtained by clustering are obtained by classifying the samples according to the sample labels.
[0030] This application uses an image segmentation model as an example to illustrate the specific process of clustering a training sample set. The image segmentation model includes an encoder and a decoder. When clustering the training sample set, the labeled training sample set is input into the encoder, which outputs the features of each sample based on initial parameters. Classifying each sample feature according to its label yields the positive and negative sample classes corresponding to the current training sample set.
[0031] After obtaining the positive and negative sample classes, it is necessary to determine the cluster centers of the positive and negative samples. This is done by calculating the mean of the features of each sample in both classes. Specifically, to determine the cluster centers of the positive samples, the mean of the positive sample features (e.g., a 512-dimensional feature vector) in the positive sample class will yield the cluster centers; similarly, the mean of the negative sample features (e.g., a 512-dimensional feature vector) in the negative sample class will yield the cluster centers of the negative samples.
[0032] Based on the confirmed positive and negative sample cluster centers, the intra-cluster distances of each positive sample to its cluster center and the intra-cluster distances of each negative sample to its cluster center can be calculated. This application calculates the intra-cluster distance of each sample by calculating the Euclidean distance between each sample and its cluster center. The calculation of Euclidean distance is common knowledge in the field and will not be elaborated upon here.
[0033] When calculating the intra-class distance for each sample, the calculated intra-class distance represents the spatial distribution characteristic of each sample. The weight of each sample can then be calculated based on its spatial distribution characteristic.
[0034] In one possible implementation, when calculating the weights of each sample based on the spatial distribution characteristics of each sample, the calculation includes at least one of the weights of each positive sample and the weights of each negative sample.
[0035] In calculating the weight of each positive sample based on the spatial distribution characteristics of each sample, the weight is obtained by acquiring the spatial distribution characteristics of each positive sample, and can be expressed by the following formula: in, This represents the adaptive attention weight for the i-th positive sample. For the first Spatial distribution characteristics of positive samples This is the weighting adjustment coefficient. To avoid the minimum value where the denominator is 0.
[0036] When calculating the weight of each negative sample based on the spatial distribution characteristics of each sample, the weight is obtained by acquiring the spatial distribution characteristics of each negative sample, and can be expressed by the following formula: in, This represents the adaptive attention weight for the i-th negative sample. For the first Spatial distribution characteristics of negative samples This is the weighting adjustment coefficient. To avoid the minimum value where the denominator is 0.
[0037] It should be noted that the weighting adjustment coefficient and Based on practical experience, it is determined that when setting the weight adjustment coefficient, the weight adjustment coefficient for positive samples should be greater than that for negative samples.
[0038] It should be further noted that traditional loss functions often calculate the weights of each sample based on a fixed-weight balancing strategy, which has certain limitations. For example, the existing weighted cross-entropy loss function can be expressed by the following formula: in, The total number of categories, For category The true label (one-hot encoding). For the model to class The predicted probability, For category The weighting coefficients. The calculation of these weighting coefficients allows for a shift from "experience-based weighting" to "data-driven weighting," with a typical adaptive calculation method being... ( The total number of samples, For category (sample size), or log-normalized form. ( For category (Global proportion), ensuring that the weight allocation is deeply adapted to the data distribution.
[0039] This method of calculating sample weights only balances the loss based on the number of categories, ignoring the differences in sample difficulty. In the majority class, the loss of a large number of easily distinguishable samples (such as a pure background without interference) can still mask the gradient contribution of difficult samples in the minority class (such as small targets with blurred edges), resulting in insufficient feature learning for difficult samples. This application, however, adaptively adjusts the weights of each sample through different weight calculation methods for positive and negative samples. Simultaneously, it incorporates the spatial distribution characteristics of the samples during weight calculation to dynamically adjust the contribution of positive and negative samples as well as the difficulty level of the samples, adapting to different degrees of imbalance (applicable to imbalance ratios from 10:1 to 100:1). That is, for minority class positive samples, attention weights are constructed by calculating the distance between the sample and the positive class cluster center, so that the "difficult positive samples" that are farther away are given higher weight allocation, guiding the model to focus on the calibration of the class boundary; for majority class negative samples, attention weights are generated by using the softmax normalization strategy of the inverse distance, suppressing the weights of "redundant negative samples" that are too close to the negative class cluster center, while strengthening the constraint of "difficult negative samples" that are close to the positive class samples, so as to avoid the majority class samples from overdoing the loss gradient.
[0040] After obtaining the weights of each sample based on the above operations, the next step is to calculate the current loss function of the model to be trained based on the weights of each sample.
[0041] In one possible implementation, when calculating the current loss function of the model to be trained based on the weights of each sample, the process includes: obtaining the weights of each sample and calculating the values of the positive sample guiding term and the negative sample constraint term respectively; and calculating the current loss function based on the values of the positive sample guiding term and the negative sample constraint term. Specifically, obtaining the weights of each sample and calculating the values of the positive sample guiding term and the negative sample constraint term respectively includes: extracting the weights of each positive sample and each negative sample from the weights of each sample; calculating the value of the positive sample guiding term based on the weights of each positive sample; and calculating the value of the negative sample constraint term based on the weights of each negative sample.
[0042] After obtaining the weights of each positive sample, the value of the positive sample guiding term can be calculated based on these weights, which can be expressed by the formula: In the formula, This represents the value of the positive sample guide term. For the positive sample set, The number of positive samples; The threshold value for intra-class distance of positive samples constrains the compactness of positive sample clustering, and Based on experience, the larger the value, the better the model training effect; the preferred value is 0.3. Temperature coefficient: used to adjust the gradient smoothness of the loss function and balance the model's focus on easy and difficult samples.
[0043] After obtaining the weights of each negative sample, the value of the negative sample constraint term can be calculated based on these weights, which can be expressed by the formula: In the formula, This represents the value of the negative sample constraint term. For the negative sample set, The number of negative samples satisfies ; This is the inter-class distance threshold for negative samples, ensuring the separability of negative and positive sample classes. Based on experience, the larger the value, the better the model training effect; the preferred value is 0.3. It is also a temperature coefficient, used to adjust the gradient smoothness of the loss function, balancing the model's focus on both easy and difficult samples. The initial value is 1, and it can be adjusted according to the difficulty of the samples during subsequent training. That is, under normal circumstances, T=1 can meet the training needs of simple or ordinary samples. In training scenarios with more difficult samples or when the loss function has not converged after the model has undergone multiple rounds of training, the temperature T can be appropriately lowered. After adjustment, the value range of T can be set to 0.01-0.9.
[0044] Based on the positive sample guiding term and the negative sample constraint term mentioned above, the current loss function can be calculated, which can be expressed by the formula: In the formula, This represents the current loss function of the model to be trained.
[0045] It should be noted that the loss function of this application is based on the three-in-one design paradigm of "dynamic weight allocation - enhanced class cohesion - guaranteed class separability". By introducing an adaptive attention mechanism (adaptively adjusting the weight of samples based on the spatial distribution characteristics of samples) to deconstruct the heterogeneity of sample distribution, and by using a contrastive learning framework (comparing and calculating positive sample guiding terms and negative sample constraint terms) to strengthen the semantic boundary of categories, the model's generalization ability under imbalanced data is accurately improved.
[0046] In other words, the loss function in this application strengthens positive class cohesion and negative class dispersion through piecewise contrastive constraints (i.e., a contrastive learning framework), effectively preventing the decision boundary from shifting towards the minority class and improving the model's accuracy in identifying minority class samples. Specifically, the positive sample guiding term... Using the exponential function as the core, when the intra-class distance of positive samples exceeds a threshold... At that time, the loss value grows exponentially, forcing the model to compress the positive class cohesion distance; negative sample constraint terms The reverse constraint significantly increases the loss value when the distance between a negative sample and the center of the negative class is less than a threshold ω, promoting the effective dispersion of negative samples and clarifying the boundaries between positive and negative classes. The introduction of the temperature coefficient T further optimizes the distribution characteristics of the loss gradient, reducing the impact of difficult samples on model training in extremely imbalanced scenarios while ensuring the effectiveness of gradient descent.
[0047] The parameters of the model to be trained are adjusted based on the calculated loss function, and the above training process is repeated based on the adjusted model. The model training ends when the loss function converges. Any adjustment method can be used when adjusting the model parameters based on the loss function; no specific limitation is imposed.
[0048] For example, after calculating the current loss function of the image segmentation model based on the above process, the encoder parameters are adjusted using backpropagation based on the current loss function. Then, based on the adjusted parameters, the encoder repeats the above training process until the loss function converges, and the encoder training ends. In this embodiment, the model generation process is trained based on the loss function of this application, which improves the segmentation accuracy of the model when the encoder performs region segmentation based on imbalanced sample data.
[0049] Based on this, this application provides a model training method based on an adaptive attention-weighted contrastive loss function for training a model to be trained. The method includes: acquiring a training sample set and a pre-constructed model to be trained; wherein the training sample set includes positive samples as target regions and negative samples as background regions; inputting the training sample set into the target region segmented by the model to be trained, and calculating the current loss function of the model to be trained, adjusting the parameters of the model to be trained according to the current loss function; repeating the above training process based on the adjusted model to be trained, and ending model training when the loss function converges; wherein, when calculating the current loss function of the model to be trained, it is calculated using the weights of each sample; and the weights of each sample are calculated based on the spatial distribution characteristics of each sample. This application proposes a novel loss function for model training, namely, an adaptive attention-weighted contrastive loss function. This loss function incorporates the spatial distribution characteristics of each sample into the calculation of sample weights when positive and negative samples are imbalanced, allowing the weights of samples to be adaptively adjusted based on the spatial distribution characteristics of each sample when positive and negative samples are imbalanced. This enables the model to avoid excessive dominance of the loss gradient by the majority class samples, thereby improving the model's recognition accuracy.
[0050] Furthermore, the loss function in this application achieves closed-loop optimization of "data distribution awareness - adaptive weight adjustment - class boundary optimization". Through refined mining and constraint of sample semantic features, the model can adaptively learn more discriminative feature representations in imbalanced data scenarios, effectively alleviating the overfitting problem caused by majority class dominance, and providing an efficient loss optimization scheme for modeling tasks of high-dimensional, strongly heterogeneous and imbalanced data. Moreover, the loss function in this application is controllable through adaptive weight allocation, strong class boundary constraints, and gradient smoothing. Specifically, adaptive weight allocation: without manual pre-setting of class weights, it dynamically adjusts the contribution of positive and negative samples and easy and difficult samples based on the sample space distribution, adapting to different degrees of imbalance scenarios (applicable to imbalance ratios of 10:1 to 100:1). Strong class boundary constraints: by strengthening positive class cohesion and negative class dispersion through a contrastive learning framework, it effectively avoids the decision boundary shifting towards the minority class, improving the model's recognition accuracy for minority class samples. Controllable gradient smoothing: the temperature coefficient can flexibly adjust the gradient change rate, balancing the model's learning ability for easy and difficult samples, and improving the stability and convergence efficiency of the training process.
[0051] <Device Embodiment> Figure 2 A schematic block diagram of a model training apparatus for an adaptive attention-weighted contrastive loss function according to an embodiment of this application is shown. Figure 2As shown, the device 100 is used to train a model to be trained, and the device 100 includes: a data acquisition module 110, a model training module 120, and an iteration module 130. The data acquisition module 110 is used to acquire a training sample set and a pre-built model to be trained; wherein the training sample set includes positive samples as target regions and negative samples as background regions; the model training module 120 is used to input the training sample set into the target region segmented by the model to be trained, calculate the current loss function of the model to be trained, and adjust the parameters of the model to be trained according to the current loss function; the iteration module 130 is used to repeat the above training process based on the adjusted model to be trained, and the model training ends when the loss function converges; wherein, when calculating the current loss function of the model to be trained, it is calculated using the weights of each sample; and the weights of each sample are calculated based on the spatial distribution characteristics of each sample.
[0052] <Equipment Example> Figure 3 A schematic block diagram of a model training apparatus with an adaptive attention-weighted contrastive loss function according to an embodiment of this application is shown. Figure 3 As shown, the model training device 200 for the adaptive attention-weighted contrastive loss function includes a processor 210 and a memory 220 for storing executable instructions of the processor 210. The processor 210 is configured to implement any of the aforementioned adaptive attention-weighted contrastive loss function model training methods when executing the executable instructions.
[0053] It should be noted here that the number of processors 210 can be one or more. Furthermore, the model training device 200 for the adaptive attention-weighted contrastive loss function in this embodiment may also include an input device 230 and an output device 240. The processors 210, memory 220, input device 230, and output device 240 can be connected via a bus or other means, which are not specifically limited here.
[0054] The memory 220, as a computer-readable storage medium, can be used to store software programs, computer-executable programs, and various modules, such as the program or module corresponding to the adaptive attention-weighted contrastive loss function model training method in this application embodiment. The processor 210 executes various functional applications and data processing of the adaptive attention-weighted contrastive loss function model training device 200 by running the software program or module stored in the memory 220.
[0055] Input device 230 can be used to receive input digital numbers or signals. These signals may include key signals related to user settings and function control of the device / terminal / server. Output device 240 may include a display device such as a screen.
[0056] <Storage Medium Examples> According to a fourth aspect of this application, a non-volatile computer-readable storage medium is also provided, on which computer program instructions are stored, which, when executed by processor 210, implement a model training method for any of the aforementioned adaptive attention-weighted contrastive loss functions.
[0057] The various embodiments of this application have been described above. These descriptions are exemplary and not exhaustive, nor are they limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical applications, or technological improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.
Claims
1. A model training method based on an adaptive attention-weighted contrastive loss function, characterized in that, Used for training the model to be trained, including: Obtain a training sample set and the pre-constructed model to be trained; wherein the training sample set includes positive samples as target regions and negative samples as background regions; The training sample set is input into the target region of the model to be trained, and the current loss function of the model to be trained is calculated. The parameters of the model to be trained are adjusted according to the current loss function. The above training process is repeated based on the adjusted model to be trained, and the model training ends when the loss function converges. Specifically, when calculating the current loss function of the model to be trained, it is obtained by calculating the weights of each sample; and the weights of each sample are calculated based on the spatial distribution characteristics of each sample.
2. The method according to claim 1, characterized in that, When obtaining the spatial distribution characteristics of each of the samples, the following are included: The training sample set is clustered to obtain positive sample class and negative sample class; Based on the positive sample class and the negative sample class, the positive sample cluster center and the negative sample cluster center are determined; Based on the positive sample cluster centers and the negative sample cluster centers, calculate the intra-class distance between each positive sample and its cluster center, and the intra-class distance between each negative sample and its cluster center; the calculated intra-class distance is the spatial distribution feature of each sample.
3. The method according to claim 1, characterized in that, When calculating the weight of each sample based on the spatial distribution characteristics of each sample, it includes calculating at least one of the weights of each positive sample and the weights of each negative sample.
4. The method according to claim 3, characterized in that, When calculating the weights of the positive samples based on the aforementioned spatial distribution characteristics, the formula can be expressed as follows: in, This represents the adaptive attention weight for the i-th positive sample. For the first Spatial distribution characteristics of positive samples This is the weighting adjustment coefficient. To avoid the minimum value where the denominator is 0.
5. The method according to claim 3, characterized in that, When calculating the weights of the negative samples based on the aforementioned spatial distribution characteristics, the formula can be expressed as follows: in, This represents the adaptive attention weight for the i-th negative sample. For the first Spatial distribution characteristics of negative samples This is the weighting adjustment coefficient. To avoid the minimum value where the denominator is 0.
6. The method according to claim 1, characterized in that, When calculating the current loss function of the model to be trained based on the weights of each sample, the following steps are included: The weights of each sample are obtained, and the values of the positive sample guiding term and the negative sample constraint term are calculated respectively. The current loss function is calculated based on the values of the positive sample guiding term and the negative sample constraint term.
7. The method according to any one of claims 1 to 6, characterized in that, When calculating the values of the positive sample guiding term and the negative sample constraint term by obtaining the weights of each sample, the following steps are included: The weights of each positive sample and each negative sample are extracted from the weights of each sample. The value of the positive sample guiding term is calculated based on the weight of each positive sample; The value of the negative sample constraint term is calculated based on the weight of each negative sample.
8. A model training device based on an adaptive attention-weighted contrastive loss function, characterized in that, Used for training the model to be trained, including: The data acquisition module is used to acquire a training sample set and a pre-built model to be trained; wherein, the training sample set includes positive samples as target regions and negative samples as background regions; The model training module is used to input the training sample set into the target region segmented by the model to be trained, calculate the current loss function of the model to be trained, and adjust the parameters of the model to be trained according to the current loss function. An iterative module is used to repeat the above training process based on the adjusted model to be trained, and the model training ends when the loss function converges. Specifically, when calculating the current loss function of the model to be trained, it is obtained by calculating the weights of each sample; and the weights of each sample are calculated based on the spatial distribution characteristics of each sample.
9. A model training device based on an adaptive attention-weighted contrastive loss function, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor is configured to implement the method of any one of claims 1 to 7 when executing the executable instructions.
10. A non-volatile computer-readable storage medium storing computer program instructions thereon, characterized in that, When the computer program instructions are executed by the processor, they implement the method described in any one of claims 1 to 7.