Target detection method, device and storage medium
By conducting background prediction training on negative sample data groups, the problem of ignoring background images when training in multiple scenarios and domains is solved, reducing the error detection rate and improving the accuracy of the model.
Patent Information
- Application Number
- CN202011271127.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-13
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2040-11-13
Smart Images

Figure CN113743439B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of computer technology, and in particular to a target detection method, device and storage medium. Background Art
[0002] At present, in order to ensure the accuracy of target detection, the detection results can be obtained through the target detection model. In the prior art, image target detection using convolutional neural networks is the mainstream method of current target detection. In particular, its data-driven characteristics can greatly improve the detection index when there is a large amount of target data. In the process of implementing target detection with convolutional neural networks, sample data is needed to train the target detection model, and the sample data is mainly pictures.
[0003] In the existing open-set big data scenario, the target detection model needs to adapt to data from a variety of different scenarios and domains. Most of the data from different scenarios and domains have different distributions and complex backgrounds. The target that the model needs to detect often occupies a very small part of the image. The solution used in the training of the target detection model will cause the target detection model to ignore the training of a large number of images with only backgrounds, resulting in insufficient training of the target detection model, which will cause a large number of false detections in the detection application. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a target detection method, device and storage medium. The target detection method provided by the embodiment of the present invention has a low false detection rate when detecting a current image to be detected.
[0005] An embodiment of the present invention provides a target detection method, including:
[0006] Get the current image to be detected;
[0007] Using the target detection model to perform target detection on the current image to be detected, and predicting the current detection result;
[0008] The target detection model is obtained after background class prediction training is performed on a data group that is all negative samples.
[0009] In the above scheme, before performing target detection on the current image to be detected using a preset target detection model and predicting the current detection result, the method further includes:
[0010] Acquire a training image set; the training image set includes a plurality of data groups, and one data group includes a plurality of samples for training;
[0011] If the one data group does not include positive samples, extracting a first predetermined number of first negative samples from the trained sample set;
[0012] Inputting the first negative sample into an initial detection model to obtain a first predicted background class result;
[0013] In the back propagation stage, the initial detection model is trained based on the first predicted background class result and the true result corresponding to the first negative sample until the target detection model is obtained.
[0014] In the above solution, after acquiring the training image set, the method further includes:
[0015] Inputting the training image set into an image recognition model to obtain a first image recognition result;
[0016] When the first image recognition result corresponding to the one data group has an image whose degree of fit with the preset standard result is greater than a fit threshold, determining that the one data group contains a positive sample;
[0017] When there is no image in the first image recognition result corresponding to a data group whose degree of fit with a preset standard result is greater than a fit threshold, it is determined that the data group does not contain a positive sample.
[0018] In the above solution, if the one data group does not include positive samples, extracting a first predetermined number of first negative samples from the trained sample set includes:
[0019] If the one data group does not include positive samples, then extracting a first predetermined number of first negative samples from the second negative samples of the sample set that have been trained, according to the negative sample losses corresponding to the second negative samples, in the order of negative sample losses from large to small;
[0020] The first predetermined number is an integer multiple of the number of samples in the one data group.
[0021] In the above solution, after acquiring the training image set, the method further includes:
[0022] If the one data group includes the positive sample, extracting a second positive sample and a second negative sample from the one data group according to a first predetermined ratio;
[0023] The second positive sample and the second negative sample are input into an initial detection model to obtain a target result corresponding to the second positive sample and a second predicted background class result corresponding to the second negative sample.
[0024] In the above scheme, when there are data groups of positive samples and data groups of non-positive samples in the training image set, in the back propagation stage, the initial detection model is trained based on the first predicted background class result and the real result corresponding to the first negative sample until the target detection model is obtained, including:
[0025] In the back propagation stage, the negative sample loss is determined according to the first preset loss function, the first predicted background class result and the first true result corresponding to the first negative sample;
[0026] Determine the positive sample loss according to a second preset loss function, the target result and the second predicted background class result, a target true result corresponding to the target result, and a second true result corresponding to the second negative sample;
[0027] Based on the positive sample loss and the negative sample loss, the initial detection model is trained until a target detection model is obtained.
[0028] In the above solution, the initial detection model is trained based on the negative sample loss and the positive sample loss until the target detection model is obtained, including:
[0029] Determine a current loss according to the negative sample loss and the positive sample loss;
[0030] If the current loss is greater than the preset loss threshold, the next training image set is obtained, and the initial detection model is continuously trained until the next loss is no greater than the preset loss threshold, thereby obtaining the target detection model.
[0031] In the above solution, determining the current loss according to the negative sample loss and the positive sample loss includes:
[0032] The positive sample loss and the negative sample loss are weighted to determine the current loss; wherein a first weight corresponding to the positive sample loss is greater than a second weight corresponding to the negative sample loss.
[0033] In the above solution, the weighted processing of the positive sample loss and the negative sample loss to determine the current loss includes:
[0034] The positive sample loss is multiplied by the first weight, and the result is added to the product of the negative sample loss and the second weight to obtain the current loss.
[0035] A target detection device is also provided, comprising:
[0036] An image acquisition unit, used to acquire the current image to be detected;
[0037] A detection unit, used to perform target detection on the current image to be detected using a target detection model, and predict a current detection result;
[0038] The target detection model is obtained after background class prediction training is performed on a data group that is all negative samples.
[0039] A target detection device is also provided, comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and the steps in the above method are implemented when the processor executes the program.
[0040] A computer-readable storage medium is also provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the above method are implemented.
[0041] In the embodiment of the present invention, the current image to be detected is obtained; the target detection model is used to perform target detection on the current image to be detected, and the current detection result is predicted; wherein the target detection model is obtained after background class prediction training is performed on a data group that is all negative samples. The target detection model can increase the training amount of background class prediction training of the target detection model by performing background class prediction training on a data group that is all negative samples, and reduce the probability of false detection of the target detection model when it is applied. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 An optional effect diagram of a data group provided by an embodiment of the present invention;
[0043] Figure 2 An optional effect diagram of a data group provided by an embodiment of the present invention;
[0044] Figure 3 An optional rendering of an image to be detected provided by an embodiment of the present invention;
[0045] Figure 4 An optional rendering of an image to be detected provided by an embodiment of the present invention;
[0046] Figure 5 Schematic diagram of the process of the target detection method provided by the embodiment of the present invention Figure 1 ;
[0047] Figure 6 Schematic diagram of the process of the target detection method provided by the embodiment of the present invention Figure 2 ;
[0048] Figure 7 Schematic diagram of the process of the target detection method provided by the embodiment of the present invention Figure 3 ;
[0049] Figure 8Schematic diagram of the process of the target detection method provided by the embodiment of the present invention Figure 4 ;
[0050] Fig. 9 Schematic diagram of the process of the target detection method provided by the embodiment of the present invention Figure 5 ;
[0051] Fig.10 Schematic diagram of the process of the target detection method provided by the embodiment of the present invention Figure 6 ;
[0052] Fig.11 Schematic diagram of the process of the target detection method provided by the embodiment of the present invention Figure 7 ;
[0053] Fig.12 A schematic diagram of the structure of a target detection device provided by an embodiment of the present invention;
[0054] Fig.13 A schematic diagram of a hardware entity of a target detection device provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical solutions and advantages of the present invention clearer, the technical solutions of the present invention are further elaborated in detail below in conjunction with the drawings and embodiments. The described embodiments should not be regarded as limiting the present invention. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present invention.
[0056] In the following description, reference is made to “some embodiments”, which describe a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0057] If similar descriptions of "first / second" appear in the invention document, the following description is added. In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged in a specific order or sequence where permitted, so that the embodiments of the invention described herein can be implemented in an order other than that illustrated or described herein.
[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which the present invention belongs. The terms used herein are only for the purpose of describing the embodiments of the present invention and are not intended to limit the present invention.
[0059] The present invention provides a target detection model training. Figure 5 , which is a schematic diagram of the process of the target detection method provided by the embodiment of the present invention Figure 1 .
[0060] S01, obtaining the current image to be detected.
[0061] In an embodiment of the present invention, the image to be detected includes an image frame or a photo in a video frame. The image to be detected may or may not include a target. The target in the image to be detected may include a face, a QR code, a car, a pedestrian, a mobile phone, and other targets with physical images that can be detected by the target detection model.
[0062] In an embodiment of the present invention, the target detection device can obtain the image to be detected through the image acquisition unit of the target detection device. The image to be detected is stored in a database in advance according to a predetermined rule, wherein the image to be detected can be classified and stored in the database by the size of the image, or can be classified and stored in the database by the source of the image to be detected. The image acquisition unit establishes a communication connection with the database storing the image to be detected, and when the target detection model receives the detection instruction, the database transmits the specified image to be detected to the image acquisition unit for the target detection model to detect.
[0063] S02, using the target detection model to perform target detection on the current image to be detected, and predict the current detection result.
[0064] In an embodiment of the present invention, the target detection model includes a detection model based on a convolutional neural network model. The target detection model is obtained after background class prediction training is performed on a data group that is all negative samples. After the background class prediction training, the target detection model can effectively process a large number of images to be detected in different domains, and the target detection model after the background class prediction training has a significantly reduced false detection rate when processing images to be detected. In an embodiment of the present invention, the network structure of the target detection model includes: a real-time fast target detection model (You Only Look Once, YOLO) or a single-machine multi-card target detection algorithm (Single Shot MultiBox Detector, SSD). Among them, the network structure of the target detection model may include: an input layer, several intermediate layers and an output layer. The target detection model obtains the image to be detected through an image acquisition unit, inputs the image to be detected into the input layer of the target detection model, and after the intermediate layer of the target detection model processes the image to be detected, the output layer of the target detection model outputs the coordinate information and confidence of the target in the image to be detected. Combined with Figure 4In the embodiment of the present invention, the image 3 to be detected is input into the trained target detection model, and the target result 4 frame of the image 3 to be detected can be obtained after the target detection model is initialized. Then, the target result 4 is compared and calculated with the target true result, and the coordinate information and confidence of the target result 4 of the image 3 to be detected can be output.
[0065] In the embodiment of the present invention, the current image to be detected is obtained; the target detection model is used to perform target detection on the current image to be detected, and the current detection result is predicted; wherein the target detection model is obtained after background class prediction training is performed on a data group that is all negative samples. The target detection model can increase the training amount of the target detection model by performing background class prediction training on a data group that is all negative samples, and reduce the probability of false detection of the target detection model when it is applied.
[0066] In some embodiments, see Figure 6 , Figure 6 is an optional flow chart of the method provided in an embodiment of the present invention, Figure 5 The step S01 or S02 shown may also include S03 to S06, which will be described in conjunction with each step.
[0067] S03, obtaining a training image set.
[0068] In an embodiment of the present invention, before the target detection model detects the image to be detected, or before the target detection model obtains the current image to be detected, a large amount of background class prediction training needs to be performed on the target detection model. Before the target detection model completes the background class prediction training, it is an initial detection model. The initial detection model obtains a training image set, wherein the training image set includes multiple data groups, and each data group includes multiple samples for initial detection model training.
[0069] In an embodiment of the present invention, samples are pre-stored in a sample database, wherein the sample database may include positive samples and negative samples. In an embodiment of the present invention, a positive sample may be a picture including a face, a picture including a QR code, or a picture including a mobile phone. A negative sample may be a picture not including a face, a picture not including a QR code, or a picture not including a mobile phone. Before the initial detection model is trained, the samples in the sample database are divided into a plurality of data groups. The sample database is communicatively connected to the initial detection model, and the sample database transmits a training image set including a plurality of data groups to the initial detection model.
[0070] Combination Figure 1In an embodiment of the present invention, the data group in the training image set acquired by the initial detection model may include data group 1. Data group 1 is composed of positive samples and negative samples extracted from the sample database at a ratio of 1:3. Data group 1 includes 8 samples, the positive samples are pictures including faces, and the negative samples are pictures not including faces. Among them, sample 1 and sample 2 are positive samples, and sample 3, sample 4, sample 5, sample 6, sample 7 and sample 8 are negative samples. In an embodiment of the present invention, the initial detection model can establish a communication connection with the sample database, and when the initial detection model needs to be trained, the sample database transmits data group 1 to the initial detection model.
[0071] Combination Figure 2 , in an embodiment of the present invention, the data group acquired by the initial detection model may include data group 2. Data group 2 may be composed of samples extracted from a sample database. Data group 2 includes 8 samples, positive samples are pictures including faces, and negative samples are pictures not including faces. Sample 1, sample 2, sample 3, sample 4, sample 5, sample 6, sample 7, and sample 8 are all negative samples. The way in which the initial detection model acquires data group 2 is the same as the way in which the initial detection model acquires data group 1, which will not be described one by one here.
[0072] S04: If a data group does not include positive samples, extract a first predetermined number of first negative samples from the trained sample set.
[0073] In an embodiment of the present invention, after the initial detection model obtains multiple data groups in the training image set, it is first necessary to determine whether the data group includes positive samples. The initial detection model compares the samples in the training image set with the preset standard results, and can distinguish and mark the positive samples and negative samples in the data group. After the data group enters the initial detection model, the processing unit of the initial detection model identifies the positive samples and negative samples in the data group. When it is identified that the samples in a data group do not include positive samples, the initial detection model extracts a first predetermined number of first negative samples from the trained sample set.
[0074] The initial detection model extracts a first predetermined number of first negative samples from the trained sample set in the order of negative sample loss from large to small. The trained sample set may be a set of samples from other trained data groups in this model training. The trained sample set includes positive samples and negative samples from other trained data groups. After the other trained data groups have completed training, the initial detection model can obtain the losses corresponding to the trained positive and negative samples. The initial detection model stores the trained positive and negative samples to form a sample set. Combined with Figure 2In the embodiment of the present invention, when the data set 2 acquired by the initial detection model does not include positive samples, the initial detection model extracts 16 first negative samples from the sample set. The number of the first negative samples is exactly twice the number of samples in the data set 2.
[0075] S05: Input the first negative sample into the initial detection model to obtain a first predicted background class result.
[0076] In the embodiment of the present invention, after the initial detection model obtains the first negative sample, the initial detection model can use a sliding window method or a selective search method to predict the first predicted background class result on the first negative sample. Figure 3 When the initial detection model obtains the image to be detected 1, the intermediate layer of the initial detection model can use the sliding window method to predict the first predicted background class result 2 on the image to be detected 1.
[0077] S06, in the back propagation stage, the initial detection model is trained based on the first predicted background class result and the true result corresponding to the first negative sample until the target detection model is obtained.
[0078] In an embodiment of the present invention, one training of the initial detection model can be represented by the following stages: a forward propagation stage, a back propagation stage, and a weight update stage. In the forward propagation stage, the first negative sample is input from the input layer and transmitted backward to the output layer. In the back propagation stage, the first negative sample is transmitted forward from the output layer to the input layer. In the target detection method proposed in the embodiment of the present invention, the first negative sample is input into the network structure of the initial detection model to be trained in the forward propagation stage. The network structure of the initial detection model calculates the loss corresponding to the first negative sample through a loss function based on the first predicted background class result of the first negative sample and the true result corresponding to the first negative sample. Among them, the true result corresponding to the first negative sample is the background class result of the negative sample that is pre-calibrated manually or by machine.
[0079] In an embodiment of the present invention, the network structure of the initial detection model calculates the loss corresponding to the first negative sample based on the loss function, and adds the loss of the first negative sample and the losses corresponding to other data groups to obtain the current loss. If the current loss is greater than the loss threshold, the network structure of the initial detection model will be based on the current loss through the output layer, back-propagated to the intermediate layer and the input layer layer by layer, and the weights of each layer will be corrected by gradient descent. After the weights of each layer of the network structure of the initial detection model are corrected, the network structure of the initial detection model will continue to train the newly acquired training image set. The process of training the initial detection model to obtain the target detection model continues until the current loss calculated by the initial detection model is not greater than the loss threshold, or until the number of initial detection model training reaches a preset number of training times.
[0080] The embodiment of the present invention extracts a first negative sample from a trained sample set; inputs the first negative sample into an initial detection model to obtain a first predicted background class result; in the back propagation stage, the initial detection model is trained based on the first predicted background class result and the real result corresponding to the first negative sample until a target detection model is obtained. A large amount of background class prediction training can be performed even when there is no target sample in the initial detection model training, thereby increasing the training amount of the initial detection model and reducing the probability of false detection when the target detection model is applied.
[0081] In some embodiments, see Figure 7 , Figure 7 is an optional flow chart of the method provided in an embodiment of the present invention, Figure 6 S101 - S103 are also included between S03 and S04 shown, and will be explained in conjunction with each step.
[0082] S101, inputting a training image set into an image recognition model to obtain a first image recognition result.
[0083] In an embodiment of the present invention, after the initial detection model obtains each sample of the data group in the training image set, the sample in the training image set is input into the image recognition model, wherein the image recognition model can be a pre-established convolutional neural network model, and the image recognition model is a branch model of the initial detection model. The image recognition model processes each sample in the training image set to obtain a first image recognition result corresponding to each sample. That is, the first image recognition result of each sample in the data group can be obtained.
[0084] In an embodiment of the present invention, the first image recognition result is a recognition block diagram of a corresponding sample. The image recognition model processes the positive sample to obtain the first image recognition result corresponding to the positive sample, wherein the first image recognition result corresponding to the positive sample includes the target. The image recognition model processes the negative sample to obtain the first image recognition result corresponding to the negative sample, wherein the first image recognition result corresponding to the negative sample includes the background area of the negative sample.
[0085] S102, when a first image recognition result corresponding to a data group has an image whose degree of fit with a preset standard result is greater than a fit threshold, it is determined that a data group contains a positive sample.
[0086] In the embodiment of the present invention, the initial detection model compares and calculates the first image recognition results corresponding to the samples in a data group with the preset standard results, and can obtain the degree of fit between the first image recognition results corresponding to all samples in a data group and the preset standard results. When there is a first image recognition result corresponding to a sample in a data group and the degree of fit between the preset standard result is greater than the fit threshold, the data group includes a positive sample.
[0087] In the embodiment of the present invention, the fit threshold is an artificially set constant used to determine the error between the first image recognition result and the preset standard result of the sample in the data group. If the fit is greater than the fit threshold, it means that the error between the first image recognition result and the preset standard result is small, which means that the sample corresponding to the first image recognition result is a positive sample.
[0088] Exemplary Combinations Figure 1 When the initial detection model obtains data group 1, it identifies that the samples in data group 1 have a degree of fit with the preset standard results greater than the fit threshold, which means that data group 1 includes positive samples.
[0089] In the embodiment of the present invention, the degree of fit includes the overlap rate of the image between the first image recognition result and the preset standard result. The degree of fit threshold is a preset overlap rate threshold. When the degree of fit is greater than the degree of fit threshold, it means that the overlap rate of the image between the first image recognition result and the preset standard result is very high. The first image recognition result is very similar to the preset standard result.
[0090] S103: When a first image recognition result corresponding to a data group does not contain an image whose degree of fit with a preset standard result is greater than a fit threshold, it is determined that the data group does not contain a positive sample.
[0091] In the embodiment of the present invention, when the degree of fit between the first image recognition result corresponding to the sample that does not exist in a data group and the preset standard result is greater than the fit threshold, the data group does not include a positive sample.
[0092] In the embodiment of the present invention, the fit threshold may be a manually set constant used to determine the error between the first image recognition result and the preset standard result of the sample in the data group. If the fit is not greater than the fit threshold, it means that the error between the first image recognition result and the preset standard result is large, which means that the sample corresponding to the first image recognition result is a negative sample.
[0093] In the embodiment of the present invention, the degree of fit includes the overlap rate of the image between the first image recognition result and the preset standard result. The degree of fit threshold is a preset overlap rate threshold. When the degree of fit is not greater than the degree of fit threshold, it means that the overlap rate of the image between the first image recognition result and the preset standard result is very low. The first image recognition result is very different from the preset standard result.
[0094] Exemplary Combinations Figure 2 When the initial detection model obtains data group 2, it recognizes that there is no sample in data group 2 and the fit degree of the preset standard result is greater than the fit threshold, which means that data group 2 does not include positive samples.
[0095] In some embodiments, see Figure 8 , Figure 8 is an optional flow chart of the method provided in an embodiment of the present invention, Figure 6 S21-S22 are also included between S03 and S06, and will be described in conjunction with each step.
[0096] S21: If a data group includes a positive sample, extract a second positive sample and a second negative sample from the data group according to a first predetermined ratio.
[0097] In an embodiment of the present invention, if a data set includes a positive sample, the initial detection model will extract a second positive sample and a second negative sample from the data set according to a first predetermined ratio, wherein the positive sample is a sample including a target.
[0098] In an embodiment of the present invention, the first predetermined ratio may be a ratio of 1:3, 1:2, or 1:4. The number of samples in a data group is usually 10 or 20. The initial detection model extracts a certain number of second positive samples and second negative samples in a data group according to the first predetermined ratio.
[0099] In the embodiment of the present invention, the initial detection model determines that a data group includes a positive sample through S101-S103, and then extracts a second positive sample and a second negative sample from the data group according to a first predetermined ratio. Figure 1 , in the embodiment of the present invention, the data group acquired by the initial detection model may be data group 1. Data group 1 includes 8 samples. Among them, sample 1 and sample 2 are positive samples, and sample 3, sample 4, sample 5, sample 6, sample 7 and sample 8 are negative samples. In the embodiment of the present invention, the second positive sample and the second negative sample may be extracted from data group 1 in a ratio of 1:3 or 1:4, respectively. For example, 1 second positive sample and 3 second negative samples are extracted from data group 1. Among them, the second positive sample may include: sample 1, and the second negative sample may include: sample 3, sample 4 and sample 5.
[0100] S22, inputting the second positive sample and the second negative sample into the initial detection model to obtain a target result corresponding to the second positive sample and a second predicted background class result corresponding to the second negative sample.
[0101] In an embodiment of the present invention, the second positive sample and the second negative sample are input into the initial detection model, and after initialization of the initial detection model, the target result corresponding to the second positive sample and the second predicted background class result corresponding to the second negative sample can be obtained.
[0102] In the embodiment of the present invention, the target result corresponding to the second positive sample may be a picture frame including only the target, and the predicted background class result corresponding to the second negative sample may be a picture frame including the background area on the second negative sample.
[0103] In the embodiment of the present invention, after the initial detection model obtains 1 second positive sample and 3 second negative samples. The initial detection model can use the sliding window method or the selective search method to process sample 1 in the second positive sample to obtain the target result corresponding to the second positive sample, wherein the target result is the face area in sample 1. At the same time, the initial detection model can use the sliding window method or the selective search method to process samples 3, 4, and 5 in the second negative sample to obtain the second predicted background class result corresponding to sample 3, the second predicted background class result corresponding to sample 4, and the second predicted background class result corresponding to sample 5. Among them, the second predicted background class result corresponding to sample 3 is the bonsai image area in sample 3, the second predicted background class result corresponding to sample 4 is the laptop computer image area in sample 4, and the second predicted background class result corresponding to sample 5 is the pony image area in sample 5.
[0104] In some embodiments, see Fig. 9 , Fig. 9 is an optional flow chart of the method provided in an embodiment of the present invention, Figure 6 The illustrated S06 can be implemented through S23-S25, which will be described in conjunction with each step.
[0105] S23, in the back propagation stage, determining the negative sample loss according to the first preset loss function, the first predicted background class result and the first true result corresponding to the first negative sample.
[0106] In an embodiment of the present invention, the initial detection model can determine the negative sample loss according to a first preset loss function, a first predicted background class result, and a first true result corresponding to the first negative sample, wherein the first preset loss function can be a cross entropy loss function or an L2 loss function.
[0107] In an embodiment of the present invention, the coordinates of the center point of the first predicted background class result of the first negative sample, the width of the first predicted background class result, and the height of the first predicted background class result can be obtained through the network structure of the initial detection model. At the same time, the network structure of the initial detection model can also obtain the true distribution probability of the sample on the first negative sample by comparing the coordinates of the center point of the first predicted background class result, the width of the first predicted background class result, and the height of the first predicted background class result with the first true result corresponding to the first negative sample.
[0108] In an embodiment of the present invention, the network structure of the initial detection model can calculate the negative sample loss by using a cross entropy loss function or an L2 loss function on the first negative sample. In an embodiment of the present invention, the cross entropy loss function formula (1) is:
[0109]
[0110] Among them, n is the number of the first negative samples, p(x i ) is the true distribution probability of the first negative sample of the i-th order, q(x i ) is the predicted distribution probability of the i-th first negative sample. The initial detection model can obtain the negative sample loss of the first negative sample by calculating the difference between the true distribution probability of the first negative sample and the predicted distribution probability of the first negative sample.
[0111] S24, determining the positive sample loss according to the second preset loss function, the target result and the second predicted background class result, the target true result corresponding to the target result, and the second true result corresponding to the second negative sample.
[0112] In an embodiment of the present invention, the initial detection model determines the second positive sample loss based on the target result and the target true result corresponding to the target result through the second loss function. The initial detection model determines the second negative sample loss based on the second predicted background class result and the second true result corresponding to the second negative sample through the second loss function. The second positive sample loss and the second negative sample loss are added to form the positive sample loss.
[0113] In an embodiment of the present invention, the coordinates of the center point of the target result on the second positive sample, the width of the target result and the height of the predicted target result can be obtained through the network structure of the initial detection model. At the same time, the network structure of the initial detection model can also calculate the true distribution probability of the sample on the second positive sample through the coordinates of the center point of the target result, the width of the target result and the height of the target result and the target true result corresponding to the second positive sample, and collect the pixel value of each pixel on the target result. The network structure of the initial detection model has measured the coordinates of the center point of the second predicted background class result of the second negative sample, the width of the second predicted background class result and the height of the second predicted background class result, which can be obtained through the network structure of the initial detection model. At the same time, the network structure of the initial detection model can also calculate the true distribution probability of the sample on the second negative sample through the coordinates of the center point of the second predicted background class result, the width of the second predicted background class result and the height of the second predicted background class result and the second true result corresponding to the second negative sample, and collect the pixel value of each pixel on the second predicted background class result.
[0114] In an embodiment of the present invention, the network structure of the initial detection model calculates the second positive sample and the second negative sample through the cross entropy loss function and the L2 loss function to determine the positive sample loss. Among them, the positive sample loss includes the second positive sample loss and the second negative sample loss. In an embodiment of the present invention, the initial detection model calculates the second negative sample loss through the cross entropy loss function, and the cross entropy loss function formula (1) is:
[0115]
[0116] Among them, n is the number of the second negative samples, p(x i ) is the true distribution probability of the i-th second negative sample, q(x i ) is the predicted distribution probability of the i-th second negative sample. The initial detection model can obtain the second negative sample loss by calculating the difference between the true distribution probability of the second negative sample and the predicted distribution probability of the second negative sample.
[0117] In the embodiment of the present invention, the initial detection model calculates the second positive sample loss through the L2 loss function, and the L2 loss function formula (2) is:
[0118]
[0119] Where N is the number of second positive samples, P is the total number of pixels in a single second positive sample, and O ij (θ) is the output value of the jth pixel in the i-th second positive sample, Y ij is the value of the jth pixel unit in the i-th sample in the true result corresponding to the second positive sample, ξ j The weight given to the target in the second positive sample. Among them, P and O ij (θ) can be obtained through the primary detection model. The initial detection model can obtain the second positive sample loss by calculating the loss of the second positive sample and the true result corresponding to the second positive sample.
[0120] In this embodiment of the present invention, the second negative sample loss and the second positive sample loss are added to obtain the positive sample loss.
[0121] S25, based on the positive sample loss and the negative sample loss, the initial detection model is trained until the target detection model is obtained.
[0122] In an embodiment of the present invention, the initial detection model adds the positive sample loss and the negative sample loss to obtain the current loss of the initial detection model. If the current loss is greater than the loss threshold, the initial detection model obtains the next training image set for the next model training until the next loss is no greater than the loss threshold, thereby obtaining the target detection model.
[0123] In an embodiment of the present invention, the initial detection model adds the positive sample loss and the negative sample loss to obtain the current loss of the initial detection model. If the current loss is greater than the loss threshold, the initial detection model obtains the next training image set for the next model training until the initial detection model is trained a predetermined number of times to obtain a target detection model.
[0124] In some embodiments, see Fig.10 , Fig.10 is an optional flow chart of the method provided in an embodiment of the present invention, Fig. 9 The illustrated S25 can be implemented through S26-S27, which will be described in conjunction with each step.
[0125] S26, determining a current loss according to the negative sample loss and the positive sample loss.
[0126] In the embodiment of the present invention, the current loss can be obtained by adding the positive sample loss and the negative sample loss.
[0127] In the embodiment of the present invention, the positive sample loss is the loss calculated by the loss function for the data set including the positive sample. The negative sample loss is the loss calculated by the loss function for the data set not including the positive sample. The current loss is the loss obtained by training the initial detection model once for the training image set.
[0128] S27, if the current loss is greater than the preset loss threshold, the next training image set is obtained, and the initial detection model is continuously trained until the next loss is no greater than the preset loss threshold, thereby obtaining the target detection model.
[0129] In an embodiment of the present invention, if the current loss is greater than a preset loss threshold, the network structure of the initial detection model will be back-propagated layer by layer to the intermediate layer and the input layer through the output layer based on the current loss, and the weights of each layer of the initial detection model will be corrected by gradient descent. After the weights of each layer of the network structure of the initial detection model are corrected, the network structure of the initial detection model will continue to train the newly acquired training image set. The process of training the initial detection model to obtain the target detection model continues until the current loss calculated by the initial detection model is not greater than the preset loss threshold, or until the number of initial detection model training reaches a preset number of training times.
[0130] In an embodiment of the present invention, the next training image set acquired by the initial detection model may be acquired in the same manner as the current training image set. In some embodiments, the initial detection model may use the current training image set as the next training image set.
[0131] In some embodiments, see Fig.11 , Fig.11is an optional flow chart of the method provided in an embodiment of the present invention, Fig.10 The illustrated S26 can be implemented through S28, which will be described in conjunction with each step.
[0132] S28, weighting the positive sample loss and the negative sample loss to determine the current loss.
[0133] In an embodiment of the present invention, the initial detection model is trained to obtain the positive sample loss and negative sample loss corresponding to the data group in the newly acquired training image set. The positive sample loss corresponding to the data group in the newly acquired training image set is multiplied by the first weight, and the negative sample loss corresponding to the data group in the newly acquired training image set is multiplied by the second weight. The initial detection model adds the adjusted positive sample loss and negative sample loss to determine the current loss. The first weight is greater than the second weight.
[0134] In an embodiment of the present invention, when the initial detection model trains the positive sample loss corresponding to the data group in the newly acquired training image set, the target result of the data group including the positive sample in the training image set is multiplied by the first weight to calculate the positive sample loss. The initial detection model adds the positive sample loss and the negative sample loss to determine the current loss.
[0135] In an embodiment of the present invention, when the initial detection model trains the positive sample loss corresponding to the data group in the newly acquired training image set, the second positive sample loss in the positive sample loss is multiplied by the first weight, and then added to the second negative sample loss to obtain the positive sample loss. The initial detection model adds the positive sample loss and the negative sample loss to determine the current loss.
[0136] See also Fig.12 , is a schematic diagram of the structure of a target detection device provided in an embodiment of the present invention.
[0137] In the embodiment of the present invention, the target detection device 800 includes: an image acquisition unit 81 and a detection unit 82 .
[0138] An image acquisition unit 81 is used to acquire the current image to be detected;
[0139] The detection unit 82 is used to perform target detection on the current image to be detected using the target detection model and predict the current detection result. In the embodiment of the present invention, the target detection model includes a detection model based on a convolutional neural network model. The target detection model is obtained after background class prediction training is performed on a data group that is all negative samples. After the background class prediction training, the target detection model can effectively process a large number of images to be detected in different domains, and the target detection model after the background class prediction training has a significantly reduced false detection rate when processing the image to be detected.
[0140] In the embodiment of the present invention, the target detection device 800 first obtains a training image set when performing background class prediction training. The training image set includes multiple data groups, and one data group includes multiple samples for training; if a data group does not include a positive sample, the target detection device 800 extracts a first predetermined number of first negative samples from the trained sample set; the target detection device 800 inputs the first negative sample into the initial detection model to obtain a first predicted background class result; in the back propagation stage, the target detection device 800 trains the initial detection model based on the first predicted background class result and the real result corresponding to the first negative sample until the target detection model is obtained.
[0141] In the embodiment of the present invention, after acquiring the training image set, the target detection device 800 also needs to determine whether the data group in the training image set includes a positive sample. The target detection device 800 inputs the training image set into the image recognition model to obtain a first image recognition result; when the first image recognition result corresponding to a data group has an image whose degree of fit with the preset standard result is greater than the fit threshold, it is determined that a data group contains a positive sample; when the first image recognition result corresponding to a data group does not have an image whose degree of fit with the preset standard result is greater than the fit threshold, it is determined that a data group does not contain a positive sample.
[0142] In an embodiment of the present invention, if a data group does not include positive samples, the target detection device 800 extracts a first predetermined number of first negative samples from the second negative samples of the trained sample set, according to the negative sample losses corresponding to the second negative samples, in order of negative sample losses from large to small; the first predetermined number can be an integer multiple of the number of samples in a data group.
[0143] In an embodiment of the present invention, if a data group includes a positive sample, the target detection device 800 extracts a second positive sample and a second negative sample from the data group according to a first predetermined ratio; the second positive sample and the second negative sample are input into the initial detection model to obtain a target result corresponding to the second positive sample and a second predicted background class result corresponding to the second negative sample. In the back propagation stage, the target detection device 800 determines the negative sample loss according to the first preset loss function, the first predicted background class result and the first true result corresponding to the first negative sample. The target detection device 800 determines the positive sample loss according to the second preset loss function, the target result and the second predicted background class result, the target true result corresponding to the target result, and the second true result corresponding to the second negative sample. The negative sample loss and the positive sample loss are added to determine the current loss; if the current loss is greater than the preset loss threshold, the target detection device 800 obtains the next training image set and continues to train the initial detection model until the next loss is not greater than the preset loss threshold, thereby obtaining the target detection model.
[0144] In an embodiment of the present invention, the object detection device 800 may also perform weighted processing on the positive sample loss and the negative sample loss to determine the current loss; wherein the first weight corresponding to the positive sample loss is greater than the second weight corresponding to the negative sample loss. The object detection device 800 may multiply the positive sample loss and the first weight and then add the product of the negative sample loss and the second weight to obtain the current loss.
[0145] In the embodiment of the present invention, the current image to be detected is acquired by the image acquisition unit; the detection unit is used to perform target detection on the current image to be detected using the target detection model, and predict the current detection result; wherein the target detection model is obtained after background class prediction training is performed on a data group that is all negative samples. The target detection model can increase the training amount of the target detection model by performing background class prediction training on a data group that is all negative samples, and reduce the probability of false detection of the target detection model when it is applied.
[0146] It should be noted that, in the embodiment of the present invention, if the above-mentioned target detection method is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the relevant technology. The computer software product is stored in a storage medium, including several instructions to enable a target detection device (which can be a personal computer, or a network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk. In this way, the embodiment of the present invention is not limited to any specific combination of hardware and software.
[0147] Correspondingly, an embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the above method are implemented.
[0148] Correspondingly, an embodiment of the present invention provides a target detection device, including a memory 803 and a processor 801, wherein the memory 803 stores a computer program that can be executed on the processor 801, and the processor 801 implements the steps in the above method when executing the program.
[0149] It should be noted that the description of the above storage medium and device embodiments is similar to the description of the above method embodiments, and has similar beneficial effects as the method embodiments. For technical details not disclosed in the storage medium and device embodiments of the present invention, please refer to the description of the method embodiments of the present invention for understanding.
[0150] It should be noted that Fig.13 A schematic diagram of a hardware entity of a target detection device provided by an embodiment of the present invention, such as Fig.13 As shown, the hardware entity of the target detection device 800 includes: a processor 801, a communication interface 802 and a memory 803, wherein
[0151] The processor 801 generally controls the overall operation of the object detection apparatus 800 .
[0152] The communication interface 802 enables the target detection device to communicate with a data set or a sample database through a network.
[0153] The memory 803 is configured to store instructions and applications executable by the processor 801, and can also cache data to be processed or processed by the processor 801 and each module in the target detection device 800 (for example, image data, audio data, voice communication data, and video communication data), which can be implemented through flash memory (FLASH) or random access memory (Random Access Memory, RAM).
[0154] It should be understood that "one embodiment" or "an embodiment" mentioned throughout the specification means that specific features, structures or characteristics related to the embodiment are included in at least one embodiment of the present invention. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. In addition, these specific features, structures or characteristics can be combined in one or more embodiments in any suitable manner. It should be understood that in various embodiments of the present invention, the size of the serial number of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention. The serial numbers of the above-mentioned embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments.
[0155] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.
[0156] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as: multiple units or components can be combined, or can be integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the components shown or discussed can be through some interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0157] The units described above as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units; they may be located in one place or distributed on multiple network units; some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0158] In addition, all functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may be separately used as a unit, or two or more units may be integrated into one unit; the above-mentioned integrated units may be implemented in the form of hardware or in the form of hardware plus software functional units.
[0159] A person skilled in the art can understand that all or part of the steps of implementing the above method embodiment can be completed by hardware related to program instructions, and the aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps of the above method embodiment; and the aforementioned storage medium includes: mobile storage devices, read-only memories (ROM), magnetic disks or optical disks, etc., various media that can store program codes.
[0160] Alternatively, if the above-mentioned integrated unit of the present invention is implemented in the form of a software function module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiment of the present invention can be essentially or partly reflected in the form of a software product that contributes to the relevant technology. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as mobile storage devices, ROMs, magnetic disks, or optical disks.
[0161] The above is only an embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A target detection method, characterized in that: include: Get the current image to be detected; Get a training image set; The training image set includes a plurality of data groups, and one data group includes a plurality of samples for training; If the one data group does not include positive samples, extracting a first predetermined number of first negative samples from the trained sample set; If the one data group includes the positive sample, extracting a second positive sample and a second negative sample from the one data group according to a first predetermined ratio; Inputting the first negative sample into an initial detection model to obtain a first predicted background class result; Inputting the second positive sample and the second negative sample into the initial detection model to obtain a target result corresponding to the second positive sample and a second predicted background class result corresponding to the second negative sample; In the back propagation stage, the initial detection model is trained based on the first predicted background class result and the true result corresponding to the first negative sample until the target detection model is obtained; Using the target detection model to perform target detection on the current image to be detected, and predicting the current detection result; The target detection model is obtained after background class prediction training is performed on a data group that is all negative samples.
2. The target detection method according to claim 1, characterized in that: After acquiring the training image set, the method further includes: Inputting the training image set into an image recognition model to obtain a first image recognition result; When the first image recognition result corresponding to the one data group has an image whose degree of fit with the preset standard result is greater than a fit threshold, determining that the one data group contains a positive sample; When the first image recognition result corresponding to the one data group does not contain an image whose degree of fit with the preset standard result is greater than the fit threshold, it is determined that the one data group does not include the positive sample.
3. The target detection method according to claim 1, characterized in that: If the one data group does not include a positive sample, extracting a first predetermined number of first negative samples from a trained sample set comprises: If the one data group does not include the positive sample, then, from the second negative samples of the sample set that has been trained, according to the negative sample losses corresponding to the second negative samples, extracting a first predetermined number of the first negative samples in descending order of the negative sample losses; The first predetermined number is an integer multiple of the number of samples in the one data group.
4. The target detection method according to claim 1, characterized in that: When the training image set includes: a data group with positive samples and a data group without positive samples, the back propagation stage, based on the first predicted background class result and the real result corresponding to the first negative sample, trains the initial detection model until the target detection model is obtained, including: In the back propagation stage, the negative sample loss is determined according to the first preset loss function, the first predicted background class result and the first true result corresponding to the first negative sample; Determine the positive sample loss according to a second preset loss function, the target result and the second predicted background class result, a target true result corresponding to the target result, and a second true result corresponding to the second negative sample; Based on the positive sample loss and the negative sample loss, the initial detection model is trained until a target detection model is obtained.
5. The target detection method according to claim 4, characterized in that: The training of the initial detection model based on the negative sample loss and the positive sample loss until a target detection model is obtained includes: Determine a current loss according to the negative sample loss and the positive sample loss; If the current loss is greater than the preset loss threshold, the next training image set is obtained, and the initial detection model is continuously trained until the next loss is no greater than the preset loss threshold, thereby obtaining the target detection model.
6. The target detection method according to claim 5, characterized in that: The determining the current loss according to the negative sample loss and the positive sample loss includes: The positive sample loss and the negative sample loss are weighted to determine the current loss; wherein a first weight corresponding to the positive sample loss is greater than a second weight corresponding to the negative sample loss.
7. The target detection method according to claim 6, characterized in that: The weighting the positive sample loss and the negative sample loss to determine the current loss includes: The positive sample loss is multiplied by the first weight, and the result is added to the product of the negative sample loss and the second weight to obtain the current loss.
8. A target detection device, characterized in that: include: An image acquisition unit, used to acquire the current image to be detected; A detection unit, used to perform target detection on the current image to be detected using a target detection model, and predict a current detection result; The target detection model is obtained after background class prediction training is performed on a data group that is all negative samples; The target detection device, before using the target detection model to perform target detection on the current image to be detected and predicting the current detection result, obtains a training image set; the training image set includes multiple data groups, and one data group includes multiple samples for training; If the one data group does not include positive samples, extracting a first predetermined number of first negative samples from the trained sample set; If the one data group includes the positive sample, extracting a second positive sample and a second negative sample from the one data group according to a first predetermined ratio; Inputting the first negative sample into an initial detection model to obtain a first predicted background class result; Inputting the second positive sample and the second negative sample into the initial detection model to obtain a target result corresponding to the second positive sample and a second predicted background class result corresponding to the second negative sample; In the back propagation stage, the initial detection model is trained based on the first predicted background class result and the true result corresponding to the first negative sample until the target detection model is obtained.
9. A target detection device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the program, the steps in the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps in the method according to any one of claims 1 to 7 are implemented.
