Model generation method, detection method, device, electronic device, medium and product
By generating a model that can customize targets based on user description information, it solves the problem of limited detection range of traditional target detection methods and achieves flexible identification and detection of any target.
Patent Information
- Application Number
- CN202410579543.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-11
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2044-05-11
AI Technical Summary
Traditional target detection methods can only detect within a predefined category range and cannot detect targets outside the preset category range, resulting in a limited target detection range.
By obtaining sample data, including sample pictures and description information, and using the initial model to perform feature extraction and feature fusion to generate a target model, the target to be detected can be identified based on the description information input by the user, and any target can be detected.
It realizes the detection of any target, avoids the problem of limited detection range, and improves the flexibility and accuracy of target detection.
Smart Images

Figure CN118172546B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a model generation method, a detection method, a device, an electronic device, a medium and a product. Background Art
[0002] Object detection is a core technology in the current computer field. It has extremely high research and application value in video surveillance, autonomous driving, scene understanding, etc. Object detection is to detect whether there are objects in a given image, and to determine the semantic type and location of these objects. However, traditional object detection methods can usually only detect objects within a predefined category range, but cannot detect objects outside the predefined category range, resulting in the problem of limited object detection range. Summary of the invention
[0003] The purpose of the embodiments of the present application is to provide a model generation method, a detection method, an apparatus, an electronic device, a medium and a product, which can solve the problem of limited target detection range of the target detection model in the related art during target detection.
[0004] In a first aspect, an embodiment of the present application provides a model generation method, the method comprising:
[0005] Acquire sample data, wherein the sample data includes a sample picture, first description information, and label information, wherein the first description information is description information of a target to be detected in the sample picture, and the label information is used to indicate a position of the target to be detected in the sample picture;
[0006] Extracting features of the sample image based on the initial model to obtain image features, and extracting features of the first description information based on the initial model to obtain text features;
[0007] Based on the initial model, the image features and the text features are fused to obtain target features;
[0008] Predicting the position of the target to be detected in the sample image using the target feature based on the initial model to obtain a prediction result;
[0009] Parameters of the initial model are optimized based on the prediction result and the label information to obtain a target model.
[0010] In a second aspect, an embodiment of the present application provides a target detection method, the method comprising:
[0011] Acquire data to be detected, wherein the data to be detected includes a picture to be detected and second description information, wherein the second description information is description information of a target to be detected in the picture to be detected;
[0012] Extracting features of the image to be detected based on the target model to obtain image features, and extracting features of the second description information based on the target model to obtain text features;
[0013] Based on the target model, the image feature and the text feature are subjected to feature fusion to obtain a target feature;
[0014] The position of the target to be detected in the image to be detected is predicted based on the target model using the target features to obtain a prediction result.
[0015] In a third aspect, an embodiment of the present application provides a model generation device, the device comprising:
[0016] A first acquisition module, used to acquire sample data, wherein the sample data includes a sample picture, first description information and label information, wherein the first description information is description information of a target to be detected in the sample picture, and the label information is used to indicate a position of the target to be detected in the sample picture;
[0017] A first feature extraction module, configured to extract features of the sample image based on an initial model to obtain image features, and to extract features of the first description information based on the initial model to obtain text features;
[0018] A first feature fusion module, used for fusing the image feature and the text feature based on the initial model to obtain a target feature;
[0019] A first prediction module, configured to predict the position of the target to be detected in the sample image based on the initial model using the target feature to obtain a prediction result;
[0020] An optimization module is used to optimize the parameters of the initial model based on the prediction result and the label information to obtain a target model.
[0021] In a fourth aspect, an embodiment of the present application provides a target detection device, the device comprising:
[0022] A second acquisition module is used to acquire data to be detected, wherein the data to be detected includes a picture to be detected and second description information, wherein the second description information is description information of a target to be detected in the picture to be detected;
[0023] A second feature extraction module is used to extract features of the image to be detected based on the target model to obtain image features, and to extract features of the second description information based on the target model to obtain text features;
[0024] A second feature fusion module is used to perform feature fusion on the image feature and the text feature based on the target model to obtain a target feature;
[0025] The second prediction module is used to predict the position of the target to be detected in the image to be detected based on the target model and using the target feature to obtain a prediction result.
[0026] In a fifth aspect, an embodiment of the present application further provides an electronic device, comprising a processor, a memory, and a program stored in the memory and executable on the processor, wherein when the program is executed by the processor, the steps of the method described in the first aspect or the second aspect are implemented.
[0027] In a sixth aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the method described in the first aspect or the second aspect are implemented.
[0028] In a seventh aspect, an embodiment of the present application further provides a computer program product, comprising computer instructions, which, when executed by a processor, implement the steps of the method described in the first aspect or the second aspect.
[0029] In an embodiment of the present application, the generated target model can identify the target to be detected in the received image according to the description information input by the user. Since the user can customize the description of the target to be detected through the description information, the scope of target detection by the target model will not be limited to the preset category range, which is conducive to the detection of any target. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. 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 labor.
[0031] Figure 1 One of the flow charts of the model generation method provided in the embodiment of the present application;
[0032] Figure 2 The second flowchart of the model generation method provided in the embodiment of the present application;
[0033] Figure 3 A schematic diagram of a target detection method provided in an embodiment of the present application;
[0034] Figure 4 A schematic diagram of the structure of a model generation device provided in an embodiment of the present application;
[0035] Figure 5 A schematic diagram of the structure of a target detection device provided in an embodiment of the present application;
[0036] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The following will be combined with the drawings in the embodiments of the present application to clearly describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all the embodiments. All other embodiments obtained by ordinary technicians in this field based on the embodiments in the present application belong to the scope of protection of this application.
[0038] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.
[0039] The method provided in the embodiment of the present application is described in detail below through specific embodiments and their application scenarios in conjunction with the accompanying drawings.
[0040] like Figure 1 FIG. 1 is a flow chart of a model generation method provided in an embodiment of the present application, wherein the model generation method comprises the following steps:
[0041] Step 101: Acquire sample data, wherein the sample data includes a sample picture, first description information, and label information, wherein the first description information is description information of a target to be detected in the sample picture, and the label information is used to indicate a position of the target to be detected in the sample picture;
[0042] Step 102: extracting features of the sample image based on the initial model to obtain image features, and extracting features of the first description information based on the initial model to obtain text features;
[0043] Step 103: Based on the initial model, the image features and the text features are fused to obtain target features;
[0044] Step 104: predicting the position of the target to be detected in the sample image using the target feature based on the initial model to obtain a prediction result;
[0045] Step 105: Optimize the parameters of the initial model based on the prediction result and the label information to obtain a target model.
[0046] The sample images may be images obtained in various scenarios, for example, monitoring images in monitoring scenarios, or real-time images outside the vehicle taken by a vehicle-mounted camera while the vehicle is driving.
[0047] The above-mentioned first description information may be text description information of the target to be detected that is defined by the user. For example, when the sample image is a picture taken by construction site monitoring, the first description information may be: detect people wearing safety helmets. In this case, the target to be detected is the "person wearing a safety helmet" in the sample image. Alternatively, the first description information may also be: detect people not wearing safety helmets. In this case, the target to be detected is the "person not wearing a safety helmet" in the sample image. For another example, when the sample image is a real-time image outside the vehicle taken by a vehicle-mounted camera while the vehicle is driving, the first description information may be: detect vehicles. In this case, the target to be detected is the vehicle in the sample image.
[0048] The above-mentioned label information may include the position information of the target to be detected described by the first description information in the sample image. For example, when the sample image is a picture taken for construction site monitoring, the first description information is: when detecting a person wearing a safety helmet, the label information may include the position of the person wearing a safety helmet in the sample image. The label information may be in the form of: (x, y, w, h), where x and y are the coordinates of the center point of the target, and w and h are the length and width of the target box corresponding to the target.
[0049] See also Figure 2In some embodiments of the present application, the initial model may include a visual feature extraction (backbone) module, an encoder (encode) module and a decoder (decode) module, wherein the backbone module is used to perform the above steps 102 and 103. The encoder module is used to perform the above step 104. The decode module is used to perform the above step 105.
[0050] The above encoder may be composed of a visual encoder and a text encoder. The visual encoder is used to extract features from the sample image to obtain image features, wherein, in order to take into account the detection of targets of different sizes, the visual encoder may use a ResNet backbone to extract multi-scale features. The text encoder is used to extract features from the first description information to obtain text features, wherein the text encoder uses Bert to extract text features, the text includes words, sentences, etc., and introduces an attention mask to mark the detection subject, and when multiple detection subjects appear in the first description information, the target is distinguished. Specifically, the text encoder can mark the target to be detected in the first description information through the attention mask, that is, the text feature may include the marking information of the target to be detected, so that the subsequent model can detect the position of the target to be detected. For example, when the first description information is "detecting a pen on the table", the first description information includes the following two detection subjects: "table" and "pen". At this time, the detection subject can be marked as "pen" through the attention mask, that is, the above target to be detected is "pen".
[0051] The feature fusion of the image features and the text features may be performed by adopting various feature fusion methods. For example, a cross attention mechanism “cross attention” may be used to fuse the image features and the text features.
[0052] The above prediction result may include the predicted position of the target to be detected in the sample image. In this way, the loss of the initial model can be determined according to the predicted position and the actual position indicated by the label information, and based on the loss of the initial model, the parameters of the initial model are optimized to obtain the target model.
[0053] It can be understood that the above embodiment only takes the training process of the initial model with one sample data as an example to explain the training process of the initial model. In fact, a large number of different sample data can be generated, and each sample data can be used to iteratively train the initial model according to the method in the above embodiment until the model converges to obtain the target model, wherein a test set can be used to determine whether the model converges. For example, when the accuracy of the trained model in target detection of the test data in the test set is higher than the target threshold, the model is determined to converge. The target threshold can be a relatively high value, for example, it can be 95%, 98%, etc.
[0054] In this implementation, the generated target model can identify the target to be detected in the received image based on the description information input by the user. Since the user can customize the description of the target to be detected through the description information, the scope of target detection by the target model will not be limited to the preset category range, which is conducive to the detection of any target.
[0055] Optionally, the image feature includes M first feature vectors of different scales, and the M first feature vectors of different scales are: feature vectors generated based on the feature maps of M different scales corresponding to the sample image, and the M first feature vectors of different scales are generated based on the feature maps of M different scales corresponding to the sample image. Figure 1 One by one, the text feature includes a second feature vector, and M is an integer greater than 1;
[0056] The step of fusing the image features and the text features based on the initial model to obtain target features includes:
[0057] Based on the cross attention mechanism, the second feature vector is respectively fused with each first feature vector to obtain M third feature vectors;
[0058] Feature fusion is performed on the M third feature vectors to obtain the target feature.
[0059] The M first feature vectors of different scales can be the multi-scale features extracted by the visual encoder using the ResNet backbone. Specifically, the sample image can be scaled to different resolutions, and features can be extracted from images of different resolutions to obtain image features of different scales.
[0060] The above-mentioned feature fusion of the second feature vector with each first feature vector based on the cross-attention mechanism to obtain M third feature vectors specifically refers to: the second feature vector is individually fused with each first feature vector to obtain a corresponding third feature vector, and the M third feature vectors correspond one-to-one to the M first feature vectors. For ease of understanding, the following takes the process of feature fusion of the second feature vector with the tth first feature vector as an example to further explain the process of feature fusion of the second feature vector with each first feature vector based on the cross-attention mechanism:
[0061] The tth first eigenvector Projecting onto the query matrix, we get: , wherein the t-th first eigenvector may be any first eigenvector among the M first eigenvectors of different scales;
[0062] The second eigenvector Projecting to the key matrix, we get: At the same time, the second eigenvector Projecting to the value matrix, we get: ,in is the linear projection transformation matrix obtained through learning. The main calculation method of cross attention is as follows:
[0063] .
[0064] The elements in M are defined as the attention weights of the pixel feature vectors, and M is the cross-attention representation of the image features and text features, where d is the projection dimension of the key and query. The main method of feature fusion is to scale the text sequence and the image sequence to the same dimension, and use cross attention to assign weights to each element in the image feature sequence by calculating the correlation of Q, K, and V on image features of different scales. Cross attention is mainly used to capture the correlation between different positions in the text sequence and the visual sequence, establish the dependency relationship between text and visual features, realize feature enhancement, and output multimodal features. In this way, multimodal features of different scales can be obtained, and the multimodal features of different scales are the above-mentioned M third feature vectors.
[0065] In this implementation, in order to allow text information to better guide target detection, feature enhancement is performed on image features of different scales, that is, cross attention is used to perform cross-modal feature fusion on image features of different scales using text features, which is beneficial to improving the effect of feature fusion.
[0066] Optionally, the performing feature fusion on the M third feature vectors to obtain the target feature includes:
[0067] According to a preset order, the M third feature vectors are iteratively fused M-1 times to obtain the target feature, wherein the preset order is the order in which the M third feature vectors are sorted from high to low according to the scale of the corresponding feature graph; the i-th fusion in the M-1 iterative fusion includes:
[0068] Down-sampling the i-th vector to be fused to obtain the i-th sampling vector, wherein, when i is equal to 1, the i-th vector to be fused is the first third eigenvector in the preset order; when i is greater than 1, the i-th vector to be fused is the i-1th fusion vector; the characteristic dimension of the i-th sampling vector is the same as the characteristic dimension of the i+1th third eigenvector in the preset order, and i is a positive integer less than M;
[0069] The i-th sampling vector and the i+1-th third feature vector are subjected to feature fusion to obtain the i-th fused vector, and the target feature is the M-1-th fused vector.
[0070] The scale of the feature map is the size of the feature map, which is the image size after scaling the sample image. For example, see Figure 2 After the vision encoder extracts features from the sample image, three feature maps of different sizes can be obtained. From left to right, the size of the feature map gradually decreases. Figure 2 As an example, the process of fusing the above-mentioned image features and text features is explained. Figure 2 In the example, the value of N is 3. Figure 2 In , the three feature maps from left to right are respectively recorded as: the first feature map, the second feature map and the third feature map, and the scale of the first feature map is higher than the scale of the second feature map, and the scale of the second feature map is higher than the scale of the third feature map. The process of feature fusion of image features and text features is:
[0071] Based on cross attention, the second feature vector obtained by the text encoder performing feature extraction on the first description information is fused with the first feature vector corresponding to the first feature map to obtain the first third feature vector; based on cross attention, the second feature vector is fused with the first feature vector corresponding to the second feature map to obtain the second third feature vector; based on cross attention, the second feature vector is fused with the first feature vector corresponding to the third feature map to obtain the third third feature vector;
[0072] Downsampling the first third eigenvector to obtain a first sampling vector, wherein the feature dimension of the first sampling vector is the same as the feature dimension of the second third eigenvector; then, fusing the first sampling vector with the second third eigenvector, for example, the first sampling vector and the second third eigenvector may be added to obtain a first fused vector;
[0073] Then, the first fused vector is downsampled to obtain a second sampling vector, wherein the feature dimension of the second sampling vector is the same as the feature dimension of the third third feature vector; then, the second sampling vector is fused with the third third feature vector, for example, the second sampling vector and the third third feature vector can be added to obtain a second fused vector; and the second fused vector is used as the above-mentioned target vector.
[0074] In this implementation, after obtaining multimodal features of different scales, feature fusion is performed by downsampling from high dimensions to low dimensions, that is, the attention results of targets of each scale are fused to avoid the mutual contact of shallow feature information. The target detection effect is improved by fusing high and low layer features. The fused target features contain a large amount of local information. Finally, the results of the encoder part are output through a feedforward neural network, thereby improving the effect of feature fusion.
[0075] Optionally, the prediction result includes a predicted position of the target to be detected in the sample image, and the step of optimizing parameters of the initial model based on the prediction result and the label information to obtain the target model includes:
[0076] Determining a first loss based on the predicted position and the label information, and determining a second loss based on an image feature corresponding to the predicted position and the text feature, wherein the image feature corresponding to the predicted position is: a feature obtained by extracting a feature of the predicted position in the sample image;
[0077] Parameters of the initial model are optimized based on the first loss and the second loss to obtain a target model.
[0078] The first loss can be used as the positioning loss of the target, and the second loss can be used as the classification loss. In the process of calculating the second loss, the text feature can be obtained through backnone, and then the similarity between the text feature and the area box feature is calculated to obtain a matching score, wherein the matching score is used to characterize the second loss, and the area box feature is the feature obtained by extracting the feature of the predicted position in the sample image.
[0079] The above-mentioned parameter optimization of the initial model may specifically be to optimize the M, , or Make optimizations.
[0080] In this implementation, the parameters of the initial model are optimized based on the first loss and the second loss, which is helpful to improve the accuracy of the trained target model in identifying the position and category of the target.
[0081] Optionally, predicting the position of the target to be detected in the sample image by using the target feature based on the initial model to obtain a prediction result includes:
[0082] Based on the initial model, the position of the target to be detected in the sample image is predicted using the target features and the target query vector to obtain a prediction result, wherein the number of dimensions of the target query vector is greater than a preset threshold, and the preset threshold is the maximum number of targets to be detected included in the sample image.
[0083] The above target query vectors may be represented as object queries, wherein the object queries may be initialized query vectors, that is, all values in the object queries are 0.
[0084] Specifically, the target features output by the encoder and the object queries can be input into the decoder (transform decoder), and finally the output of the transform decoder is sent to the feedforward neural network to predict the object category and bounding box. The decoder outputs a length of N, and each output contains the category of a possible target and the absolute coordinate information of the center point. If the number of targets in the sample image is less than N, the redundant positions of the object queries are left blank, completely eliminating the post-processing steps of the previous detection algorithm that rely on artificial priors such as nms and anchor generators. Among them, N is the number of dimensions of the object queries.
[0085] In this embodiment, the position of the target to be detected in the sample image is predicted by utilizing the target features and the target query vector based on the initial model to obtain a prediction result. In this way, since there is no need to rely on artificial a priori post-processing steps to obtain the detection result, it is helpful to simplify the target detection process.
[0086] In summary, the method provided in the embodiments of the present application has at least the following beneficial effects:
[0087] Introduce text information into target detection, establish the connection between vision and text, and use image-text to train the model, so that the trained target model can recognize targets of any category based on the text prompt.
[0088] A deeper level of fusion is introduced between image and text features, and multi-scale deep cross-modal fusion is used in the encoding part to enhance the model's ability to obtain cross-modal information and improve the ability to detect objects of various sizes.
[0089] See also Figure 3 , Figure 3 A target detection method provided in an embodiment of the present application comprises the following steps:
[0090] Step 301: Acquire data to be detected, wherein the data to be detected includes a picture to be detected and second description information, wherein the second description information is description information of a target to be detected in the picture to be detected;
[0091] Step 302: extracting features of the image to be detected based on the target model to obtain image features, and extracting features of the second description information based on the target model to obtain text features;
[0092] Step 303: Fusing the image features and the text features based on the target model to obtain target features;
[0093] Step 304: predict the position of the target to be detected in the image to be detected based on the target model and using the target features to obtain a prediction result.
[0094] It can be understood that the target model is a model trained based on the model generation method in the above embodiment.
[0095] The image to be detected may be an image including various types of targets to be detected. The second description information may be text description information of the target to be detected defined by the user, and the image to be detected includes the target to be detected described by the second description information.
[0096] The implementation process of step 302 is similar to step 102 in the above embodiment, and will not be described in detail here to avoid repetition. The implementation process of step 303 is similar to step 103 in the above embodiment, and will not be described in detail here to avoid repetition. The implementation process of step 304 is similar to step 104 in the above embodiment, and will not be described in detail here to avoid repetition.
[0097] This implementation is a target detection method flow corresponding to the above-mentioned model generation method. Its specific implementation process is similar to the above-mentioned embodiment and has the same beneficial effects. To avoid repetition, it will not be described here.
[0098] See also Figure 4 , Figure 4 A schematic diagram of the structure of a model generation device 400 provided in an embodiment of the present application, the device comprising:
[0099] A first acquisition module 401 is used to acquire sample data, wherein the sample data includes a sample picture, first description information and label information, wherein the first description information is description information of a target to be detected in the sample picture, and the label information is used to indicate a position of the target to be detected in the sample picture;
[0100] A first feature extraction module 402 is used to extract features from the sample image based on an initial model to obtain image features, and to extract features from the first description information based on the initial model to obtain text features;
[0101] A first feature fusion module 403 is used to fuse the image feature and the text feature based on the initial model to obtain a target feature;
[0102] A first prediction module 404 is used to predict the position of the target to be detected in the sample image based on the initial model using the target feature to obtain a prediction result;
[0103] The optimization module 405 is used to optimize the parameters of the initial model based on the prediction result and the label information to obtain a target model.
[0104] Optionally, the image feature includes M first feature vectors of different scales, and the M first feature vectors of different scales are: feature vectors generated based on the feature maps of M different scales corresponding to the sample image, and the M first feature vectors of different scales are generated based on the feature maps of M different scales corresponding to the sample image. Figure 1One by one, the text feature includes a second feature vector, and M is an integer greater than 1; the first feature fusion module 403 is specifically used to fuse the second feature vector with each first feature vector based on a cross attention mechanism to obtain M third feature vectors;
[0105] The first feature fusion module 403 is further used to perform feature fusion on the M third feature vectors to obtain the target feature.
[0106] Optionally, the first feature fusion module 403 is specifically used to perform M-1 iterative fusion on the M third feature vectors in a preset order to obtain the target feature, wherein the preset order is an order in which the M third feature vectors are sorted from high to low according to the scale of the corresponding feature map; the i-th fusion in the M-1 iterative fusion includes:
[0107] Down-sampling the i-th vector to be fused to obtain the i-th sampling vector, wherein, when i is equal to 1, the i-th vector to be fused is the first third eigenvector in the preset order; when i is greater than 1, the i-th vector to be fused is the i-1th fusion vector; the characteristic dimension of the i-th sampling vector is the same as the characteristic dimension of the i+1th third eigenvector in the preset order, and i is a positive integer less than M;
[0108] The i-th sampling vector and the i+1-th third feature vector are subjected to feature fusion to obtain the i-th fused vector, and the target feature is the M-1-th fused vector.
[0109] Optionally, the prediction result includes a predicted position of the target to be detected in the sample image, and the optimization module 405 includes:
[0110] A determination submodule, configured to determine a first loss based on the predicted position and the label information, and to determine a second loss based on an image feature corresponding to the predicted position and the text feature, wherein the image feature corresponding to the predicted position is a feature obtained by extracting a feature of the predicted position in the sample image;
[0111] An optimization submodule is used to optimize the parameters of the initial model based on the first loss and the second loss to obtain a target model.
[0112] Optionally, the first prediction module 404 is specifically used to predict the position of the target to be detected in the sample image based on the initial model using the target features and the target query vector to obtain a prediction result, wherein the number of dimensions of the target query vector is greater than a preset threshold, and the preset threshold is the maximum number of targets to be detected included in the sample image.
[0113] It should be noted that the model generation device 400 provided in the embodiment of the present application can achieve the following Figure 1 The entire technical process of the model generation method shown in the embodiment achieves the same technical effect and will not be described again here to avoid repetition.
[0114] See also Figure 5 , Figure 5 A schematic diagram of the structure of a target detection device 500 provided in an embodiment of the present application, the device comprising:
[0115] A second acquisition module 501 is used to acquire data to be detected, wherein the data to be detected includes a picture to be detected and second description information, wherein the second description information is description information of a target to be detected in the picture to be detected;
[0116] A second feature extraction module 502 is used to extract features of the image to be detected based on the target model to obtain image features, and to extract features of the second description information based on the target model to obtain text features;
[0117] A second feature fusion module 503 is used to perform feature fusion on the image feature and the text feature based on the target model to obtain a target feature;
[0118] The second prediction module 504 is used to predict the position of the target to be detected in the image to be detected based on the target model and using the target feature to obtain a prediction result.
[0119] It should be noted that the target detection device 500 provided in the embodiment of the present application can achieve the following Figure 3 The entire technical process of the target detection method shown in the embodiment achieves the same technical effect and will not be described again here to avoid repetition.
[0120] The embodiment of the present application also provides an electronic device, comprising: a processor, a memory, and a program stored in the memory and executable on the processor, wherein the program is executed by the processor to implement the above Figure 1 The model generation method shown, or, to achieve Figure 3 The various processes of the target detection method embodiment shown can achieve the same technical effect, and will not be described again here to avoid repetition.
[0121] For details, see Figure 6 As shown, an embodiment of the present application further provides an electronic device, including a bus 601, a transceiver 602, an antenna 603, a bus interface 604, a processor 605 and a memory 606.
[0122] In this embodiment, the electronic device further includes: a computer program stored in the memory 606 and executable on the processor 605. When the computer program is executed by the processor 605, the following can be achieved: Figure 1 The model generation method shown in the embodiment, or, implementing Figure 3 The various processes of the target detection method shown in the figure can achieve the same technical effect. To avoid repetition, they will not be described here.
[0123] exist Figure 6 In the embodiment, the bus architecture (represented by bus 601) may include any number of interconnected buses and bridges, and bus 601 links various circuits including one or more processors represented by processor 605 and memory represented by memory 606. Bus 601 may also link various other circuits such as peripherals, voltage regulators, and power management circuits, which are well known in the art and are therefore not further described herein. Bus interface 604 provides an interface between bus 601 and transceiver 602. Transceiver 602 may be one element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices on a transmission medium. Data processed by processor 605 is transmitted on a wireless medium via antenna 603, and further, antenna 603 also receives data and transmits the data to processor 605.
[0124] The processor 605 is responsible for managing the bus 601 and general processing, and can also provide various functions, including timing, peripheral interfaces, voltage regulation, power management and other control functions. The memory 606 can be used to store data used by the processor 605 when performing operations.
[0125] Optionally, the processor 605 may be a CPU, an ASIC, an FPGA or a CPLD.
[0126] The present application also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the above Figure 1 or Figure 3 The various processes of the method embodiment shown can achieve the same technical effect, and are not described here in detail to avoid repetition. The computer-readable storage medium is, for example, a ROM, RAM, a magnetic disk or an optical disk.
[0127] The present application also provides a computer program product, including computer instructions, which, when executed by a processor, implement the above Figure 1 or Figure 3 The various processes of the method embodiment shown can achieve the same technical effect, and will not be described again here to avoid repetition.
[0128] 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.
[0129] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal (which can be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0130] The embodiments of the present application are described above in conjunction with the accompanying drawings, but the present application is not limited to the above-mentioned specific implementation methods. The above-mentioned specific implementation methods are merely illustrative and not restrictive. Under the guidance of the present application, ordinary technicians in this field can also make many forms without departing from the purpose of the present application and the scope of protection of the claims, all of which are within the protection of the present application.
Claims
1. A model generation method, characterized in that: The method comprises: Acquire sample data, wherein the sample data includes a sample picture, first description information, and label information, wherein the first description information is description information of a target to be detected in the sample picture, and the label information is used to indicate a position of the target to be detected in the sample picture; Extracting features of the sample image based on the initial model to obtain image features, and extracting features of the first description information based on the initial model to obtain text features; Based on the initial model, the image features and the text features are fused to obtain target features; Predicting the position of the target to be detected in the sample image using the target feature based on the initial model to obtain a prediction result; Optimizing the parameters of the initial model based on the prediction result and the label information to obtain a target model; The prediction result includes a predicted position of the target to be detected in the sample image, and the initial model is optimized based on the prediction result and the label information to obtain a target model, including: Determining a first loss based on the predicted position and the label information, and determining a second loss based on an image feature corresponding to the predicted position and the text feature, wherein the image feature corresponding to the predicted position is: a feature obtained by extracting a feature of the predicted position in the sample image; Optimize the parameters of the initial model based on the first loss and the second loss to obtain a target model; The picture feature includes M first feature vectors of different scales, wherein the M first feature vectors of different scales are feature vectors generated based on feature maps of different scales corresponding to the sample picture, and the M first feature vectors of different scales correspond to the M feature maps of different scales one by one, and the text feature includes a second feature vector, wherein M is an integer greater than 1; The step of fusing the image features and the text features based on the initial model to obtain target features includes: Based on the cross attention mechanism, the second feature vector is respectively fused with each first feature vector to obtain M third feature vectors; According to a preset order, the M third feature vectors are iteratively fused M-1 times to obtain the target feature, wherein the preset order is the order in which the M third feature vectors are sorted from high to low according to the scale of the corresponding feature graph; the i-th fusion in the M-1 iterative fusion includes: Down-sampling the i-th vector to be fused to obtain the i-th sampling vector, wherein, when i is equal to 1, the i-th vector to be fused is the first third eigenvector in the preset order; when i is greater than 1, the i-th vector to be fused is the i-1th fusion vector; the characteristic dimension of the i-th sampling vector is the same as the characteristic dimension of the i+1th third eigenvector in the preset order, and i is a positive integer less than M; The i-th sampling vector and the i+1-th third feature vector are subjected to feature fusion to obtain the i-th fused vector, and the target feature is the M-1-th fused vector.
2. The method according to claim 1, characterized in that The step of predicting the position of the target to be detected in the sample image based on the initial model using the target feature to obtain a prediction result includes: Based on the initial model, the position of the target to be detected in the sample image is predicted using the target features and the target query vector to obtain a prediction result, wherein the number of dimensions of the target query vector is greater than a preset threshold, and the preset threshold is the maximum number of targets to be detected included in the sample image.
3. A target detection method, characterized in that: The method comprises: Acquire data to be detected, wherein the data to be detected includes a picture to be detected and second description information, wherein the second description information is description information of a target to be detected in the picture to be detected; Performing feature extraction on the image to be detected based on the target model to obtain image features, and performing feature extraction on the second description information based on the target model to obtain text features, wherein the target model is a model generated based on the method described in any one of claims 1 to 2; Based on the target model, the image feature and the text feature are fused to obtain a target feature; The position of the target to be detected in the image to be detected is predicted based on the target model using the target features to obtain a prediction result.
4. A model generation device, characterized in that: The device comprises: A first acquisition module, used to acquire sample data, wherein the sample data includes a sample picture, first description information and label information, wherein the first description information is description information of a target to be detected in the sample picture, and the label information is used to indicate a position of the target to be detected in the sample picture; A first feature extraction module, configured to extract features of the sample image based on an initial model to obtain image features, and to extract features of the first description information based on the initial model to obtain text features; A first feature fusion module, used for fusing the image feature and the text feature based on the initial model to obtain a target feature; A first prediction module, configured to predict the position of the target to be detected in the sample image based on the initial model using the target feature to obtain a prediction result; An optimization module, used to optimize the parameters of the initial model based on the prediction result and the label information to obtain a target model; The prediction result includes the predicted position of the target to be detected in the sample image, and the optimization module includes: A determination submodule, configured to determine a first loss based on the predicted position and the label information, and to determine a second loss based on an image feature corresponding to the predicted position and the text feature, wherein the image feature corresponding to the predicted position is a feature obtained by extracting a feature of the predicted position in the sample image; an optimization submodule, configured to optimize parameters of the initial model based on the first loss and the second loss to obtain a target model; The picture feature includes M first feature vectors of different scales, and the M first feature vectors of different scales are: feature vectors generated based on the feature maps of M different scales corresponding to the sample picture, and the M first feature vectors of different scales correspond to the M feature maps of different scales one by one. The text feature includes a second feature vector, and M is an integer greater than 1; the first feature fusion module is specifically used to perform feature fusion on the second feature vector with each first feature vector based on a cross attention mechanism to obtain M third feature vectors; The first feature fusion module is specifically used to perform M-1 iterative fusion on the M third feature vectors in a preset order to obtain the target feature, wherein the preset order is the order in which the M third feature vectors are sorted from high to low according to the scale of the corresponding feature map; the i-th fusion in the M-1 iterative fusion includes: Down-sampling the i-th vector to be fused to obtain the i-th sampling vector, wherein, when i is equal to 1, the i-th vector to be fused is the first third eigenvector in the preset order; when i is greater than 1, the i-th vector to be fused is the i-1th fusion vector; the characteristic dimension of the i-th sampling vector is the same as the characteristic dimension of the i+1th third eigenvector in the preset order, and i is a positive integer less than M; The i-th sampling vector and the i+1-th third feature vector are subjected to feature fusion to obtain the i-th fused vector, and the target feature is the M-1-th fused vector.
5. A target detection device, characterized in that: The device comprises: A second acquisition module is used to acquire data to be detected, wherein the data to be detected includes a picture to be detected and second description information, wherein the second description information is description information of a target to be detected in the picture to be detected; A second feature extraction module, configured to extract features of the image to be detected based on a target model to obtain image features, and to extract features of the second description information based on the target model to obtain text features, wherein the target model is a model generated based on the method described in any one of claims 1 to 2; A second feature fusion module is used to perform feature fusion on the image feature and the text feature based on the target model to obtain a target feature; The second prediction module is used to predict the position of the target to be detected in the image to be detected based on the target model and using the target feature to obtain a prediction result.
6. An electronic device, characterized in that: include: A processor, a memory, and a program stored in the memory and executable on the processor, wherein the program implements the steps of the method according to any one of claims 1 to 3 when executed by the processor.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 3 are implemented.
8. A computer program product, characterized in that The method comprises computer instructions, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 3.
