Target detection method, system, electronic device and storage medium
By constructing a target detection model of multiple convolutional neural network branches and fusing features, and adjusting the loss function based on the aspect ratio of the target, the problem of insufficient detection accuracy in the existing technology is solved, and effective extraction and accuracy of targets of different scales are achieved. detection.
Patent Information
- Application Number
- CN202111227765.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-21
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-10-21
AI Technical Summary
Existing target detection algorithms are difficult to effectively extract features of targets of different scales in complex detection scenarios, resulting in insufficient detection accuracy.
Construct a target detection model with multiple convolutional neural network branches. The convolution kernel size of each branch is different. By inputting training images to each branch and fusing the features, the loss function is determined according to the actual aspect ratio of the target, and the model parameters are adjusted to Improve detection accuracy.
Effectively extract features of targets of different scales and improve the accuracy and robustness of target detection, especially in complex scenes with large differences in target scales.
Smart Images

Figure CN113947154B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a target detection method, system, electronic device and storage medium. Background Art
[0002] With the rapid development of object detection in deep learning computer vision, object detection technology plays an extremely important role and has application value in many fields. However, as the detection scenes become more and more complex, the shapes and scales of the samples to be detected vary. Objects of different scales need to obtain features of different levels in a targeted manner to complete detection tasks of different difficulty levels.
[0003] In the existing technology, it is usually based on image-level scale fusion and detection optimization on large and small objects. For example, Pyramid Scense Parsing Network and Feature Pyramid Network use parallel fusion of multiple different receptive fields to meet the characteristics of objects of different scales. However, when the detection scene is more complex and the target scales vary greatly, the existing detection algorithms cannot meet the requirements of high-precision detection.
[0004] Therefore, how to effectively extract features of targets of different scales and improve the accuracy of target detection is a technical problem that technicians in this field currently need to solve. Summary of the invention
[0005] The purpose of this application is to provide a target detection method, system, electronic device and storage medium, which can effectively extract features of targets of different scales and improve the accuracy of target detection.
[0006] In order to solve the above technical problems, the present application provides a target detection method, which includes:
[0007] Constructing a target detection model including multiple convolutional neural network branches; wherein the convolution kernel sizes of any two of the convolutional neural network branches are different;
[0008] Inputting the training images into each of the convolutional neural network branches respectively, and fusing the features extracted by the convolution kernels of all the convolutional neural network branches to obtain fused features;
[0009] Determine a loss function according to the actual aspect ratio of the target in the training image, and use the loss function to calculate the fusion feature to obtain a loss function calculation result;
[0010] The loss function calculation result is used to adjust the parameters of the target detection model, and the target detection operation is performed using the target detection model with adjusted parameters.
[0011] Optionally, the constructing of the target detection model including multiple convolutional neural network branches includes:
[0012] Determining the number of convolutional neural network branches in the target detection model;
[0013] Clustering the objects contained in all the training images in the data set according to the actual aspect ratio to obtain a plurality of data set cluster sets; wherein the number of the data set cluster sets is the same as the number of the convolutional neural network branches;
[0014] Determining the convolution kernel size of each of the convolutional neural network branches according to the set aspect ratio of each of the data set cluster sets; wherein the set aspect ratio is an output value of the clustering algorithm for the data set cluster set;
[0015] Constructing the target detection model including all the convolutional neural network branches. Optionally, the training images are input into each of the convolutional neural network branches respectively, and the features extracted by the convolution kernels of all the convolutional neural network branches are fused to obtain the fused features including:
[0016] Dividing the training pictures in the data set into a plurality of picture groups;
[0017] Selecting a current picture group, and inputting the training pictures in the current picture group into each of the convolutional neural network branches respectively;
[0018] The features extracted by the convolution kernels of all the convolutional neural network branches are fused to obtain fused features corresponding to the current picture group.
[0019] Optionally, a loss function is determined according to an actual aspect ratio of the target in the training image, and the fusion feature is calculated using the loss function to obtain a loss function calculation result;
[0020] Clustering all the objects in the current picture group according to actual aspect ratios to obtain multiple picture group cluster sets;
[0021] Setting the picture group cluster set containing the largest number of targets as the target picture group cluster set;
[0022] Setting a data set cluster set including the target picture group cluster set as a target data set cluster set, and determining a penalty factor corresponding to the current picture group according to the number of targets in the target data set cluster set; wherein the number of targets is negatively correlated with the value of the penalty factor;
[0023] Constructing a loss function of the current picture group using the penalty factor; wherein a calculation result of the loss function is related to the predicted width and height and the actual width and height;
[0024] The loss function is used to calculate the fusion features corresponding to the current picture group to obtain the loss function calculation result.
[0025] Optionally, determining the convolution kernel size of each convolutional neural network branch according to the set aspect ratio of each of the data set cluster sets includes:
[0026] Determine whether all the data set cluster sets meet preset conditions; wherein the preset constraint conditions are: the data set cluster sets include a first data set cluster set, a second data set cluster set and a third data set cluster set; the difference between the set aspect ratio of the first data set cluster set and 1 is greater than a first preset value, the difference between the set aspect ratio of the third data set cluster set and 1 is less than a second preset value, and the difference between the set aspect ratio of the second data set cluster set and 1 is less than or equal to the first preset value and greater than or equal to the second preset value;
[0027] If so, determine the maximum convolution kernel width and the maximum convolution kernel height;
[0028] Determining a convolution kernel size of a first convolution neural network branch according to the set aspect ratio of the first data set cluster set; wherein the convolution kernel width of the first convolution neural network branch is the maximum convolution kernel width, and the convolution kernel height of the first convolution neural network branch is obtained by rounding the ratio of the maximum convolution kernel height to the set aspect ratio of the first data set cluster set;
[0029] Setting the convolution kernel size of the second convolutional neural network branch to the maximum convolution kernel width and the maximum convolution kernel height;
[0030] Determining a convolution kernel size of a third convolution neural network branch according to the set aspect ratio of the third data set clustering set; wherein the convolution kernel width of the third convolution neural network branch is obtained by rounding the ratio of the maximum convolution kernel width to the set aspect ratio of the third data set clustering set, and the convolution kernel height of the third convolution neural network branch is the maximum convolution kernel height;
[0031] Accordingly, constructing the target detection model including all the convolutional neural network branches includes:
[0032] Construct the target detection model including the first convolutional neural network branch, the second convolutional neural network branch and the third convolutional neural network branch.
[0033] Optionally, before inputting the training images into each of the convolutional neural network branches respectively, the method further includes:
[0034] Extract the current image group from the dataset;
[0035] Calculate the average number of targets and the median number of targets in the current picture group; wherein the average number of targets is the average number of targets included in the current picture group, and the median number of targets is the median number of targets included in the current picture group;
[0036] Determining a discrete degree of the number of the targets contained in the current picture group according to a ratio of the target number average value to the target number median value;
[0037] Determining whether the discreteness meets a preset standard;
[0038] If yes, setting the picture in the current picture group as the training picture;
[0039] If not, a new current picture group is re-extracted from the data set.
[0040] Optionally, before inputting the training images into each of the convolutional neural network branches respectively, the method further includes:
[0041] Acquire a current picture group, and remove duplicate images in the current picture group; wherein the duplicate images are images whose similarity with other images is greater than a third preset value;
[0042] New pictures are added to the current picture group according to the number of deleted duplicate images, and the pictures in the current picture group are set as the training pictures.
[0043] The present application also provides a target detection system, which includes:
[0044] A model building module, used to build a target detection model including multiple convolutional neural network branches; wherein the convolution kernel sizes of any two of the convolutional neural network branches are different;
[0045] A feature fusion module, used to input the training image into each of the convolutional neural network branches respectively, and fuse the features extracted by the convolution kernels of all the convolutional neural network branches to obtain fused features;
[0046] A loss calculation module, used to determine a loss function according to the actual aspect ratio of the target in the training image, and use the loss function to calculate the fusion feature to obtain a loss function calculation result;
[0047] The target detection module is used to adjust the parameters of the target detection model using the calculation result of the loss function, and perform the target detection operation using the target detection model with adjusted parameters.
[0048] The present application also provides a storage medium on which a computer program is stored, and when the computer program is executed, the steps of the target detection method described above are implemented.
[0049] The present application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the target detection method when calling the computer program in the memory.
[0050] The present application provides a target detection method, including: constructing a target detection model including multiple convolutional neural network branches; wherein the convolution kernel sizes of any two of the convolutional neural network branches are different; inputting a training image into each of the convolutional neural network branches respectively, and fusing the features extracted by the convolution kernels of all the convolutional neural network branches to obtain a fused feature; determining a loss function according to the actual aspect ratio of the target in the training image, and calculating the fused feature using the loss function to obtain a loss function calculation result; adjusting the parameters of the target detection model using the loss function calculation result, and performing a target detection operation using the target detection model after adjusting the parameters.
[0051] The present application constructs a target detection model including multiple convolutional neural network branches, and the convolution kernel sizes of the above-mentioned convolutional neural network branch models are different. After the training picture is input into each convolutional neural network branch, each convolutional neural network branch can extract features of multiple targets in the picture, and fuse the different size features extracted by each convolutional neural network branch to obtain fused features. The present application determines a loss function that is strongly related to the target scale according to the actual aspect ratio of the target in the training picture, and then uses the loss function calculation result to adjust the parameters of the target detection model, and uses the target detection model after adjusting the parameters to perform the target detection operation. Compared with the target detection scheme based on the image scale in the related art, the present application trains the target detection model based on the aspect ratio of the target, which can effectively extract the features of targets of different scales and improve the accuracy of target detection. The present application also provides a target detection system, an electronic device and a storage medium, which have the above-mentioned beneficial effects and are not repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the embodiments of the present application, the following is a brief introduction to the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0053] Figure 1 A flow chart of a target detection method provided in an embodiment of the present application;
[0054] Figure 2 A schematic diagram of a generation process of a fusion feature provided in an embodiment of the present application;
[0055] Figure 3 A flowchart of a method for optimizing target detection based on multi-scale objects provided in an embodiment of the present application;
[0056] Figure 4 A schematic diagram of the structure of a target detection system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0057] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0058] See below Figure 1 , Figure 1 A flowchart of a target detection method provided in an embodiment of the present application.
[0059] Specific steps may include:
[0060] S101: Build an object detection model including multiple convolutional neural network branches;
[0061] Among them, the target detection model constructed in this embodiment may include more than two convolutional neural network branches. The convolution kernel size of each convolutional neural network branch is different, and different convolutional neural network branches have different sensitivities to targets with different aspect ratios when extracting features. As a feasible implementation, the target detection model may include three convolutional neural network branches, and the three convolutional neural network branches include three branches that are sensitive to targets with aspect ratios greater than 1, targets with aspect ratios equal to 1, and targets with aspect ratios less than 1. If the target detection model includes five convolutional neural network branches, the five convolutional neural network branches include five branches that are sensitive to targets with aspect ratios greater than 2, targets with aspect ratios greater than 1 and less than or equal to 2, targets with aspect ratios equal to 1, targets with aspect ratios less than 1 and greater than or equal to 0.5, and targets with aspect ratios less than 0.5. It can be understood that the more branches of the target detection model, the better the detection effect of the target detection model, but the increase in branches will affect the network time consumption to a certain extent, and the number of convolutional neural network branches can be determined according to demand. In the process of feature extraction using the target detection model, the input training image can be copied into multiple copies according to the number of convolutional neural network branches, and the same training image can be input into each convolutional neural network branch for feature extraction. Since the convolution kernel size of each branch is different, each convolutional neural network branch has different sensitivity to targets with different aspect ratios. After feature extraction, the features extracted from the same training image by each convolutional neural network branch can be fused to obtain fused features.
[0062] In this embodiment, the convolution kernel sizes of any two of the convolutional neural network branches are different so as to fully extract the features of targets with different aspect ratios.
[0063] S102: inputting the training images into each of the convolutional neural network branches respectively, and fusing the features extracted by the convolution kernels of all the convolutional neural network branches to obtain fused features;
[0064] The training picture may include multiple pictures, and there may be any number of targets in the training picture. The above targets are objects to be detected by target detection, for example, the targets may be vehicles, pedestrians, traffic lights, etc. The above training pictures may be pictures in the data set.
[0065] In this embodiment, each training image can be copied into multiple copies, and the same training image is input to each convolutional neural network branch, so that convolutional neural network branches with different convolutional kernel sizes can extract target features from the same training image. The present application fuses the features extracted by the convolution kernel of each convolutional neural network branch to obtain fused features.
[0066] S103: determining a loss function according to the actual aspect ratio of the target in the training image, and calculating the fusion feature using the loss function to obtain a loss function calculation result;
[0067] Among them, this embodiment can pre-mark the actual aspect ratio of the target in the training picture, and then set the loss function according to the actual aspect ratio of the target, so that the loss function is strongly related to the target scale. After obtaining the loss function, this embodiment can use the loss function to calculate the fusion features obtained by all convolutional neural network branches to obtain the loss function calculation result.
[0068] S104: adjusting the parameters of the target detection model using the calculation result of the loss function, and performing a target detection operation using the target detection model with adjusted parameters.
[0069] Among them, based on the loss function calculation result, this embodiment can use the loss function calculation result to iteratively adjust the parameters of the target detection model until the loss function calculation result meets the model iteration stop condition, and obtain the trained target detection model. After receiving the unknown picture, this embodiment can use the target detection model with adjusted parameters to extract the features of the location picture and determine whether the target exists in the location picture.
[0070] The present embodiment constructs a target detection model including multiple convolutional neural network branches, and the convolution kernel sizes of the above-mentioned convolutional neural network branch models are different. After the training picture is input into each convolutional neural network branch, each convolutional neural network branch can extract features of multiple targets in the picture, and fuse the different size features extracted by each convolutional neural network branch to obtain fused features. The present embodiment determines a loss function that is strongly correlated with the target scale according to the actual aspect ratio of the target in the training picture, and then uses the loss function calculation result to adjust the parameters of the target detection model, and uses the target detection model after adjusting the parameters to perform target detection operations. Compared with the target detection scheme based on the picture scale in the related art, the present embodiment trains the target detection model based on the aspect ratio of the target, which can effectively extract the features of targets of different scales and improve the accuracy of target detection.
[0071] As for Figure 1Further introduction to the corresponding embodiment, this embodiment can construct a target detection model including multiple convolutional neural network branches in the following manner: determine the number of convolutional neural network branches in the target detection model; cluster the targets contained in all the training images in the data set according to the actual aspect ratio to obtain multiple data set clustering sets; wherein the number of the data set clustering sets is the same as the number of the convolutional neural network branches; determine the convolution kernel size of each convolutional neural network branch according to the collection aspect ratio of each data set clustering set; wherein the collection aspect ratio is the output value of the clustering algorithm for the data set clustering set; construct the target detection model including all the convolutional neural network branches. The number of the above-mentioned convolutional neural network branches can be set by the staff according to actual needs. This embodiment can use the k-means algorithm to cluster the targets contained in all the training images in the data set according to the actual aspect ratio, and the clustering result obtained is the data set clustering set. The output value of the k-means algorithm for the data set clustering set is the collection aspect ratio, and the collection aspect ratio is used to describe the aspect ratio of most of the targets in the set.
[0072] In the above method, the number of data set cluster sets is determined by the number of convolutional neural network branches. Specifically, the convolution kernel size of the convolutional neural network branch can be determined by the set aspect ratio of the data set cluster set. The following takes a target detection model including three convolutional neural network branches as an example to illustrate its construction method. After obtaining multiple cluster sets, it is determined whether all the data set cluster sets meet the preset conditions; wherein the preset constraint conditions are: the data set cluster set includes a first data set cluster set, a second data set cluster set and a third data set cluster set; the difference between the set aspect ratio of the first data set cluster set and 1 is greater than a first preset value, the difference between the set aspect ratio of the third data set cluster set and 1 is less than a second preset value, and the difference between the set aspect ratio of the second data set cluster set and 1 is less than or equal to the first preset value and greater than or equal to the second preset value;
[0073] In the above manner, the first data set clustering set is a set whose set aspect ratio is obviously greater than 1, the second data set clustering set is a set whose set aspect ratio is approximately equal to 1, and the third data set clustering set is a set whose set aspect ratio is obviously less than 1. The first preset value and the second preset value can be set according to actual needs, for example, the first preset value and the second preset value can both be 0.1.
[0074] The process of calculating the convolution kernel size is as follows:
[0075] Step 1: Determine the maximum convolution kernel width and maximum convolution kernel height;
[0076] Step 2: determining the convolution kernel size of the first convolutional neural network branch according to the set aspect ratio of the first data set clustering set;
[0077] The convolution kernel width of the first convolution neural network branch is the maximum convolution kernel width, and the convolution kernel height of the first convolution neural network branch is obtained by rounding the ratio of the maximum convolution kernel height to the set aspect ratio of the first data set clustering set;
[0078] Step 3: setting the convolution kernel size of the second convolutional neural network branch to the maximum convolution kernel width and the maximum convolution kernel height;
[0079] Step 4: determining the convolution kernel size of the third convolutional neural network branch according to the set aspect ratio of the third data set clustering set;
[0080] The convolution kernel width of the third convolution neural network branch is obtained by rounding the ratio of the maximum convolution kernel width to the set aspect ratio of the third data set clustering set, and the convolution kernel height of the third convolution neural network branch is the maximum convolution kernel height;
[0081] Step 5: Construct the target detection model including the first convolutional neural network branch, the second convolutional neural network branch and the third convolutional neural network branch.
[0082] The process of clustering targets and determining the convolution kernel size of the convolutional neural network branch is described below through an example in a practical application:
[0083] All objects in the training image are clustered into three categories according to their aspect ratios using the k-means algorithm, and the aspect ratios are recorded. The convolution kernel sizes of the three branches of the neural network are determined based on the aspect ratios. For performance reasons, the maximum width and height of the convolution kernel is no more than 5. The specific calculation method is as follows:
[0084] For a dataset cluster set with a collection aspect ratio greater than 1, the size of the convolution kernel constructed based on the dataset cluster set is: convolution kernel width = 5, convolution kernel height = (rounded) 5 / collection aspect ratio. For a dataset cluster set with a collection aspect ratio approximately equal to 1, the size of the convolution kernel constructed based on the dataset cluster set is: convolution kernel width = 5, convolution kernel height = 5. For a dataset cluster set with a collection aspect ratio less than 1, the size of the convolution kernel constructed based on the dataset cluster set is: convolution kernel width = (rounded) 5 / collection aspect ratio, convolution kernel height = 5. The above collection aspect ratio is obtained by clustering the target width and height, also known as multi-scale ratio, and its calculation method = clustered width / height.
[0085] See also Figure 2 , Figure 2A schematic diagram of a fusion feature generation process provided in an embodiment of the present application, wherein a convolutional neural network branch is designed according to a determined convolution kernel size, and the input data is copied three times and input into three convolutional neural network branches with convolution kernels of different scales to extract features, and finally the features extracted by the convolution kernels of different scales are fused. Specifically, the convolutional neural network branch includes a first convolutional neural network branch, a second convolutional neural network branch, and a third convolutional neural network branch, and then the multi-scale convolution kernels of each convolutional neural network branch are used to extract features. Through the feature extraction and feature fusion method of this embodiment, the feature extraction capability of the target detection model can be improved, thereby realizing multi-scale feature extraction of the target.
[0086] As for Figure 1 For further introduction of the corresponding embodiment, all training images can be input into the target detection model in batches, and the specific process is as follows: the training images in the data set are divided into multiple image groups; the current image group is selected, and the training images in the current image group are respectively input into each of the convolutional neural network branches; the features extracted by the convolution kernels of all the convolutional neural network branches are fused to obtain the fused features corresponding to the current image group. After the above process is completed, a new current image group can be reselected and the step of inputting the training images in the current image group into each of the convolutional neural network branches is executed.
[0087] Furthermore, in this embodiment, the data set can be used as the original image set, and the current image group that needs to be input into the target detection model is extracted from the data set in batches, that is, the current image group is the current batch image set extracted from the original image set. In this embodiment, the loss function can be determined in the following manner, and then the loss function calculation result is determined. The specific process is as follows: clustering all the targets in the current image group according to the actual aspect ratio to obtain multiple image group clustering sets; setting the image group clustering set containing the largest number of targets as the target image group clustering set; setting the data set clustering set containing the target image group clustering set as the target data set clustering set, and determining the penalty factor corresponding to the current image group according to the number of targets in the target data set clustering set; wherein the number of targets is negatively correlated with the value of the penalty factor; using the penalty factor to construct the loss function of the current image group; wherein the loss function calculation result is related to the predicted width and height and the actual width and height; using the loss function to calculate the fusion features corresponding to the current image group, the loss function calculation result is obtained. The above loss function calculation result is related to the adjustment of the penalty factor. In actual calculation, the value of the loss function can be reduced by adjusting the penalty factor.
[0088] Furthermore, in order to avoid gradient explosion caused by excessive loss function in early training, the predicted width and height and the actual width and height in the loss function can be normalized.
[0089] The conventional target detection loss function is composed of the center point coordinates and width and height of the target, which fails to directly reflect the change in target scale. This embodiment adds scale information to the original loss function and adds scale information to the loss function. In addition, the loss function penalty factor α is set according to the number of targets with different aspect ratios in the current batch of training images. The penalty factor obtained in the above manner is determined based on the results of clustering in the previous step, and can be flexibly changed in combination with the data distribution of the current image group, and can adjust the optimization weight to improve the detection accuracy.
[0090] Calculation method of penalty factor α: cluster the target aspect ratio and corresponding number of all training images (i.e., data sets) obtained by clustering, where the penalty factor α corresponding to the largest cluster set is 0.5, the penalty factor α corresponding to the second largest cluster set is 1.5, and the penalty factor α corresponding to the smallest cluster set is 2.0. For example, the number of targets in the cluster set of data sets with a set aspect ratio greater than 1 is the largest, the number of targets in the cluster set of data sets with a set aspect ratio equal to 1 is the second largest, and the number of targets in the cluster set of data sets with a set aspect ratio less than 1 is the smallest. In this embodiment, the current batch of training pictures are clustered according to the actual aspect ratio to obtain multiple picture group cluster sets, and the picture group cluster set containing the largest number of the targets is set as the target picture group cluster set; if the set aspect ratio of the target picture group cluster set is greater than 1, the penalty factor used by the current batch of training pictures is 0.5; if the set aspect ratio of the target picture group cluster set is equal to 1, the penalty factor used by the current batch of training pictures is 1.5; if the set aspect ratio of the target picture group cluster set is less than 1, the penalty factor used by the current batch of training pictures is 2. In the above manner, the value of the penalty factor α can be determined according to which gradient the cluster set corresponding to the fusion feature belongs to.
[0091] The conventional target detection loss function is
[0092] The loss function used in this embodiment is:
[0093] Among them, IOU is the intersection of the predicted and actual target areas, p represents the Euclidean distance, c is the minimum diagonal value between the predicted box and the real box, b is the predicted center point, and b gt is the actual center point, and α is the penalty factor of the loss function. b and H b is the predicted target width and predicted target height, W s and H sis the actual target width and the actual target height. To avoid excessive gradient explosion caused by excessive loss function in the early training, this embodiment can b , H b , W s and H s Specifically, we can normalize and By adding penalty items, the feature learning of relatively weak target categories in multi-scale is strengthened, so that the neural network pays more attention to weak categories in multi-scale during back propagation, thereby improving the overall target detection rate.
[0094] As a feasible implementation mode, this embodiment can perform a robustness improvement operation on a single batch of data before inputting the training pictures into each of the convolutional neural network branches respectively. The specific process is as follows: extracting a current picture group from a data set; calculating an average number of targets and a median number of targets in the current picture group; wherein the average number of targets is the average number of targets contained in the current picture group, and the median number of targets is the median number of targets contained in the current picture group; determining the degree of discreteness of the number of targets contained in the current picture group according to the ratio of the average number of targets to the median number of targets; judging whether the degree of discreteness meets a preset standard; if so, setting the pictures in the current picture group as the training pictures; if not, re-extracting a new current picture group from the data set.
[0095] Furthermore, before inputting the training images into each of the convolutional neural network branches, the current image group can be obtained, and repeated images in the current image group can be removed; wherein the repeated images are images whose similarity to other images is greater than a third preset value; new images are added to the current image group according to the number of deleted repeated images, and the images in the current image group are set as the training images. In this embodiment, the data set can be extracted in batches to obtain image groups, and the current image group can be a collection of images extracted in the current batch.
[0096] The dataset containing the training images is generally obtained by extracting frames from a video, or is composed of multiple similar scenes. However, the above-mentioned method of constructing the dataset (such as the interval between adjacent frames is too short when extracting frames from a video) often results in the presence of highly similar training images in the dataset. The above-mentioned image deduplication operation scheme can improve the effectiveness and robustness of the samples. The above-mentioned process can achieve data enhancement. Currently, common data enhancements include data truncation and splicing of images in the same batch. In ordinary training methods, the training data in a batch is generally randomly extracted from the entire data set to train a batch. If there are many repeated data, it is not conducive to data enhancement. At the same time, it may cause problems such as instability in training. Two solutions are proposed to solve the current problem: (1) Count the number of targets in the batch, and re-extract if the number of targets is small; (2) In order to avoid a large number of highly similar images in the same batch, we take half of the input batch data as the basic data and the other half as the comparison data.
[0097] Specific implementation methods for problem (1):
[0098] Step A1: Count the number of targets in the entire data set, defined as T. Calculate the average value, defined as A.
[0099] Step A2: After counting the number of targets in each image in the statistical data set, take the median and locate it as M.
[0100] Step A3: Analyze and judge the degree of dispersion of the data set by the values of A and M to obtain the qualified line of the batch target number. When the ratio of A to M exceeds 1.2, use the median as the judgment standard. Otherwise, use the average as the judgment standard. The value obtained in step A3 is used as the standard to determine whether the current batch needs partial resampling.
[0101] Specific implementation method for problem (2). In this embodiment, the similarity metric can be calculated using the following formula: Similarity = (2|X1∩X2|) / (|X1|+|X2|); where |X1∩X2| is the point multiplication of two normalized sample points and then the pixel addition, and |X1||X2| is the pixel addition of the two normalized samples. When the similarity is greater than the threshold, the comparison data is removed and a new image is introduced.
[0102] In the related art, images are usually divided into pixel scale, superpixel scale, and image scale based on image resolution to extract target features, but this method does not take into account the scale of targets in the image. Large images do not necessarily correspond to large targets. When there are targets of the same size but different length and width scales in the image, the above conventional scheme is difficult to achieve high-precision target detection. In the related art, the receptive field of the dilated convolution and the fusion of features at different levels are also usually used to optimize the detection difficulty between targets of different resolutions or sizes, but the problem of detecting targets of the same size but different length and width scales is not solved. The above conventional method only uses dilated convolution to improve the receptive field and increase the feature perception domain, which may not have a positive benefit for small targets, and the accuracy of target detection is low.
[0103] The process described in the above embodiment is explained below through an embodiment in practical application. This embodiment improves a method for optimizing target detection based on multi-scale objects in an image. The method of this embodiment can optimize the learning of target sizes and different aspect ratios and diverse data sets in the scene. Compared with the algorithm for processing the scale of an image, the method used in this embodiment pays more attention to the scale of the target itself in the image, and realizes a multi-scale detection optimization algorithm for the target. With respect to the shortcomings of the existing technical solutions, this embodiment provides a deep learning method that can optimize the detection method of multi-scale targets. By designing a complete set of processes including training data clustering algorithm, data robustness enhancement in the same batch, designing different convolution kernel scales according to different images, and establishing a strong connection between the regression loss function and the target scale, the algorithm goal of optimizing multi-scale target detection is finally achieved.
[0104] See also Figure 3 , Figure 3A flowchart of a target detection optimization method based on multi-scale objects provided by an embodiment of the present application. In this embodiment, the original data set to be trained is used with a clustering algorithm to obtain three groups of scale ratio classifications of different scales, and this is used as the basis for subsequent convolution kernel size setting and loss function penalty factor parameters. The training data is input into the neural network in batches, and half of the batch data is used as a benchmark ratio to compare the other half of the batch data. Similar data is removed and new training data is supplemented by numerical comparison, and finally the completely processed data is repackaged into a new batch and input into the neural network. In this embodiment, it is calculated whether the number of targets in the current batch meets the requirements, and resampled if it does not meet the requirements. Three convolutional neural network branches with different convolution kernel sizes can extract features of multiple targets in the picture, fuse the different size features extracted by the three convolutional neural network branches, and send the fused target features to the target detection loss function calculation. The target detection function is a target detection loss function optimized by the present invention and strongly associated with the target scale information. The target detection loss function is used to enhance the balance of the entire training process. This embodiment proposes a solution to the problem of target detection based on multi-scale objects. In order to ensure better results, this embodiment uses three parallel networks to carefully extract features of data at different scales to solve the problem of object scale differences in the image.
[0105] This embodiment obtains the convolution kernel size used by the neural network by clustering the detection boxes in the data set, and designs multiple network branches according to different convolution kernels to perform feature extraction respectively; this embodiment obtains the convolution kernel scale by clustering the target detection box of the data set, which more appropriately solves the multi-scale problem of objects and ensures that the neural network can fully learn the target features of different scales. This embodiment removes duplicate data and filters low-quality data sets for each batch of training data to ensure that each batch of training neural networks can be trained to the best robustness. This embodiment uses the target detection loss function optimization based on the multi-scale of objects, and cooperates with the neural network structure to learn the target features of different scales to the greatest extent. By modifying the results of the neural network and strengthening the regression box loss function, the scale information is introduced to optimize the loss function, which greatly improves the learning effect of targets of different scales and achieves the purpose of optimizing multi-scale target detection.
[0106] This embodiment can be improved based on Yolo detection and optimized on the data set of motor vehicles, pedestrians, and non-motor vehicles in traffic scenes. The aspect ratio scales of pedestrians, non-motor vehicles and motor vehicles are quite different. The average accuracy comparison table before and after optimization is as follows:
[0107] Table 1 Comparison of average accuracy before and after optimization
[0108] pedestrian car Motorcycle Conventional methods 44.15% 92.67% 89.01% The method of this embodiment 52.60% 95.51% 93.73%
[0109] It can be seen from Table 1 that the average accuracy achieved by the training method of this embodiment is significantly improved compared with the general target detection training method.
[0110] See also Figure 4 , Figure 4 A schematic diagram of the structure of a target detection system provided in an embodiment of the present application, the system may include:
[0111] A model building module 401 is used to build a target detection model including multiple convolutional neural network branches; wherein the convolution kernel sizes of any two of the convolutional neural network branches are different;
[0112] A feature fusion module 402 is used to input the training image into each of the convolutional neural network branches, and fuse the features extracted by the convolution kernels of all the convolutional neural network branches to obtain fused features;
[0113] A loss calculation module 403 is used to determine a loss function according to the actual aspect ratio of the target in the training image, and calculate the fusion feature using the loss function to obtain a loss function calculation result;
[0114] The target detection module 404 is used to adjust the parameters of the target detection model using the calculation result of the loss function, and perform the target detection operation using the target detection model with adjusted parameters.
[0115] The present embodiment constructs a target detection model including multiple convolutional neural network branches, and the convolution kernel sizes of the above-mentioned convolutional neural network branch models are different. After the training picture is input into each convolutional neural network branch, each convolutional neural network branch can extract features of multiple targets in the picture, and fuse the different size features extracted by each convolutional neural network branch to obtain fused features. The present embodiment determines a loss function that is strongly correlated with the target scale according to the actual aspect ratio of the target in the training picture, and then uses the loss function calculation result to adjust the parameters of the target detection model, and uses the target detection model after adjusting the parameters to perform target detection operations. Compared with the target detection scheme based on the image scale in the related art, the present embodiment trains the target detection model based on the aspect ratio of the target, which can effectively extract the features of targets of different scales and improve the accuracy of target detection.
[0116] Furthermore, the model building module 401 includes:
[0117] A branch number determination unit, used to determine the number of branches of the convolutional neural network in the target detection model;
[0118] A clustering unit, used for clustering the objects contained in all the training images in the data set according to the actual aspect ratio to obtain a plurality of data set cluster sets; wherein the number of the data set cluster sets is the same as the number of the convolutional neural network branches;
[0119] A size determination unit, configured to determine the convolution kernel size of each of the convolutional neural network branches according to the set aspect ratio of each of the data set cluster sets; wherein the set aspect ratio is an output value of the clustering algorithm for the data set cluster set;
[0120] A construction unit is used to construct the target detection model including all the convolutional neural network branches.
[0121] Furthermore, the feature fusion module 402 is used to divide the training images in the data set into multiple image groups; it is also used to select the current image group, and input the training images in the current image group into each of the convolutional neural network branches respectively; it is also used to fuse the features extracted by the convolution kernels of all the convolutional neural network branches to obtain the fused features corresponding to the current image group.
[0122] Furthermore, the loss calculation module 403 is used to cluster all the targets in the current picture group according to the actual aspect ratio to obtain multiple picture group cluster sets; it is also used to set the picture group cluster set containing the largest number of targets as the target picture group cluster set; it is also used to set the data set cluster set containing the target picture group cluster set as the target data set cluster set, and determine the penalty factor corresponding to the current picture group according to the number of targets in the target data set cluster set; wherein the number of targets is negatively correlated with the value of the penalty factor; it is also used to construct the loss function of the current picture group using the penalty factor; wherein the loss function calculation result is related to the predicted width and height and the actual width and height; it is also used to calculate the fusion features corresponding to the current picture group using the loss function to obtain the loss function calculation result.
[0123] Furthermore, a size determination unit is used to determine whether all the data set cluster sets meet preset conditions; wherein the preset constraints are: the data set cluster sets include a first data set cluster set, a second data set cluster set and a third data set cluster set; the difference between the set aspect ratio of the first data set cluster set and 1 is greater than a first preset value, the difference between the set aspect ratio of the third data set cluster set and 1 is less than a second preset value, and the difference between the set aspect ratio of the second data set cluster set and 1 is less than or equal to the first preset value and greater than or equal to the second preset value; if so, determine the maximum convolution kernel width and the maximum convolution kernel height; and also determine the convolution kernel size of the first convolutional neural network branch according to the set aspect ratio of the first data set cluster set. ; wherein the convolution kernel width of the first convolution neural network branch is the maximum convolution kernel width, and the convolution kernel height of the first convolution neural network branch is obtained by rounding the ratio of the maximum convolution kernel height to the set aspect ratio of the first data set clustering set; it is also used to set the convolution kernel size of the second convolution neural network branch to the maximum convolution kernel width and the maximum convolution kernel height; it is also used to determine the convolution kernel size of the third convolution neural network branch according to the set aspect ratio of the third data set clustering set; wherein the convolution kernel width of the third convolution neural network branch is obtained by rounding the ratio of the maximum convolution kernel width to the set aspect ratio of the third data set clustering set, and the convolution kernel height of the third convolution neural network branch is the maximum convolution kernel height;
[0124] Correspondingly, the construction unit is used to construct the target detection model including the first convolutional neural network branch, the second convolutional neural network branch and the third convolutional neural network branch.
[0125] Furthermore, it also includes:
[0126] A target quantity detection module is used to extract a current picture group from a data set before inputting training pictures into each of the convolutional neural network branches respectively; it is also used to calculate the average number of targets and the median number of targets in the current picture group; wherein the average number of targets is the average number of targets contained in the current picture group, and the median number of targets is the median number of targets contained in the current picture group; it is also used to determine the degree of discreteness of the number of targets contained in the current picture group according to the ratio of the average number of targets to the median number of targets; it is also used to determine whether the degree of discreteness meets a preset standard; if so, the pictures in the current picture group are set as the training pictures; if not, a new current picture group is re-extracted from the data set.
[0127] Furthermore, it also includes:
[0128] A similarity detection module is used to obtain a current picture group and remove duplicate images in the current picture group before inputting training pictures into each of the convolutional neural network branches respectively; wherein the duplicate images are images whose similarity with other images is greater than a third preset value; and is also used to add new pictures to the current picture group according to the number of deleted duplicate images, and set the pictures in the current picture group as the training pictures.
[0129] Since the embodiments of the system part correspond to the embodiments of the method part, please refer to the description of the embodiments of the method part for the embodiments of the system part, which will not be repeated here.
[0130] The present application also provides a storage medium on which a computer program is stored, and when the computer program is executed, the steps provided in the above embodiment can be implemented. The storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0131] The present application also provides an electronic device, which may include a memory and a processor, wherein a computer program is stored in the memory, and when the processor calls the computer program in the memory, the steps provided in the above embodiment may be implemented. Of course, the electronic device may also include various network interfaces, power supplies and other components.
[0132] The various embodiments in the specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referred to each other. For the system disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part description. It should be pointed out that for ordinary technicians in this technical field, without departing from the principles of this application, several improvements and modifications can be made to the present application, and these improvements and modifications also fall within the scope of protection of the claims of this application.
[0133] It should also be noted that, in this specification, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprises", "comprising" or any other variants 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 statement "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.
Claims
1. A target detection method, characterized in that: include: Constructing a target detection model including multiple convolutional neural network branches; wherein the convolution kernel sizes of any two of the convolutional neural network branches are different; Inputting the training images into each of the convolutional neural network branches respectively, and fusing the features extracted by the convolution kernels of all the convolutional neural network branches to obtain fused features; Determine a loss function according to the actual aspect ratio of the target in the training image, and use the loss function to calculate the fusion feature to obtain a loss function calculation result; Adjusting the parameters of the target detection model using the loss function calculation result, and performing the target detection operation using the target detection model after the parameter adjustment; The target detection model comprising multiple convolutional neural network branches is constructed, including: Determining the number of convolutional neural network branches in the target detection model; Clustering the objects contained in all the training images in the data set according to the actual aspect ratio to obtain a plurality of data set cluster sets; wherein the number of the data set cluster sets is the same as the number of the convolutional neural network branches; Determining the convolution kernel size of each of the convolutional neural network branches according to the set aspect ratio of each of the data set cluster sets; wherein the set aspect ratio is an output value of the clustering algorithm for the data set cluster set; Construct the target detection model including all the convolutional neural network branches.
2. The target detection method according to claim 1, characterized in that: The training images are input into each of the convolutional neural network branches respectively, and the features extracted by the convolution kernels of all the convolutional neural network branches are fused to obtain fused features, including: Dividing the training pictures in the data set into a plurality of picture groups; Selecting a current picture group, and inputting the training pictures in the current picture group into each of the convolutional neural network branches respectively; The features extracted by the convolution kernels of all the convolutional neural network branches are fused to obtain fused features corresponding to the current picture group.
3. The target detection method according to claim 2, characterized in that: Determine a loss function according to the actual aspect ratio of the target in the training image, and use the loss function to calculate the fusion feature to obtain a loss function calculation result; Clustering all the objects in the current picture group according to actual aspect ratios to obtain multiple picture group cluster sets; Setting the picture group cluster set containing the largest number of targets as the target picture group cluster set; Setting a data set cluster set including the target picture group cluster set as a target data set cluster set, and determining a penalty factor corresponding to the current picture group according to the number of targets in the target data set cluster set; wherein the number of targets is negatively correlated with the value of the penalty factor; Constructing a loss function of the current picture group using the penalty factor; wherein a calculation result of the loss function is related to the predicted width and height and the actual width and height; The loss function is used to calculate the fusion features corresponding to the current picture group to obtain the loss function calculation result.
4. The target detection method according to claim 1, characterized in that: Determining the convolution kernel size of each convolutional neural network branch according to the set aspect ratio of each of the data set clustering sets, including: Determine whether all the data set cluster sets meet preset conditions; wherein the preset constraint conditions are: the data set cluster sets include a first data set cluster set, a second data set cluster set and a third data set cluster set; the difference between the set aspect ratio of the first data set cluster set and 1 is greater than a first preset value, the difference between the set aspect ratio of the third data set cluster set and 1 is less than a second preset value, and the difference between the set aspect ratio of the second data set cluster set and 1 is less than or equal to the first preset value and greater than or equal to the second preset value; If so, determine the maximum convolution kernel width and the maximum convolution kernel height; Determining a convolution kernel size of a first convolution neural network branch according to the set aspect ratio of the first data set cluster set; wherein the convolution kernel width of the first convolution neural network branch is the maximum convolution kernel width, and the convolution kernel height of the first convolution neural network branch is obtained by rounding the ratio of the maximum convolution kernel height to the set aspect ratio of the first data set cluster set; Setting the convolution kernel size of the second convolutional neural network branch to the maximum convolution kernel width and the maximum convolution kernel height; Determining a convolution kernel size of a third convolution neural network branch according to the set aspect ratio of the third data set clustering set; wherein the convolution kernel width of the third convolution neural network branch is obtained by rounding the ratio of the maximum convolution kernel width to the set aspect ratio of the third data set clustering set, and the convolution kernel height of the third convolution neural network branch is the maximum convolution kernel height; Accordingly, constructing the target detection model including all the convolutional neural network branches includes: Construct the target detection model including the first convolutional neural network branch, the second convolutional neural network branch and the third convolutional neural network branch.
5. The target detection method according to any one of claims 1 to 4, characterized in that: Before inputting the training images into each of the convolutional neural network branches, the method further includes: Extract the current image group from the dataset; Calculate the average number of targets and the median number of targets in the current picture group; wherein the average number of targets is the average number of targets included in the current picture group, and the median number of targets is the median number of targets included in the current picture group; Determining a discrete degree of the number of the targets contained in the current picture group according to a ratio of the target number average value to the target number median value; Determining whether the discreteness meets a preset standard; If yes, setting the picture in the current picture group as the training picture; If not, a new current picture group is re-extracted from the data set.
6. The target detection method according to any one of claims 1 to 4, characterized in that: Before inputting the training images into each of the convolutional neural network branches, the method further includes: Acquire a current picture group, and remove duplicate images in the current picture group; wherein the duplicate images are images whose similarity with other images is greater than a third preset value; New pictures are added to the current picture group according to the number of deleted duplicate images, and the pictures in the current picture group are set as the training pictures.
7. A target detection system, characterized in that: include: A model building module, used to build a target detection model including multiple convolutional neural network branches; wherein the convolution kernel sizes of any two of the convolutional neural network branches are different; A feature fusion module, used to input the training image into each of the convolutional neural network branches respectively, and fuse the features extracted by the convolution kernels of all the convolutional neural network branches to obtain fused features; A loss calculation module, used to determine a loss function according to the actual aspect ratio of the target in the training image, and use the loss function to calculate the fusion feature to obtain a loss function calculation result; A target detection module, used to adjust the parameters of the target detection model using the loss function calculation result, and perform a target detection operation using the target detection model after the parameter adjustment; Wherein, the model building module includes: A branch number determination unit, used to determine the number of branches of the convolutional neural network in the target detection model; A clustering unit, used for clustering the objects contained in all the training images in the data set according to the actual aspect ratio to obtain a plurality of data set cluster sets; wherein the number of the data set cluster sets is the same as the number of the convolutional neural network branches; A size determination unit, configured to determine the convolution kernel size of each of the convolutional neural network branches according to the set aspect ratio of each of the data set cluster sets; wherein the set aspect ratio is an output value of the clustering algorithm for the data set cluster set; A construction unit is used to construct the target detection model including all the convolutional neural network branches.
8. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the target detection method according to any one of claims 1 to 6 when calling the computer program in the memory.
9. A storage medium, characterized in that: The storage medium stores computer executable instructions, and when the computer executable instructions are loaded and executed by the processor, the steps of the target detection method according to any one of claims 1 to 6 are implemented.
