Target detection model training method, target detection method, device and equipment
By establishing geometric constraints across hierarchical features and employing a multi-granularity target detection model training method, the problems of high false negative rates for small targets and cross-scale mismatches are solved, thereby improving the accuracy and generalization ability of the target detection model.
Patent Information
- Application Number
- CN202511017933.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-23
- Publication Date
- 2025-11-21
AI Technical Summary
Existing target detection methods suffer from high false negative rates for small targets, mismatches across scales, and poor model generalization, with performance dropping sharply, especially in extreme scale-varying scenarios such as UAV images and satellite images.
By establishing geometric constraints on cross-level features, a multi-granularity target detection model training method is adopted, including multi-scale feature extraction, feature projection, hierarchical ranking loss calculation, and dynamic weight control, to improve the feature discrimination of multi-scale targets.
It reduced the false negative and false positive rates, and improved the accuracy and generalization ability of the model in multi-scale target detection.
Smart Images

Figure CN120997615A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of target detection technology, and in particular to a target detection model training method, target detection method, apparatus, equipment and medium. Background Technology
[0002] Object detection is a fundamental task in computer vision, involving identifying objects in images and determining their locations. Over the past two decades, object detection technology has undergone a major transformation from traditional methods to deep learning. This transformation has not only driven the development of computer vision technology but also provided strong support for various practical applications.
[0003] Existing object detection methods are mainly implemented through feature pyramid networks. However, the small and large object features output by the feature pyramid are distributed chaotically in the embedding space, which leads to the defect of inconsistency in the cross-level feature space. Existing object detection methods also have the following defects: (1) High false negative rate for small objects: The chaotic feature space makes them easy to be misclassified as background during classification; (2) Cross-scale mismatch: Large objects and small objects with similar semantics (such as pedestrians in the distance) are misdetected due to feature similarity; (3) Poor model generalization: The performance drops sharply in scenarios such as UAV images (dominated by small objects) or satellite images (extreme scale changes). Summary of the Invention
[0004] This application provides a target detection and model training method, apparatus, and medium that can establish geometric constraint relationships across features, improve the feature discrimination of multi-scale targets, and reduce the false negative rate and the probability of false positives.
[0005] This application provides a method for training an object detection model, including: The image is input into the multi-scale feature extraction module for feature extraction, resulting in multi-level features. The multi-level features are input into the feature projection module for projection mapping to obtain the projected features of each level. The projected features of each level are input into the hierarchical ranking loss module. Based on the projected features of each level and the corresponding label, the intra-granularity ranking loss, cross-granularity alignment loss and multi-granularity contrast loss are calculated. The weights of intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss are calculated using a dynamic weight controller, and the total loss is obtained. The target detection model is iteratively trained based on the total loss until the target detection model converges, thus obtaining a trained target detection model.
[0006] Furthermore, according to the above-described target detection model training method, the multi-level features are input into the feature projection module for projection mapping to obtain the projected features of each level, including: Flatten the features of each level along the spatial dimension to obtain the first vector; The first vector is mapped to a multidimensional hidden space and an activation function is applied to obtain the first layer of linear transformation results; The first-level linear transformation result is dimensionally compressed to obtain the second-level linear transformation result; The result of the second-level linear transformation is normalized to obtain the corresponding projected features.
[0007] Furthermore, according to the above-mentioned target detection model training method, the hierarchical ranking loss module includes an intra-granularity ranking sub-module, a cross-granularity alignment sub-module, and a multi-granularity comparison sub-module. The processing procedure of the hierarchical ranking loss module includes: In the granular ranking submodule, multiple anchor points are randomly selected in each level, and each anchor point is matched. The projected features of each level are divided into two categories: positive samples and negative samples. The granular ranking loss is calculated based on the positive samples, negative samples and corresponding labels. In the cross-granularity alignment submodule, the projected features of adjacent levels are aligned, and the cross-granularity alignment loss is calculated. In the multi-granularity contrast submodule, a global dictionary is constructed based on the projected features of all levels to determine positive and negative samples, and the multi-granularity contrast loss is calculated based on the positive and negative samples.
[0008] This application also provides a target detection method, including: The image to be detected is input into the multi-scale feature extraction module for feature extraction, resulting in multi-level features. The multi-level features are input into the detection head to obtain the target detection result; wherein, the multi-scale feature extraction module and the detection head are obtained through the above-mentioned target detection model training method.
[0009] Furthermore, according to the above target detection method, the multi-scale feature extraction module includes a backbone network and a feature pyramid network, and the processing procedure of the multi-scale feature extraction module includes: The image to be detected is input into the backbone network for feature extraction to obtain a preliminary feature map; The preliminary feature map is input into the feature pyramid network to obtain multi-level features.
[0010] This application also provides an object detection model training device, including: The multi-scale feature extraction module is used to extract features from images and obtain multi-level features; The feature projection module is used to project and map the multi-level features to obtain the projected features of each level. The hierarchical ranking loss module is used to calculate the intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss based on the projected features and corresponding labels of each level. A dynamic weight controller is used to calculate the weights of intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss, and to obtain the total loss. The iterative training module is used to iteratively train the target detection model based on the total loss until the target detection model converges, thus obtaining a trained target detection model.
[0011] This application also provides a target detection device, including: The multi-scale feature extraction module is used to extract features from the image to be detected, obtaining multi-level features. The detection head is used to obtain target detection results based on the multi-level features; wherein, the multi-scale feature extraction module and the detection head are obtained through the above-mentioned target detection model training method.
[0012] This application also provides a computer-readable storage medium storing a plurality of instructions adapted for loading by a processor to execute any of the above-described object detection model training methods or object detection methods.
[0013] This application also provides an electronic device, including a processor and a memory, wherein the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used in any of the steps of the target detection model training method or the target detection method described above.
[0014] This application also provides a computer program product containing instructions that, when the computer program product is run on a computer or processor, cause the computer or processor to perform the steps in any of the above-described target detection model training methods or target detection methods.
[0015] This application provides a target detection model training method, target detection method, apparatus, device, and medium. The application calculates intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss through a hierarchical ranking loss module in the target detection model. Based on these losses, a total loss is calculated, and the target detection model is trained using this total loss. The trained target detection model then achieves multi-granularity target detection. This application can establish geometric constraints across hierarchical features, improve the feature discriminative power of multi-scale targets, dynamically balance the contribution of different granularity features to the loss, and reduce gradient conflicts between classification and localization tasks. Attached Figure Description
[0016] The technical solution and other beneficial effects of this application will become apparent from the following detailed description of specific embodiments in conjunction with the accompanying drawings.
[0017] Figure 1 A flowchart illustrating the target detection model training method provided in this application embodiment.
[0018] Figure 2 This is a schematic diagram of the hierarchical feature space geometric constraints provided in the embodiments of this application.
[0019] Figure 3 This is a schematic diagram of the structure of the target detection model training device provided in the embodiments of this application.
[0020] Figure 4 This application provides a schematic diagram of the target detection device.
[0021] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0022] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0023] The existing technology has the following drawbacks: Disadvantage 1: Inconsistency in feature spaces across different levels Phenomenon: The P3 (small target) and P7 (large target) features output by the Feature Pyramid Network (FPN) are randomly distributed in the embedding space.
[0024] Disadvantage 2: Static loss weights are difficult to adapt to scale changes. Phenomenon: Manually set hierarchical loss weights (such as P3:P5:P7=1:1:1) fail in extreme scale distribution scenarios (such as dense small targets).
[0025] Disadvantage 3: The learning and testing tasks are disconnected. Phenomenon: Directly applying instance-based comparative learning (such as MoCo) can lead to the small target features being dominated by the large target.
[0026] The above-mentioned drawbacks collectively lead to: 1. High false negative rate for small targets: The chaotic feature space makes them easy to be misclassified as background during classification; 2. Cross-scale mismatch: Large targets and small targets with similar semantics (such as pedestrians in the distance) are misdetected due to feature similarity; 3. Poor model generalization: The performance drops sharply in scenarios such as drone images (dominated by small targets) or satellite images (extreme scale changes).
[0027] To address the aforementioned problems, embodiments of this application provide a method for training an object detection model, an object detection method, an apparatus, a device, and a medium. The object detection model training apparatus provided in this application can be integrated into an electronic device, which may be a terminal, a server, or other such device. The terminal may include a tablet computer, a laptop computer, a personal computer (PC), a microprocessor box, or other devices.
[0028] Please see Figure 1 , Figure 1 The flowchart illustrates a target detection model training method provided in this application embodiment, which is applied in electronic devices. This multi-granularity target detection method based on hierarchical ranking loss includes the following steps: S11: Input the image into the multi-scale feature extraction module for feature extraction to obtain multi-level features.
[0029] In one embodiment, the multi-scale feature extraction module includes a backbone network and a feature pyramid network, and the processing procedure of the multi-scale feature extraction module includes: S111: Input the images from the image dataset into the backbone network for feature extraction to obtain preliminary feature maps.
[0030] Image to be detected The input is fed into the backbone network ResNet-50 (with the last fully connected layer removed) to obtain preliminary feature maps {C3, C4, C5} with strides of {8, 16, 32} pixels.
[0031] S112, the preliminary feature map is input into the feature pyramid network to obtain multi-level features.
[0032] Pyramid levels {P3, P4, P5, P6, P7} are generated using a pyramid network, with resolution ranging from... to .
[0033] in,
[0034] S12, input the multi-level features into the feature projection module for projection mapping to obtain the projected features of each level.
[0035] The feature projection module is a two-layer MLP (Multilayer Perceptron) with shared weights, used to map the multi-level features {P3, P4, P5, P6, P7} output by the FPN to a unified 128-dimensional hyperspherical space. This ensures the comparability of features at different scales and provides a geometric constraint basis for subsequent hierarchical ranking loss calculations. This process can be expressed by the following equation:
[0036] in, , , The projected features are 128-dimensional unit vectors (in hyperspherical space).
[0037] In one embodiment, step S22 includes the following steps: S121, flatten the features of each level along the spatial dimension to obtain the first vector.
[0038] For each level of features Taking global average pooling (GAP) along the spatial dimension yields a 256-dimensional vector:
[0039] in, The height of the feature map, This represents the width of the feature map.
[0040] The purpose of feature flattening is to preserve channel semantic information and eliminate the influence of spatial location.
[0041] S122, map the first vector to the multidimensional hidden space and apply the activation function to obtain the first layer linear transformation result.
[0042] A 256-dimensional vector is mapped to a 256-dimensional hidden space using a fully connected layer, and ReLU activation is applied:
[0043] in, The learnable weight matrix is initialized using the Kaiming normal distribution. This is a bias term, initialized to 0.
[0044] S123, dimensionality compression is performed on the first-level linear transformation result to obtain the second-level linear transformation result.
[0045] Compress the hidden layer output to 128 dimensions:
[0046] in, The learnable weight matrix is initialized using the Kaiming normal distribution. This is a bias term, initialized to 0.
[0047] Design intent: Dimensionality reduction reduces computational cost while preserving distinctive features.
[0048] S124, normalize the result of the second-level linear transformation to obtain the corresponding projected features.
[0049] Project the output vector onto the unit hypersphere:
[0050] Effect: Constraining the feature vectors to a hypersphere transforms similarity calculation into a comparison of cosine values.
[0051] S13: Input the projected features of each level into the hierarchical ranking loss module, and calculate the intra-granularity ranking loss, cross-granularity alignment loss and multi-granularity contrast loss based on the projected features of each level and the corresponding label.
[0052] The input to the hierarchical ranking loss module is the projected features. and the corresponding ground truth labels (i.e., the true labels). The projected features are for each level. (like , The input to the current layer contains only the projected features. Not features at all levels. For example: calculating When there is a loss, only use .
[0053] Corresponding Labels: Labels (category and bounding box) must match the target size at the current level. Small targets (such as pedestrians) should be prioritized by Detection and tag assignment to P3, with large targets (such as vehicles) given priority. Detection, label assignment Table 1 shows the matching rules between levels and targets.
[0054] Table 1 Matching Rules between Levels and Targets
[0055] In one embodiment, the hierarchical ranking loss module includes an intra-granularity ranking submodule, a cross-granularity alignment submodule, and a multi-granularity comparison submodule. The processing procedure of the hierarchical ranking loss module includes: S131, in the granular ranking submodule, multiple anchor points are randomly selected in each level, and each anchor point is matched. The projected features of each level are divided into two categories: positive samples and negative samples. The granular ranking loss is calculated based on the positive samples, negative samples and corresponding labels.
[0056] In this context, anchor points refer to pre-defined bounding boxes. The process involves determining whether an anchor point contains a target within that bounding box, and then fine-tuning the anchor point's coordinates to obtain a precise bounding box. Specifically, anchor point matching is performed by calculating the Intersection over Union (IoU).
[0057] Positive samples are ground truth features of the same category and level, while negative samples are features of different categories at the same level (hard example mining, IoU < 0.3). The intra-granular ranking loss is:
[0058] in, This represents the feature vector of the k-th target extracted for level i. This represents the feature vector of the negative sample for level i. This represents the feature vector of a positive sample for level i. N For the number of anchor points, m As a hyperparameter, in one specific embodiment m =0.5.
[0059] S132, in the cross-granularity alignment submodule, align the projected features of adjacent levels and calculate the cross-granularity alignment loss.
[0060] The alignment target is the angle between the directions of the projected feature vectors of the same target in adjacent layers. By minimizing their cosine distance, consistency of features between levels can be achieved.
[0061] Figure 2 This is a schematic diagram of the hierarchical feature space geometric constraints provided in the embodiments of this application.
[0062] The cross-granularity alignment loss is:
[0063] in, For indicator functions, , These are the predicted bounding boxes for the i-th and i+1-th layers (obtained by decoding the layer features using the detection head of that layer). , These are the projected features of adjacent levels.
[0064] In one embodiment, the cross-granularity alignment loss can also be calculated based on Euclidean distance:
[0065] in, This is the distance threshold, and the initial value can be 1.2.
[0066] S133, in the multi-granularity contrast submodule, a global dictionary is constructed based on the projected features of all levels to determine positive and negative samples, and multi-granularity contrast loss is calculated based on the positive and negative samples.
[0067] Features of the global dictionary: (1) Input features Source module: Output features of projection heads at all levels (i.e., features processed by the projection head). Specifically, it includes: ,in, (After L2 normalization).
[0068] Hierarchical independence: Features at each level are projected independently, but share the same projection head weights.
[0069] (2) Feature selection Use only the features of the current batch: During each iteration, store the features of all levels in the current batch into queue Q.
[0070] Excludes unprojected original features: ensures all features are comparable in the same hyperspherical space.
[0071] The role and operation of queue Q (1) Queue initialization Length: Fixed size (e.g., 10,240), managed according to FIFO (First In First Out).
[0072] Filling method: Gradually fill the queue during the early stages of training. When the queue is not full, it is directly stored. When it is full, the oldest feature is replaced.
[0073] (2) Operations after deposit Loss is not calculated immediately: the queue is only used as a dynamic memory to store historical features for comparative learning.
[0074] Calculation timing: When it is necessary to calculate the loss, negative samples are randomly sampled from the queue (as detailed below).
[0075] (3) No further operations are performed after the deposit, because... Efficiency considerations: Real-time calculation of the similarity of all historical features is costly, and the queue only maintains copies of the features.
[0076] Decoupled design: The queue is only responsible for storage, and the loss is dynamically sampled during calculation to avoid redundant calculation.
[0077] Gradient isolation: Features in the queue are shielded from backpropagation of gradients by stop_gradient to prevent interference with model training.
[0078] Specifically, positive samples are features of the same target at different levels, while negative samples are features of different targets in queue Q (random sampling or all features used). The multi-granularity contrastive loss is:
[0079] in, For positive sample features, For negative sample features, This represents the input feature vector of the i-th layer. This is the temperature coefficient (usually set to 0.1).
[0080] In one embodiment, attention mechanisms can also be used to replace geometric constraints, and the specific implementation process is expressed by the following formula:
[0081] S14 calculates the weights of intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss using a dynamic weight controller, and obtains the total loss.
[0082] The dynamic weight controller is used to calculate the weights of the three hierarchical ranking losses: intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss. The total loss is:
[0083] in, , , These are the weights for intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity comparison loss, respectively.
[0084] The specific calculation process is as follows: a) Set learnable log-weight parameters And initialize it to 0; b) The logarithmic weight parameters are converted into actual weights using Softmax. The calculation process is as follows:
[0085] Guarantee weight
[0086] c) Automatic adjustment via the chain rule during gradient backpropagation. .
[0087] S15, iteratively train the object detection model based on the total loss until the object detection model converges, and obtain the trained object detection model.
[0088] Specifically, the training process is divided into two stages: Phase 1 (Feature Space Initialization): Freeze the backbone network and train only the projection head and loss module.
[0089] The configuration of each module is as follows: Optimizer: AdamW (lr=1e-4, weight_decay=1e-4) Batch Size: 16 (4 GPUs × 4 images / GPU) The goal of Phase 1 is to initially establish the hierarchical feature geometric relationships.
[0090] Phase 2 (Joint Fine-tuning): Unfreeze the backbone network and train end-to-end. Learning rate strategy: Cosine decay (minimum lr = 1e-5) Key configuration: Gradient clipping (max_norm=1.0) Loss weights : : =1:1:0.3.
[0091] The iteration standard is as follows: early stopping mechanism: training is terminated if the AP on the validation set does not improve for 5 consecutive epochs.
[0092] In one embodiment, this application also provides a target detection method, which includes the following steps: A1, input the image to be detected into the multi-scale feature extraction module for feature extraction to obtain multi-level features; A2 inputs multi-level features into the detection head to obtain the target detection result. The multi-scale feature extraction module and the detection head are obtained using the target detection model training method described above.
[0093] The processing procedure of the multi-scale feature extraction module is similar to that of the training procedure, and will not be described in detail here.
[0094] In one embodiment, the detection head includes a classification head and a regression head. Multi-level features are input into the detection head to obtain target detection results, including: Multi-level features are input into the classification head for convolution operations and then passed through an activation function to obtain the class probability of the object detection. The multi-level input is fed into the regression head to obtain the predicted target box offset, and the predicted target box is corrected by the predicted target box offset. Evaluation of predicted target boxes based on maximum suppression.
[0095] Based on the method described in the above embodiments, this embodiment will further describe it from the perspective of the target detection model training device. The target detection model training device can be implemented as an independent entity or integrated into an electronic device. The electronic device can be a terminal, server, or other devices. The terminal can include a tablet computer, a laptop computer, a personal computer (PC), a microprocessor box, or other devices.
[0096] Please see Figure 3 , Figure 3 This application provides a specific description of a target detection model training device, which is applied in an electronic device. The target detection model training device may include: The multi-scale feature extraction module is used to extract features from images and obtain multi-level features; The feature projection module is used to project and map multi-level features to obtain the projected features of each level. The hierarchical ranking loss module is used to calculate the intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss based on the projected features and corresponding labels of each level. A dynamic weight controller is used to calculate the weights of intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss, and to obtain the total loss. The iterative training module is used to iteratively train the target detection model using the base loss until the target detection model converges, thus obtaining a trained target detection model.
[0097] Please see Figure 4 , Figure 4 This application provides a specific description of a target detection device, which is applied in an electronic device and may include: The multi-scale feature extraction module is used to extract features from the image to be detected, obtaining multi-level features. The detection head is used to obtain target detection results based on multi-level features; the multi-scale feature extraction module and the detection head are obtained through the target detection model training method described above.
[0098] In specific implementation, the above modules and / or units can be implemented as independent entities, or they can be arbitrarily combined and implemented as the same or several entities. For the specific implementation of the above modules and / or units, please refer to the previous method embodiments. For the specific beneficial effects that can be achieved, please also refer to the beneficial effects in the previous method embodiments, which will not be repeated here.
[0099] In addition, this application also provides an electronic device, which may be a computer, tablet computer, or other similar device. This electronic device can implement the steps of the target detection model training method or any embodiment of the target detection method provided in this application. Therefore, it can achieve the beneficial effects that any target detection model training method or target detection method provided in this invention can achieve, as detailed in the preceding embodiments, and will not be repeated here.
[0100] Figure 5 This diagram illustrates a specific structural block diagram of an electronic device provided in an embodiment of the present invention. This electronic device can be used to implement the target detection model training method or target detection method provided in the above embodiments. The electronic device can be a terminal, server, or other device. The terminal can include a tablet computer, laptop computer, personal computer (PC), microprocessor box, or other devices. Figure 4 As shown, the electronic device includes a processor and a memory. The processor and memory are electrically connected. The processor is the control center of the electronic device, connecting all parts of the device through various interfaces and lines. By running or loading applications stored in the memory and calling data stored in the memory, it performs various functions and processes data, thereby monitoring the electronic device as a whole.
[0101] In this embodiment, the processor in the electronic device loads the instructions corresponding to the processes of one or more applications into the memory according to the following steps, and then the processor runs the applications stored in the memory to achieve various functions: The image is input into the multi-scale feature extraction module for feature extraction, resulting in multi-level features. Multi-level features are input into the feature projection module for projection mapping to obtain the projected features of each level. The projected features of each level are input into the hierarchical ranking loss module. Based on the projected features of each level and the corresponding label, the intra-granularity ranking loss, cross-granularity alignment loss and multi-granularity contrast loss are calculated. The weights of intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss are calculated using a dynamic weight controller, and the total loss is obtained. The target detection model is iteratively trained based on the total loss until the target detection model converges, resulting in a well-trained target detection model.
[0102] or, The image to be detected is input into the multi-scale feature extraction module for feature extraction, resulting in multi-level features. Multi-level features are input into the detection head to obtain the target detection result; wherein, the multi-scale feature extraction module and the detection head are obtained through the target detection model training method.
[0103] In practice, the above modules can be implemented as independent entities or combined in any way to be implemented as the same or several entities. For the specific implementation of the above modules, please refer to the previous method implementation examples, which will not be repeated here.
[0104] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by instructions, or by instructions controlling related hardware. These instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. Therefore, embodiments of the present invention provide a storage medium storing multiple instructions that can be loaded by a processor to execute the steps of any embodiment of the multi-granularity target detection method based on hierarchical ranking loss provided by the present invention.
[0105] The computer-readable storage medium may include: read-only memory (ROM), random access memory (RAM), disk or optical disk, etc.
[0106] Since the instructions stored in the storage medium can execute the steps of the target detection model training method or any embodiment of the target detection method provided in the embodiments of the present invention, the beneficial effects that the target detection model training method or target detection method provided in the embodiments of the present invention can achieve can be realized. For details, please refer to the previous embodiments, which will not be repeated here.
[0107] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this specification are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in or transmitted through a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The aforementioned available media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital versatile discs (DVDs)), or semiconductor media (e.g., solid-state drives (SSDs)).
[0108] The above provides a detailed description of the target detection model training method, target detection method, apparatus, device, and medium provided in the embodiments of this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the above embodiments are only for the purpose of helping to understand the methods and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A method for training an object detection model, comprising: The image is input into the multi-scale feature extraction module for feature extraction, resulting in multi-level features. The multi-level features are input into the feature projection module for projection mapping to obtain the projected features of each level. The projected features of each level are input into the hierarchical ranking loss module. Based on the projected features of each level and the corresponding label, the intra-granularity ranking loss, cross-granularity alignment loss and multi-granularity contrast loss are calculated. The weights of intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss are calculated using a dynamic weight controller, and the total loss is obtained. The target detection model is iteratively trained based on the total loss until the target detection model converges, thus obtaining a trained target detection model.
2. The target detection model training method according to claim 1, characterized in that, The multi-level features are input into the feature projection module for projection mapping to obtain the projected features of each level, including: Flatten the features of each level along the spatial dimension to obtain the first vector; The first vector is mapped to a multidimensional hidden space and an activation function is applied to obtain the first layer of linear transformation results; The first-level linear transformation result is dimensionally compressed to obtain the second-level linear transformation result; The result of the second-level linear transformation is normalized to obtain the corresponding projected features.
3. The target detection model training method according to claim 1, characterized in that, The hierarchical ranking loss module includes an intra-granularity ranking submodule, a cross-granularity alignment submodule, and a multi-granularity comparison submodule. The processing procedure of the hierarchical ranking loss module includes: In the granular ranking submodule, multiple anchor points are randomly selected in each level, and each anchor point is matched. The projected features of each level are divided into two categories: positive samples and negative samples. The granular ranking loss is calculated based on the positive samples, negative samples and corresponding labels. In the cross-granularity alignment submodule, the projected features of adjacent levels are aligned, and the cross-granularity alignment loss is calculated. In the multi-granularity contrast submodule, a global dictionary is constructed based on the projected features of all levels to determine positive and negative samples, and the multi-granularity contrast loss is calculated based on the positive and negative samples.
4. A target detection method, characterized in that, The method includes: The image to be detected is input into the multi-scale feature extraction module for feature extraction, resulting in multi-level features. The multi-level features are input into the detection head to obtain the target detection result; wherein, the multi-scale feature extraction module and the detection head are obtained by the target detection model training method according to any one of claims 1-3.
5. The target detection method according to claim 4, characterized in that, The multi-scale feature extraction module includes a backbone network and a feature pyramid network. The processing steps of the multi-scale feature extraction module include: The image to be detected is input into the backbone network for feature extraction to obtain a preliminary feature map; The preliminary feature map is input into the feature pyramid network to obtain multi-level features.
6. A target detection model training device, characterized in that, include: The multi-scale feature extraction module is used to extract features from images and obtain multi-level features; The feature projection module is used to project and map the multi-level features to obtain the projected features of each level. The hierarchical ranking loss module is used to calculate the intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss based on the projected features and corresponding labels of each level. A dynamic weight controller is used to calculate the weights of intra-granularity ranking loss, cross-granularity alignment loss, and multi-granularity contrast loss, and to obtain the total loss. The iterative training module is used to iteratively train the target detection model based on the total loss until the target detection model converges, thus obtaining a trained target detection model.
7. A target detection device, characterized in that, include: The multi-scale feature extraction module is used to extract features from the image to be detected, obtaining multi-level features. A detection head is used to obtain target detection results based on the multi-level features; wherein the multi-scale feature extraction module and the detection head are obtained by the target detection model training method according to any one of claims 1-3.
8. An electronic device, characterized in that, The method includes a processor and a memory, the processor being electrically connected to the memory, the memory being used to store instructions and data, and the processor being used to perform the steps of the method according to any one of claims 1-3 or 4.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a plurality of instructions adapted for loading by a processor to perform the method steps of any one of claims 1-3 or 4-5.
10. A computer program product comprising instructions that, when run on a computer or processor, cause the computer or processor to perform the steps of the method as described in any one of claims 1-3 or 4-5.