Target detection method and device, electronic equipment and readable storage medium

By using a semi-supervised pre-training method based on contrastive learning and data transfer techniques, the training and deployment efficiency of object detection models in different scenarios is solved, enabling the model to adapt quickly to different scenarios and improving the model's adaptability.

CN119540613BActive Publication Date: 2025-11-07GREE ELECTRIC APPLIANCE INC OF ZHUHAI
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411553237.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-01
Publication Date
2025-11-07
Estimated Expiration
2044-11-01

AI Technical Summary

Technical Problem

Existing object detection models trained in a single scenario degrade in performance after environmental changes, resulting in low training and deployment efficiency. This necessitates the re-collection and labeling of data in different scenarios, which is time-consuming and labor-intensive.

Method used

A semi-supervised pre-training method based on contrastive learning is adopted. Training sample pairs are constructed using labeled and unlabeled data. Pseudo-data is generated by combining data transfer and model fine-tuning to improve the model's adaptability in different scenarios without the need to re-collect and label data.

Benefits of technology

It improves the training and deployment efficiency of object detection models in different scenarios, reduces the dependence on a large amount of labeled data, enhances the model's adaptability, and eliminates the need to re-collect and label data, thus improving the model's adaptability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119540613B_ABST
    Figure CN119540613B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a target detection method and device, electronic equipment and readable storage medium, the method comprises: obtaining the training image and the background image corresponding to the source scene;According to the label data and the background image, a labeled image training sample pair is constructed;According to the unlabeled data and the background image, an unlabeled image training sample pair is constructed;The labeled image training sample pair and the unlabeled image training sample pair are used to train the target detection model to be trained, and a pre-training model is obtained;Obtain the target background image of the target scene;The target region is migrated to the target background image;Embodiments of the present application improve the training efficiency of the target detection model for the target scene, and further improve the deployment efficiency of the target detection model.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] Embodiments of the present application relate to the technical field of computer technology, and in particular to a target detection method, a target detection device, an electronic device, and a computer readable storage medium. BACKGROUND

[0002] The task of target detection is to find all the targets (objects) of interest in an image, determine the category and location of the target, and is one of the core problems in the field of computer vision. With the rapid development of artificial intelligence technology and hardware device computing power, the speed and accuracy of the target detection model have been greatly improved, and has become the core technology of many automated systems. The target detection model helps the automated device to accurately identify and locate the objects in the image or video, so as to perform the corresponding task, which not only improves the production efficiency, but also enhances the intelligent level of the system.

[0003] At present, the data required for training the target detection model in the field of automation is usually collected in a single scene (environment) (such as a laboratory scene or a certain scene of an automated production line). However, the performance of the target detection model trained by single-scene data will degrade after the environment changes. When the target detection model has different scene (such as production line change, different application scene environment difference) use requirements, it is necessary to collect data as training images in the target scene and perform labeling again, and then use it for target detection model fine-tuning to ensure the model performance. However, this way is time-consuming and laborious, resulting in low training efficiency of the target detection model, and further resulting in low deployment efficiency of the target detection model. SUMMARY

[0004] Embodiments of the present application provide a target detection method, device, electronic device and computer readable storage medium to solve the problem of low training efficiency of the target detection model, which further leads to low deployment efficiency of the target detection model.

[0005] Embodiments of the present application disclose a target detection method, the method comprising:

[0006] obtaining training images and background images corresponding to a source scene; wherein the training images include labeled data and unlabeled data, the training images are images including target regions, and the background images are images not including target regions;

[0007] constructing labeled image training sample pairs according to the labeled data and the background images;

[0008] constructing unlabeled image training sample pairs according to the unlabeled data and the background images;

[0009] The target detection model to be trained is trained by using the labeled image training sample pair and the unlabeled image training sample pair, and a pre-training model is obtained.

[0010] A target background image of a target scene is acquired, and the target region is migrated to the target background image.

[0011] The pre-training model is adjusted by using the target background image in which the target region is migrated, the adjusted pre-training model is used as a trained target detection model, and the target in the target scene is detected according to the adjusted target detection model.

[0012] The embodiment of the application further discloses a target detection model training device, and the device comprises:

[0013] A first acquisition module is configured to acquire a training image and a background image corresponding to a source scene; wherein the training image comprises labeled data and unlabeled data, the training image comprises a target region, and the background image does not comprise the target region.

[0014] A first construction module is configured to construct a labeled image training sample pair according to the labeled data and the background image.

[0015] A second construction module is configured to construct an unlabeled image training sample pair according to the unlabeled data and the background image.

[0016] A pre-training module is configured to train a target detection model to be trained by using the labeled image training sample pair and the unlabeled image training sample pair, and obtain a pre-training model.

[0017] A second acquisition module is configured to acquire a target background image of a target scene, and migrate the target region to the target background image.

[0018] An adjustment module is configured to adjust the pre-training model by using the target background image in which the target region is migrated, use the adjusted pre-training model as a trained target detection model, and detect the target in the target scene according to the adjusted target detection model.

[0019] The embodiment of the application further discloses an electronic device, which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete communication with each other through the communication bus.

[0020] The memory is used to store a computer program.

[0021] The processor is used to execute the program stored in the memory, and realize the method according to the embodiment of the application.

[0022] The embodiment of the application further discloses a computer program product stored in a storage medium, and the computer program product is executed by at least one processor to implement the method according to the embodiment of the application.

[0023] The embodiment of the application further discloses a computer readable storage medium, and instructions are stored on the computer readable storage medium, and when the instructions are executed by one or more processors, the processors execute the method according to the embodiment of the application.

[0024] The embodiment of the application has the following advantages:

[0025] In the embodiment of the application, the training image corresponding to the source scene and the background image are acquired, the labeled image training sample pair is constructed according to the labeled data and the background image, the unlabeled image training sample pair is constructed according to the unlabeled data and the background image, then the target detection model to be trained is trained by using the labeled image training sample pair and the unlabeled image training sample pair, and the pre-training model is obtained, then the target background image of the target scene is acquired, the target region is migrated to the target background image, and the pre-training model is adjusted by using the target background image to obtain the target detection model after training. After the pre-training model is trained based on the training image (including the target region) and the background image corresponding to the source scene in the embodiment of the application, the pre-training model is a model preliminarily trained, the target background image of the target scene is further acquired and combined with the target region to generate the target background image, and the pre-training model is trained, so that the model does not need to be trained from the beginning, and therefore the training efficiency of the target detection model for the target scene is improved, and the deployment efficiency of the target detection model is further improved. BRIEF DESCRIPTION OF DRAWINGS

[0026] Figure 1 is a step flowchart of a target detection method provided in the embodiment of the application;

[0027] Figure 2 is a data scene migration schematic diagram provided in the embodiment of the application;

[0028] Figure 3 is a labeled image contrast learning process diagram provided in the embodiment of the application;

[0029] Figure 4 is an unlabeled image contrast learning process diagram provided in the embodiment of the application;

[0030] Figure 5 is an object feature position search schematic diagram provided in the embodiment of the application;

[0031] Figure 6 is a target detection model training and deployment overall framework diagram provided in the embodiment of the application;

[0032] Figure 7 is a semi-supervised contrastive learning model training flowchart provided in an embodiment of the present application.

[0033] Figure 8 is a structural block diagram of a target detection device provided in an embodiment of the present application.

[0034] Figure 9 is a hardware structure schematic diagram of an electronic device for implementing various embodiments of the present application. DETAILED DESCRIPTION

[0035] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the present application will be further described in detail below in combination with the drawings and specific embodiments.

[0036] At present, most of the target detection models in the automation field adopt an end-to-end supervised learning training method, that is, a large amount of labeled data is used to adjust the parameters of the target detection model, so that the target detection model can accurately find the optimal mapping relationship between the input data and the label data. However, this end-to-end supervised learning training method relies on a large amount of manually labeled labeled data, and it is time-consuming and laborious to realize high-quality labeled data labeling, which not only increases the research and development cost, but also is not conducive to the rapid development of the target detection model.

[0037] In addition, in order to ensure the universality of the target detection model, it is usually necessary to collect a large amount of data in different scenes, which is difficult and time-consuming. In order to avoid the long deployment period of the target detection model, the data required for training the target detection model in the automation field is usually collected in a single scene (such as a laboratory scene or a certain scene of an automated production line), however, the model trained by the data in a single environment will degrade in performance after the environment changes, when the model has different scene (such as production line change, different application scene environment difference) use requirements, it is often necessary to collect data again in the target scene and label it for model fine-tuning to ensure the performance of the target detection model, which is not conducive to the rapid deployment of the target detection model.

[0038] To solve the above problems, the embodiment of the present application provides a target detection model semi-supervised pre-training method based on contrast learning, wherein the training sample (training image) of unlabeled data is extracted by an open source visual large model and a background difference algorithm, a same instance (for example, a same category) is used as a sample construction strategy of a positive sample pair, the same category target is used as a sample construction strategy of a positive sample pair of labeled data, and the labeled data and the unlabeled data are simultaneously fed into a neural network of a target detection model to extract features; anchor points are set on the image, and the features generated by the samples are searched according to the nearest distance principle to perform contrast learning training; and different loss weights are set for the labeled data and the unlabeled data by modifying the loss function, so as to prevent overfitting of the target detection model, finally reduce the dependence of the target detection model on a large amount of labeled data during training, improve the training efficiency of the target detection model in the automatic field, and further improve the deployment efficiency of the target detection model. Further, the embodiment of the present application also provides a model fast training and deployment method in different scenes combining data migration and model fine-tuning, which generates pseudo data by migrating data to a target scene, and then fine-tunes the model to improve the adaptability of the target detection model to the target scene, without the need to collect and label data again for different scenes, and improves the use performance of the target detection model in the target scene.

[0039] Referring to Figure 1 , a step flowchart of a target detection method provided in the embodiment of the present application is shown, which can specifically include the following steps:

[0040] Step 101, training images and background images corresponding to a source scene are acquired; wherein the training images include labeled data and unlabeled data, the training images are images including target regions, and the background images are images not including target regions;

[0041] Step 102, labeled image training sample pairs are constructed according to the labeled data and the background images;

[0042] Step 103, unlabeled image training sample pairs are constructed according to the unlabeled data and the background images;

[0043] In the automatic field, the task of target detection is to find all targets (objects) of interest in an image, determine the category and position of the target, for example, in the industrial field, the target can be various mechanical parts, such as bolts, nuts, bearings, gears, etc., and the quality of the parts is detected by detecting the parts on a certain production line through images to ensure the integrity and correctness of the parts and the quality of the products produced by using the parts.

[0044] In a specific implementation, the image can be divided into a foreground region and a background region, for distinguishing a region containing a target (the foreground region) from a region not containing the target (the background region) in the image, and the background region is usually a part of the image other than the target bounding box.

[0045] In the embodiment of the present application, in the target detection model parameter initialization, training images are read from the data set, specifically, one batch of training images can be sampled from the data set each time, and the training images can contain labeled data (labeled images) and unlabeled data (unlabeled images), and the proportion of the two is random. In addition, the training images are images including a target region (foreground region / labeling region), and the background images are images not including the target region. Next, each training image is traversed, and then based on whether it is labeled data or unlabeled data, labeled image training sample pairs and unlabeled image training sample pairs are constructed for contrast learning. The target region of the labeled data can include a target bounding box (object bounding box) and a category, and the target bounding box and the category are used for model training of the target detection model, so that the target detection model can accurately identify and locate the target (such as the category and position of the target) in the image. Specifically, the target bounding box is usually a rectangular box, which is used to frame the target region including the target in the image, so as to locate the position of the target in the image, such as the region including the nut in the image; the category refers to the type of the target, for example, when detecting targets such as bolts, nuts, cars, traffic signs, etc. in the image, these targets belong to different categories.

[0046] Step 104, training the target detection model to be trained by using the labeled image training sample pairs and the unlabeled image training sample pairs to obtain a pre-training model;

[0047] Contrast learning is a self-supervised learning method, which learns the representation of data by maximizing the similarity between positive sample pairs and minimizing the similarity between negative sample pairs. Contrast learning can learn a discriminative feature representation, and improve the generalization ability and robustness of the target detection model.

[0048] In the embodiment of the present application, the target detection model to be trained is trained by using the labeled image training sample pairs and the unlabeled image training sample pairs for semi-supervised contrast learning to obtain a pre-training model. The pre-training model can extract features from images, and the features of targets of the same category are close in the feature space, and the features of targets of different categories, targets and backgrounds are far apart, thereby realizing the effect of target feature clustering. In addition, because the object is randomly placed in different positions of the image during the training process, the calculation of the contrast loss considers the influence of the target position, so that the pre-training model has the function of preliminary target positioning.

[0049] Step 105, obtaining a target background image of a target scene, and migrating the target region to the target background image;

[0050] Step 106, adjusting the pre-training model by using the target background image in which the target region is migrated, taking the adjusted pre-training model as a trained target detection model, and detecting a target in the target scene according to the adjusted target detection model.

[0051] In the embodiment of the application, the pre-training model can be used for feature extraction, and a detection head needs to be connected and the model needs to be fine-tuned to realize the function of target detection. The data used for model fine-tuning is labeled data, and in order to make the final target detection model meet the use requirements of a new scene (target scene), scene migration is performed on the original data. Specifically, the scene migration can be obtaining a target background image of a target scene, wherein the target background image does not include a target region of a target, and then the target region can be migrated to the target background image to obtain an image containing the target region belonging to the target scene. Therefore, the pre-training model is adjusted based on the image, and a target detection model for the target scene can be quickly obtained.

[0052] In the embodiment of the application, the pre-training model mainly functions for feature extraction, and a detection head needs to be connected and the model needs to be fine-tuned to realize the function of target detection. The data used for model fine-tuning is labeled data, and in order to make the final target detection model meet the use requirements of a target scene, scene migration is performed on the original data, and the specific process is as follows: Figure 2 is a data scene migration schematic diagram provided in the embodiment of the application, and the specific process includes:

[0053] (1) connecting a detection head. A detection head network model is connected after the pre-training model and is initialized; (2) data scene migration. The labeled object region is intercepted, and after data enhancement processing, it is randomly pasted into a background image of a target scene. The data enhancement processing can include random cropping, rotation translation, color transformation, random noise addition, object random deletion, etc. (3) model fine-tuning. The pre-training model parameters are frozen, and only the parameters of the detection head network model are adjusted. The adjusted pre-training model is taken as a trained target detection model, which is used for detecting a target in a target scene.

[0054] In an embodiment of the application, the method can further include:

[0055] The to-be-detected image is input into the trained target detection model, and the category and position of the target in the to-be-detected image are obtained.

[0056] After obtaining the target detection model for the target scene, the target detection model can be deployed in the target scene, and then the target in the target scene is detected in terms of category and position based on the target detection model.

[0057] In the embodiment of the present application, the training image and the background image corresponding to the source scene are obtained, the labeled image training sample pair is constructed according to the labeled data and the background image, and the unlabeled image training sample pair is constructed according to the unlabeled data and the background image. Then, the target detection model to be trained can be trained by comparing the labeled image training sample pair and the unlabeled image training sample pair to obtain a pre-trained model. Then, the target background image of the target scene is obtained, the target region is migrated to the target background image, and the pre-trained model is adjusted using the target background image to obtain a trained target detection model. In the embodiment of the present application, after the pre-trained model is trained based on the training image (including the target region) and the background image corresponding to the source scene, the pre-trained model is a model preliminarily trained, and the target background image of the target scene is further combined with the target region to generate a target background image to train the pre-trained model. Therefore, the model does not need to be trained from scratch, thereby improving the training efficiency of the target detection model for the target scene and further improving the deployment efficiency of the target detection model.

[0058] In an embodiment of the present application, the target region includes a target bounding box and a category, and the labeled image training sample pair is constructed according to the labeled data and the background image, including:

[0059] The target region in the labeled data is intercepted;

[0060] A first background image is randomly obtained from the background image;

[0061] The first background image is copied to obtain a second background image;

[0062] The labeled image training sample pair is constructed according to the target region, the first background image and the second background image.

[0063] Referring to Figure 3 It is a labeled image contrast learning process diagram provided in the embodiment of the present application, and the process of constructing the labeled image training sample pair can include: if the training data is labeled data (target bounding box and category), first, the labeled data (labeled image) is read, the labeled foreground region (i.e. the target region containing the target) in the labeled image is intercepted, and a background image is randomly read, which is recorded as background image 1 (first background image). Then, a background image 1 is copied, which is recorded as background image 2 (second background image), and then the labeled image training sample pair can be constructed according to the target region, the first background image and the second background image, which is used for model training of the target detection model.

[0064] The labeled image training sample pair includes a labeled positive sample pair and a labeled negative sample pair; and the labeled image training sample pair is constructed according to the target region, the first background image and the second background image, and the construction includes:

[0065] A specific target region is obtained from the target region;

[0066] The specific target region is subjected to data enhancement processing to obtain an enhanced specific target region;

[0067] The enhanced specific target region is randomly pasted to the first background image to obtain an enhanced first background image;

[0068] A positive target region of the same category as the specific target region is randomly obtained from the target region;

[0069] The positive target region is subjected to data enhancement processing to obtain an enhanced positive target region;

[0070] The enhanced positive target region is randomly pasted to the second background image to obtain a positive second background image;

[0071] The labeled positive sample pair is constructed according to the enhanced first background image and the positive second background image;

[0072] A negative target region different from the specific target region is randomly obtained from the target region;

[0073] The negative target region is randomly pasted to the second background image to obtain a negative second background image;

[0074] The labeled negative sample pair is constructed according to the enhanced first background image and the negative second background image.

[0075] The data enhancement processing at least includes rotation translation, random cropping, color transformation, blurring, random noise adding and object randomization.

[0076] Reference Figure 3After acquiring background image 1 (first background image) and background image 2 (second background image), each target region is traversed. For a specific target region, the extracted target region is processed with data augmentation (rotation, translation, random cropping, color transformation, blurring, etc.) and then randomly pasted into any position in background image 1 to obtain the enhanced first background image. Next, with a 50% probability, labeled positive sample pairs or labeled negative sample pairs are constructed for the specific target region. Specifically, for the construction of labeled positive samples: a target region of the same category is randomly searched from the training images of the batch as the positive target region. After data augmentation, the positive target region is obtained and randomly pasted into any position in background image 2 to obtain the positive second background image. Finally, labeled positive sample pairs can be constructed based on the enhanced first background image and the positive second background image. For the construction of negative samples: randomly select a target region of a different category from the specific target region in the batch data or randomly crop the background region as the negative target region. After data augmentation processing (rotation, translation, random cropping, color transformation, blurring, etc.) is performed on the negative target region, it is randomly pasted into any position in background image 2 (second background image) to obtain the negative second background image. Based on the augmented first background image and the negative second background image, annotated negative sample pairs are constructed.

[0077] In one embodiment of the present invention, constructing unlabeled image training sample pairs based on the unlabeled data and the background image includes:

[0078] A visual model is used to segment the unlabeled data to extract the segmented regions;

[0079] Background regions are extracted from the background image using a background subtraction algorithm;

[0080] Whether the segmented region is a foreground region is determined based on the background region; wherein, the foreground region is the region that includes the target;

[0081] When the segmented region is determined to be a foreground region, the segmented region is taken as the target segmented region;

[0082] A third background image is randomly selected from the background image;

[0083] The third background image is copied to obtain the fourth background image;

[0084] Based on the target segmentation region, the third background image, and the fourth background image, construct unlabeled image training sample pairs.

[0085] Reference Figure 4The process chart of the unlabeled image contrast learning provided in the embodiment of the application, the process of constructing the unlabeled image training sample pair can comprise: for the unlabeled data of which the training data is unlabeled, firstly, reading the unlabeled data (unlabeled image), performing pixel-level panoramic segmentation on the unlabeled image by using a visual model (for example, a SegAnything visual large model) with a panoramic segmentation function, and separating each segmentation region in the image (at this time, it is impossible to judge whether the segmentation region belongs to a foreground region or a background region, and the specific category of the target); if it is determined that the segmentation region belongs to the foreground region, the segmentation region can be taken as a target segmentation region; a background image is randomly read, denoted as a background image 3 (third background image), and then the background image 3 is copied, denoted as a background image 4 (fourth background image); then, according to the target segmentation region, the third background image and the fourth background image, an unlabeled image training sample pair is constructed, which is used for model training of a target detection model.

[0086] In an embodiment of the application, determining whether the segmentation region is a foreground region according to the background region comprises:

[0087] Calculating a pixel area intersection union ratio of the segmentation region and the background region;

[0088] Determining whether the segmentation region is a foreground region according to the pixel area intersection union ratio;

[0089] If the pixel area intersection union ratio is less than a preset threshold value, it is determined that the segmentation region is a foreground region.

[0090] In the embodiment of the application, a background image is read, a background region of the background image is extracted by using a background difference algorithm, a pixel area intersection union ratio between a target segmentation region segmented by a visual large model and the background region is calculated, and when the pixel area intersection union ratio is less than a preset threshold value T, the target segmentation region is considered to be a foreground region (a target region). The foreground region contains a target to be detected, and a bounding box of the foreground region is the position of the target. Therefore, the segmentation region with the pixel area intersection union ratio less than the preset threshold value T can be taken as the target segmentation region.

[0091] In an embodiment of the application, the labeled image training sample pair comprises an unlabeled positive sample pair and an unlabeled negative sample pair; according to the target segmentation region, the third background image and the fourth background image, the unlabeled image training sample pair is constructed, comprising:

[0092] Performing data enhancement processing on the target segmentation region to obtain an enhanced target segmentation region;

[0093] Randomly pasting the enhanced target segmentation region to the third background image to obtain an enhanced third background image;

[0094] randomly paste the enhanced target segmentation region to the fourth background image to obtain an enhanced fourth background image;

[0095] construct an unlabeled positive sample pair according to the enhanced third background image and the enhanced fourth background image;

[0096] randomly obtain a random background region that is a non-foreground region from the segmentation regions;

[0097] randomly paste the random background region to the fourth background image to obtain a random fourth background image;

[0098] construct an unlabeled negative sample pair according to the enhanced third background image and the random fourth background image.

[0099] Referring to Figure 4 , each segmented target segmentation region is traversed, the target segmentation region is subjected to data enhancement processing (rotation translation, random cropping, color transformation, blurring, and the like) to obtain an enhanced target segmentation region, and the enhanced target segmentation region is randomly pasted to any position in the background image 3 to obtain an enhanced third background image; with a probability of each 50%, an unlabeled positive sample pair or an unlabeled negative sample pair is constructed for the target segmentation region: the target segmentation region is subjected to data enhancement, and a random fourth background image is obtained by randomly pasting the target segmentation region to any position in the background image 2; an unlabeled positive sample pair is constructed according to the enhanced third background image and the enhanced fourth background image; a background region of the background image is randomly intercepted, and a random fourth background image is obtained by randomly pasting the background region to any position in the background image 4; and an unlabeled negative sample pair is constructed according to the enhanced third background image and the random fourth background image.

[0100] Of course, the above-mentioned construction of the labeled image training sample pair and the unlabeled image training sample pair is only as an example, and the embodiment of the present application can select other ways to construct the positive and negative sample pairs for the target, and the embodiment of the present application does not need to be limited in this regard.

[0101] In an embodiment of the present application, the labeled image training sample pair and the unlabeled image training sample pair are used to train a target detection model to be trained to obtain a pre-training model, including:

[0102] the labeled image training sample pair and the unlabeled image training sample are input into the target detection model to be trained to obtain a feature map;

[0103] the target region corresponding features are searched from the feature map according to the training image;

[0104] the features corresponding to the labeled image training sample pair are compared and learned, and the features corresponding to the unlabeled image training sample pair are compared and learned to obtain a pre-training model.

[0105] In the embodiment of the present application, the labeled image training sample pair and the unlabeled image training sample pair are input into the target detection model to be trained to obtain the feature map of the sample pair (labeled positive sample pair, labeled negative sample pair, unlabeled positive sample pair, unlabeled negative sample pair, etc.), then the features corresponding to the sample pair in the feature map are extracted for contrast learning, the contrast loss between the features of the sample pair is calculated, and the model parameters are adjusted in the reverse direction, so that the distance between the features of the positive sample pair is closer and closer, and the distance between the features of the negative sample pair is farther and farther. The contrast loss calculation formula is shown in formula (1):

[0106]

[0107] In the formula, D W (X1,X2)=||X1-X2||2, represents the Euclidean distance of two sample features X1, X2, W is the model parameter, Y is the label of whether the two samples match, Y=1 represents that the two samples match, which is a positive sample pair, Y=0 represents a negative sample pair, m is a set threshold, N is the number of samples, Z is the label of whether the sample pair is labeled data, Z=1 represents that the sample pair is generated by labeled data, Z=0 represents that the sample pair is generated by unlabeled data, c1, c2 are weight parameters for controlling the influence of labeled data samples and unlabeled data samples on the model. Since the unlabeled data is much more than the labeled data, and the unlabeled data sample pair is obtained by data enhancement, the features are similar, and the training is prone to overfitting. In order to prevent the model from overfitting, the value of c1 needs to be greater than the value of c2, so as to reduce the influence of the unlabeled data loss on the model parameters, and c1+c2=1.

[0108] After the above semi-supervised contrast learning training of the target detection model to be trained, a pre-trained model is obtained. The pre-trained model can extract features from images, and the features of the same category of targets (objects) are close in the feature space, and the features of different categories of objects and objects and backgrounds are far apart, thereby realizing the effect of target feature clustering. In addition, since the objects are randomly placed in different positions of the image during the training process, the calculation of the contrast loss takes into account the influence of the target position, so that the pre-trained model of the embodiment of the present application has the function of preliminary target positioning.

[0109] In an embodiment of the present application, searching the feature corresponding to the target region from the feature map according to the training image comprises:

[0110] Dividing the corresponding training image into a plurality of regions with the same resolution size as the feature map;

[0111] Taking the center point of the region as an anchor point;

[0112] calculate the distance from the center point of the target bounding box in the training image to the anchor point;

[0113] take the position of the nearest anchor point in the region divided by the training image as the target position of the target region in the feature map;

[0114] take the feature corresponding to the target position in the feature map as the feature corresponding to the target region.

[0115] In the embodiments of the present application, with reference to Figure 5 For the object feature position search schematic diagram provided in the embodiments of the present application, the processed images of the background image 1, the background image 2, the background image 3 and the background image 4 are input into the target detection model to be trained for feature extraction. Since the resolution of the image changes after being processed by the neural network, the extracted feature position of the target object also changes accordingly. The method for searching the target object feature in the feature map is as shown in Figure 5 According to the resolution of the feature map, the original image (training image) is divided into several regions with the same size as the resolution of the feature map, and the center point of the region is the anchor point. The distance from the center point of the target bounding box to each anchor point is calculated, and the position of the nearest anchor point in the region divided by the original image is taken as the position of the feature of the object in the feature map.

[0116] In an embodiment of the present application, the method further comprises:

[0117] collecting training images and background data in a source scene; wherein the training images include target regions of targets to be detected, and the background data does not include target regions of targets to be detected;

[0118] divide the training images into to-be-labeled data and unlabeled data according to a preset ratio;

[0119] label the to-be-labeled data to obtain labeled data; wherein the labeled data includes target bounding boxes and categories.

[0120] In the embodiments of the present application, training data / training images (containing targets) and background data (not containing targets) can be collected in one or a small number of source scenes (such as laboratory scenes or a small number of workstation scenes in a production line). The to-be-labeled data and unlabeled data are divided according to the ratio of a:b, and the to-be-labeled data is labeled (including manual labeling or semi-automatic labeling using auxiliary tools) to obtain labeled data. The labeled data can include target bounding boxes and categories. Generally, the proportion of to-be-labeled data is less than that of unlabeled data.

[0121] In the pre-training stage, the embodiment of the application mainly adopts a large amount of unlabeled data and a small amount of labeled data to perform semi-supervised training on the target detection model to be trained, uses a training paradigm of contrast learning to obtain a pre-trained model; in the model fine-tuning stage, a small amount of background images not containing the target to be detected in the target scene are collected, the data migration method is used to migrate a small amount of labeled data in the source scene to the target scene, the pre-trained model is adjusted by using the migrated data, and a target detection model for the target scene is obtained, and finally the target detection model is deployed in the target scene for target detection.

[0122] The embodiment of the application proposes a semi-supervised model pre-training method based on contrast learning to solve the problem that deep learning target detection model training in the automation field depends on a large amount of labeled data, the method can pre-train the model by means of a large amount of unlabeled data and a small amount of labeled data, and the amount of labeled data required for training is reduced; in addition, the embodiment of the application solves the problem that the performance of the model is reduced due to changes in the application scene (target scene) or large environmental differences when the model is deployed, generates pseudo samples in the application scene by means of data migration, and combines model fine-tuning to improve the adaptability of the target detection model to the application scene, without the need to collect and label data again for different scenes.

[0123] Referring to Figure 6 It is a model training and deployment overall framework provided by the embodiment of the application, and the main process can include: data collection; data division, that is, division into unlabeled data and labeled data, the unlabeled data can be labeled to obtain labeled data; entering semi-supervised contrast learning, inputting the labeled data and the unlabeled data into an initialized model (a target detection model to be trained) to perform contrast learning training, obtaining a pre-trained model; performing data migration based on the labeled data and background data (target background images) of the target scene to obtain target scene data (including a target region), and then fine-tuning the pre-trained model according to the target scene data to obtain a trained target detection model, which can be deployed in the target scene for target detection.

[0124] Referring to Figure 7The semi-supervised contrast learning model training flowchart provided in the embodiment of the present application, the specific process includes: initializing model parameters to obtain a target detection model to be trained; reading training data (training images); determining whether the training data is labeled (i.e., labeled data or unlabeled data); if labeled, object label region (target region) extraction; constructing positive sample pairs of the same category objects; constructing negative sample pairs of different category objects; data enhancement + random mapping, finally obtaining labeled image training sample pairs; using the labeled image training sample pairs, the target detection model to be trained is subjected to contrast learning training; if unlabeled, the SegAnything visual large model is used to perform panoramic segmentation on the training data; the foreground object is extracted using background difference; the same foreground object data is enhanced to construct positive sample pairs; the foreground region is randomly cropped to construct negative sample pairs, and finally unlabeled image training sample pairs are obtained; using the unlabeled image training sample pairs, the target detection model to be trained is subjected to contrast learning training; the model obtained by fusing the labeled image training sample pairs and the unlabeled image training sample pairs subjected to contrast learning training is a pre-trained model; based on the background image of the target scene, data scene migration is performed to obtain target scene data containing a target region of the target scene; the model is fine-tuned using the target scene data, and a trained target detection model is obtained, which is used for deployment in the target scene for target detection.

[0125] The embodiment of the present application realizes a general target detection model training scheme in the automation field, pre-trains the target detection model through semi-supervised contrast learning, greatly reduces the data labeling workload, and then combines data migration and model fine-tuning technology to improve the performance of the target detection model in the target scene, so that the model can be quickly deployed in different target scenes.

[0126] It should be noted that for the method embodiment, in order to simply describe, it is expressed as a series of action combinations, but those skilled in the art should know that the embodiment of the present application is not limited by the described action sequence, because according to the embodiment of the present application, certain steps can be performed in other order or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification all belong to preferred embodiments, and the actions involved are not necessarily necessary for the embodiment of the present application.

[0127] Referring to Figure 8 , a structure block diagram of a target detection device provided in the embodiment of the present application is shown, which can specifically include the following modules:

[0128] The first acquisition module 801 is configured to acquire training images and background images corresponding to a source scene; wherein the training images include labeled data and unlabeled data, and the training images include a target region; and the background images do not include the target region;

[0129] The first construction module 802 is configured to construct a labeled image training sample pair according to the labeled data and the background image.

[0130] The second construction module 803 is configured to construct an unlabeled image training sample pair according to the unlabeled data and the background image.

[0131] The pre-training module 804 is configured to train a target detection model to be trained by using the labeled image training sample pair and the unlabeled image training sample pair, to obtain a pre-trained model.

[0132] The second acquisition module 805 is configured to acquire a target background image of a target scene, and migrate the target region to the target background image.

[0133] The adjustment module 806 is configured to adjust the pre-trained model by using the target background image in which the target region is migrated, and use the adjusted pre-trained model as a trained target detection model, so as to detect a target in a target scene according to the adjusted target detection model.

[0134] In an embodiment of the present application, the target region includes a target bounding box and a category, and the labeled image training sample pair is constructed according to the labeled data and the background image, including:

[0135] The target region in the labeled data is intercepted;

[0136] A first background image is randomly acquired from the background image;

[0137] The first background image is copied to obtain a second background image;

[0138] The labeled image training sample pair is constructed according to the target region, the first background image and the second background image.

[0139] In an embodiment of the present application, the labeled image training sample pair includes a labeled positive sample pair and a labeled negative sample pair, and the labeled image training sample pair is constructed according to the target region, the first background image and the second background image, including:

[0140] A specific target region is acquired from the target region;

[0141] The specific target region is subjected to data enhancement processing to obtain an enhanced specific target region;

[0142] The enhanced specific target region is randomly pasted to the first background image to obtain an enhanced first background image;

[0143] A positive target region with the same category as the specific target region is randomly acquired from the target region;

[0144] performing data enhancement processing on the positive target region to obtain an enhanced positive target region;

[0145] randomly pasting the enhanced positive target region to the second background image to obtain a positive second background image;

[0146] constructing a labeled positive sample pair according to the enhanced first background image and the positive second background image;

[0147] randomly obtaining a negative target region different from the specific target region from the target region;

[0148] randomly pasting the negative target region to the second background image to obtain a negative second background image;

[0149] constructing a labeled negative sample pair according to the enhanced first background image and the negative second background image.

[0150] In an embodiment of the present application, constructing an unlabeled image training sample pair according to the unlabeled data and the background image comprises:

[0151] segmenting a segmentation region from the unlabeled data by using a visual model;

[0152] extracting a background region from the background image by using a background difference algorithm;

[0153] determining whether the segmentation region is a foreground region according to the background region, wherein the foreground region is a region including a target;

[0154] when it is determined that the segmentation region is a foreground region, taking the segmentation region as a target segmentation region;

[0155] randomly obtaining a third background image from the background image;

[0156] copying the third background image to obtain a fourth background image;

[0157] constructing an unlabeled image training sample pair according to the target segmentation region, the third background image and the fourth background image.

[0158] In an embodiment of the present application, determining whether the segmentation region is a foreground region according to the background region comprises:

[0159] calculating a pixel area intersection union ratio of the segmentation region and the background region;

[0160] determining whether the segmentation region is a foreground region according to the pixel area intersection union ratio;

[0161] If the pixel area intersection-over-union ratio is less than a preset threshold, the segmentation region is determined as a foreground region.

[0162] In an embodiment of the present application, the labeled image training sample pair comprises an unlabeled positive sample pair and an unlabeled negative sample pair; and the unlabeled image training sample pair is constructed according to the target segmentation region, the third background image and the fourth background image, comprising:

[0163] The target segmentation region is subjected to data enhancement processing to obtain an enhanced target segmentation region;

[0164] The enhanced target segmentation region is randomly pasted to the third background image to obtain an enhanced third background image;

[0165] The enhanced target segmentation region is randomly pasted to the fourth background image to obtain an enhanced fourth background image;

[0166] The unlabeled positive sample pair is constructed according to the enhanced third background image and the enhanced fourth background image;

[0167] A random background region which is a non-foreground region is randomly obtained from the segmentation region;

[0168] The random background region is randomly pasted to the fourth background image to obtain a random fourth background image;

[0169] The unlabeled negative sample pair is constructed according to the enhanced third background image and the random fourth background image.

[0170] In an embodiment of the present application, the labeled image training sample pair and the unlabeled image training sample pair are used to train a target detection model to be trained to obtain a pre-training model, comprising:

[0171] The labeled image training sample pair and the unlabeled image training sample are input into the target detection model to be trained to obtain a feature map;

[0172] The feature corresponding to the target region is searched from the feature map according to the training image;

[0173] The features corresponding to the labeled image training sample pair and the unlabeled image training sample pair are subjected to comparison learning to obtain the pre-training model.

[0174] In an embodiment of the present application, the feature corresponding to the target region is searched from the feature map according to the training image, comprising:

[0175] The corresponding training image is divided into a plurality of regions with the same resolution size as the feature map;

[0176] taking the center point of the region as an anchor point;

[0177] calculating the distance from the center point of the target bounding box in the training image to the anchor point;

[0178] taking the position of the nearest anchor point in the region divided by the training image as the target position of the target region in the feature map;

[0179] taking the feature corresponding to the target position in the feature map as the feature corresponding to the target region.

[0180] In an embodiment of the present application, the data enhancement processing at least includes rotation translation, random cropping, color transformation, blurring, random noise addition and object randomness.

[0181] In an embodiment of the present application, the data enhancement processing at least includes rotation translation, random cropping, color transformation, blurring, random noise addition and object randomness.

[0182] collecting training images and background data in a source scene; wherein the training images include target regions to be targeted, and the background data does not include target regions to be targeted;

[0183] dividing the training images into labeled data and unlabeled data according to a preset ratio;

[0184] annotating the labeled data to obtain annotation data; wherein the annotation data includes target bounding boxes and categories.

[0185] In an embodiment of the present application, the device further includes;

[0186] inputting the to-be-detected image into the trained target detection model to obtain the category and position of the target in the to-be-detected image.

[0187] In an embodiment of the present application, the labeled data is less than the unlabeled data.

[0188] For the device embodiment, it is basically similar to the method embodiment, so the description is relatively simple, and the related parts refer to the part of the method embodiment.

[0189] In addition, the embodiment of the present application also provides an electronic device, which includes a processor, a memory, a computer program stored on the memory and executable on the processor, and the computer program is executed by the processor to implement each process of the above target detection method embodiment and achieve the same technical effect. To avoid repetition, it will not be described here.

[0190] The embodiment of the present application further provides a computer readable storage medium, and the computer readable storage medium stores a computer program. The computer program is executed by a processor to implement each process of the target detection method embodiment and achieve the same technical effects. To avoid repetition, details are not described herein. The computer readable storage medium includes a read-only memory (ROM), a random access memory (RAM), a magnetic disk, an optical disk, and the like.

[0191] The embodiment of the present application further provides a computer program product, which is stored in a storage medium and is executed by at least one processor to implement each process of the target detection method embodiment and achieve the same technical effects. To avoid repetition, details are not described herein.

[0192] Figure 9 A hardware structure diagram of an electronic device for implementing various embodiments of the present application.

[0193] The electronic device 900 includes, but is not limited to, a radio frequency unit 901, a network module 902, an audio output unit 903, an input unit 904, a sensor 905, a display unit 906, a user input unit 907, an interface unit 908, a memory 909, a processor 910, and a power supply 911, and the like. Those skilled in the art can understand that the electronic device structure shown in the figure is not a limitation on the electronic device, and the electronic device can include more or fewer components than the figure, or combine certain components, or different component arrangements. In the embodiments of the present application, the electronic device includes, but is not limited to, a mobile phone, a tablet computer, a notebook computer, a palm computer, a vehicle terminal, a wearable device, and a pedometer, and the like. Figure 9

[0194] It should be understood that in the embodiments of the present application, the radio frequency unit 901 can be used for receiving and sending signals in the process of information or call. Specifically, after receiving the downlink data from the base station, the processor 910 processes it. In addition, the uplink data is sent to the base station. Generally, the radio frequency unit 901 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier, a duplexer, and the like. In addition, the radio frequency unit 901 can also communicate with the network and other devices through a wireless communication system.

[0195] The electronic device provides wireless broadband Internet access for users through the network module 902, such as helping users to send and receive emails, browse web pages, and access streaming media, and the like.

[0196] ​The audio output unit 903 can convert audio data, which is received by the radio frequency unit 901 or the network module 902 or stored in the memory 909, into an audio signal and output as sound. Also, the audio output unit 903 can provide an audio output related to a particular function performed by the electronic device 900 (e.g., a call signal reception sound, a message reception sound, etc.). The audio output unit 903 includes a speaker, a buzzer, and a receiver, etc.

[0197] The input unit 904 is used to receive audio or video signals. The input unit 904 can include a graphics processor (GPU) 9041 and a microphone 9042. The graphics processor 9041 processes image data of a still picture or a video obtained by an image capture device (e.g., a camera) in a video capture mode or an image capture mode. The processed image frame can be displayed on the display unit 906. The image frame processed by the graphics processor 9041 can be stored in the memory 909 (or other storage medium) or transmitted via the radio frequency unit 901 or the network module 902. The microphone 9042 can receive sound and can process such sound as audio data. The processed audio data can be converted into a format transmittable to a mobile communication base station via the radio frequency unit 901 in the case of a telephone call mode.

[0198] The electronic device 900 further includes at least one sensor 905, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor includes an ambient light sensor and a proximity sensor, wherein the ambient light sensor can adjust the brightness of the display panel 9061 according to the brightness of ambient light, and the proximity sensor can turn off the display panel 9061 and / or the backlight when the electronic device 900 is moved to the ear. As one of the motion sensors, the accelerometer sensor can detect the magnitude of acceleration in each direction (generally three axes), and can detect the magnitude and direction of gravity when at rest, which can be used to identify the electronic device posture (such as screen switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometer, knock), etc. The sensor 905 can also include a fingerprint sensor, a pressure sensor, an iris sensor, a molecular sensor, a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, etc., which will not be described here.

[0199] The display unit 906 is used to display information input by a user or information provided to a user. The display unit 906 can include a display panel 9061, which can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc.

[0200] The user input unit 907 can be used to receive inputted numerical or character information, and to generate key signal inputs related to user settings of the electronic device and control of functions. Specifically, the user input unit 907 includes a touch panel 9071 and other input devices 9072. The touch panel 9071, also called a touch screen, can collect a user's touch operation (such as a user's operation on or near the touch panel 9071 using a finger, a stylus, or any suitable object or accessory) on or near the touch panel 9071. The touch panel 9071 can include two parts, a touch detecting device and a touch controller. The touch detecting device detects a user's touch position and detects a signal resulting from the touch operation, and transmits the signal to the touch controller. The touch controller receives the touch information from the touch detecting device, converts it into touch coordinates, and sends it to the processor 910, and receives commands from the processor 910 and executes them. In addition, the touch panel 9071 can be implemented in various types such as a resistive type, a capacitive type, an infrared type, and a surface acoustic wave type. In addition to the touch panel 9071, the user input unit 907 can include other input devices 9072. Specifically, the other input devices 9072 can include, but are not limited to, a physical keyboard, function keys (such as volume control keys, switch keys, etc.), a trackball, a mouse, a joystick, etc., without being limited thereto.

[0201] Further, the touch panel 9071 can be overlaid on the display panel 9061, and when the touch panel 9071 detects a touch operation on or near it, it transmits it to the processor 910 to determine the type of touch event, and then the processor 910 provides a corresponding visual output on the display panel 9061 according to the type of touch event. Although in the above description, the touch panel 9071 and the display panel 9061 are implemented as two independent components to realize the input and output functions of the electronic device, in some embodiments, the touch panel 9071 and the display panel 9061 can be integrated to realize the input and output functions of the electronic device, without being limited thereto. Figure 9

[0202] The interface unit 908 is an interface for connecting an external device to the electronic device 900. For example, the external device can include a wired or wireless headset port, an external power supply (or battery charger) port, a wired or wireless data port, a memory card port, a port for connecting a device having an identification module, an audio input / output (I / O) port, a video I / O port, an earphone port, etc. The interface unit 908 can be used to receive input (e.g., data information, power, etc.) from an external device and transmit the received input to one or more elements within the electronic device 900, or can be used to transmit data between the electronic device 900 and the external device.

[0203] ​The memory 909 is operable to store software programs and various data. The memory 909 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs (such as a sound play function, an image play function, etc.) required by at least one function, etc.; and the data storage area can store data (such as audio data, a phone book, etc.) created according to the use of the mobile phone, etc. In addition, the memory 909 can include a high-speed random access memory, and can further include a nonvolatile memory such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device.

[0204] The processor 910 is a control center of the electronic device, connects all parts of the electronic device through various interfaces and lines, executes various functions of the electronic device and processes data by running or executing software programs and / or modules stored in the memory 909 and calling data stored in the memory 909, and thus performs overall monitoring on the electronic device. The processor 910 can include one or more processing units; preferably, the processor 910 can integrate an application processor and a modem processor, wherein the application processor mainly processes an operating system, a user interface, and an application program, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor can also not be integrated into the processor 910.

[0205] The electronic device 900 can further include a power supply 911 (such as a battery) for supplying power to various components; preferably, the power supply 911 can be logically connected to the processor 910 through a power management system, so as to realize functions such as management of charging, discharging, and power consumption management through the power management system.

[0206] In addition, the electronic device 900 includes some functional modules which are not shown and will not be described herein.

[0207] It should be noted that, in this document, the term "comprising" or "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article, or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or further includes elements inherent to such a process, method, article, or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of additional identical elements in the process, method, article, or device including the element.

[0208] Those skilled in the art can clearly understand that the above-mentioned embodiment method can be realized by means of software and necessary general hardware platform, of course, it can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes a plurality of instructions for making a terminal (which can be a mobile phone, computer, server, air conditioner, or network device) execute the method described in each embodiment of the present application.

[0209] The embodiments of the present application are described above with reference to the accompanying drawings, but the present application is not limited to the above-mentioned specific embodiments, and the above-mentioned specific embodiments are only illustrative, not restrictive. Those skilled in the art can make many forms without departing from the purpose of the present application and the scope protected by the claims under the inspiration of the present application, which all belong to the protection of the present application.

[0210] Those skilled in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in the embodiments of the present application can be realized by electronic hardware or a combination of computer software and electronic hardware. Whether the functions are realized in hardware or software depends on the specific application and design constraints of the technical solutions. Those skilled in the art can use different methods to realize the described functions for each specific application, but such implementation should not be considered beyond the scope of the present application.

[0211] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-mentioned system, device and unit can refer to the corresponding process in the foregoing method embodiments, which will not be repeated here.

[0212] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the units is only a logical function division, and actual implementation can have another division manner, for example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed units can be indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0213] The units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, may be located in one place, or may be distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment scheme.

[0214] In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present alone, or two or more units can be integrated in one unit.

[0215] The functions, if realized in the form of software functional units and sold or used as independent products, can be stored in a computer readable storage medium. Based on such understanding, the technical scheme of the present application or the part of the present application that essentially contributes to the prior art or the part of the technical scheme can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes various storage media that can store program codes, such as a U disk, a mobile hard disk, a ROM, a RAM, a magnetic disk or an optical disk.

[0216] The above is only a specific embodiment of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art can easily think of changes or replacements within the technical range disclosed by the present application, which should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A target detection method characterized by, The method comprises: acquiring a training image and a background image corresponding to a source scene; wherein the training image comprises labeled data and unlabeled data, the training image is an image comprising a target region, and the background image is an image not comprising the target region; constructing a labeled image training sample pair according to the labeled data and the background image; constructing an unlabeled image training sample pair according to the unlabeled data and the background image; training a target detection model to be trained by using the labeled image training sample pair and the unlabeled image training sample pair to obtain a pre-trained model; acquiring a target background image of a target scene and migrating the target region to the target background image; adjusting the pre-trained model by using the target background image with the target region migrated, taking the adjusted pre-trained model as a target detection model trained to detect a target in the target scene according to the target detection model.

2. The method of claim 1, wherein, The target region comprises a target bounding box and a category, and the labeled image training sample pair is constructed according to the labeled data and the background image, comprising: cutting the target region in the labeled data; randomly acquiring a first background image from the background image; copying the first background image to obtain a second background image; constructing a labeled image training sample pair according to the target region, the first background image and the second background image.

3. The method of claim 2, wherein, The labeled image training sample pair comprises a labeled positive sample pair and a labeled negative sample pair, and the labeled image training sample pair is constructed according to the target region, the first background image and the second background image, comprising: acquiring a specific target region from the target region; performing data enhancement processing on the specific target region to obtain an enhanced specific target region; randomly pasting the enhanced specific target region to the first background image to obtain an enhanced first background image; randomly acquiring a positive target region with the same category as the specific target region from the target region; performing data enhancement processing on the positive target region to obtain an enhanced positive target region; randomly pasting the enhanced positive target region to the second background image to obtain a positive second background image; constructing a labeled positive sample pair according to the enhanced first background image and the positive second background image; randomly acquiring a negative target region with a different category from the specific target region from the target region; randomly pasting the negative target region to the second background image to obtain a negative second background image; constructing a labeled negative sample pair according to the enhanced first background image and the negative second background image.

4. The method of claim 1, wherein, The unlabeled image training sample pair is constructed according to the unlabeled data and the background image, comprising: segmenting a segmentation region from the unlabeled data by using a visual model; extracting a background region from the background image by using a background difference algorithm; determining whether the segmentation region is a foreground region according to the background region; wherein the foreground region is a region comprising a target; when it is determined that the segmentation region is a foreground region, taking the segmentation region as a target segmentation region; randomly acquiring a third background image from the background image; copying the third background image to obtain a fourth background image; According to the target segmentation region, the third background image and the fourth background image, an unlabeled image training sample pair is constructed.

5. The method of claim 4, wherein, According to the background region, whether the segmentation region is a foreground region is determined, comprising: Calculating a pixel area intersection-over-union ratio of the segmentation region and the background region; According to the pixel area intersection-over-union ratio, whether the segmentation region is a foreground region is determined; If the pixel area intersection-over-union ratio is less than a preset threshold, the segmentation region is determined as a foreground region.

6. The method of claim 4, wherein, The labeled image training sample pair comprises an unlabeled positive sample pair and an unlabeled negative sample pair; according to the target segmentation region, the third background image and the fourth background image, an unlabeled image training sample pair is constructed, comprising: Performing data enhancement processing on the target segmentation region to obtain an enhanced target segmentation region; Randomly pasting the enhanced target segmentation region to the third background image to obtain an enhanced third background image; Randomly pasting the enhanced target segmentation region to the fourth background image to obtain an enhanced fourth background image; According to the enhanced third background image and the enhanced fourth background image, an unlabeled positive sample pair is constructed; Randomly obtaining a random background region which is a non-foreground region from the segmentation region; Randomly pasting the random background region to the fourth background image to obtain a random fourth background image; According to the enhanced third background image and the random fourth background image, an unlabeled negative sample pair is constructed.

7. The method of claim 1, wherein, The labeled image training sample pair and the unlabeled image training sample pair are used to train a target detection model to be trained to obtain a pre-training model, comprising: The labeled image training sample pair and the unlabeled image training sample are input into the target detection model to be trained to obtain a feature map; According to the training image, a feature corresponding to the target region is searched from the feature map; The features corresponding to the labeled image training sample pair are compared and learned, and the features corresponding to the unlabeled image training sample pair are compared and learned to obtain a pre-training model.

8. The method of claim 7, wherein, According to the training image, a feature corresponding to the target region is searched from the feature map, comprising: The corresponding training image is divided into a plurality of regions with the same resolution size as the feature map; The center points of the regions are taken as anchor points; The distances from the center points of the target bounding boxes in the training image to the anchor points are calculated; The positions of the anchor points closest to the distances in the regions divided by the training image are taken as target positions of the target region in the feature map; The features corresponding to the target positions in the feature map are taken as features corresponding to the target region.

9. The method of claim 3, wherein, The data enhancement processing at least comprises rotation translation, random cropping, color transformation, blurring, random noise and object randomness.

10. The method of claim 1, wherein, The method further comprises: Collecting training images and background data in a source scene; wherein the training images comprise a target region of a target to be detected, and the background data does not comprise the target region of the target to be detected; The training images are divided into to-be-labeled data and unlabeled data according to a preset ratio; The to-be-labeled data is labeled as labeled data; wherein the labeled data comprises a target bounding box and a category.

11. The method of claim 1, wherein, The method further comprises: The image to be detected is input into the trained target detection model to obtain the category and position of the target in the image to be detected.

12. The method of claim 1, wherein, The amount of labeled data is less than that of unlabeled data.

13. An object detection model training apparatus, comprising: The device comprises: The first obtaining module is configured to obtain a training image corresponding to a source scene and a background image; the training image comprises labeled data and unlabeled data, and the training image comprises a target region; the background image does not comprise the target region; The first constructing module is configured to construct a labeled image training sample pair according to the labeled data and the background image; The second constructing module is configured to construct an unlabeled image training sample pair according to the unlabeled data and the background image; The pre-training module is configured to train a target detection model to be trained by using the labeled image training sample pair and the unlabeled image training sample pair to obtain a pre-trained model; The second obtaining module is configured to obtain a target background image of a target scene and migrate the target region to the target background image; The adjusting module is configured to adjust the pre-trained model by using the target background image with the target region migrated, and use the adjusted pre-trained model as a trained target detection model to detect a target in a target scene according to the adjusted target detection model.

14. An electronic device, comprising: The device comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is configured to store a computer program; The processor is configured to execute the program stored in the memory to implement the method of any one of claims 1-12.

15. A computer readable storage medium having instructions stored thereon that, when executed by one or more processors, cause the processors to perform the method of any one of claims 1-12.

Citation Information

Patent Citations

  • Image target detection method and device, terminal equipment and storage medium

    CN111242234A

  • Target detection method and device, electronic equipment and storage medium

    CN113095434A