Image detection method and device, terminal equipment and computer readable storage medium
By constructing a feature dictionary and calculating a weight matrix, the dependence of deep learning image detection methods on training datasets is solved, reducing training costs and improving detection accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-22
- Publication Date
- 2026-03-24
AI Technical Summary
Existing deep learning-based image detection methods rely heavily on training datasets, resulting in high data acquisition difficulty, long processing time, and high network training costs.
By constructing a feature dictionary, a weight matrix is calculated using the sample image feature data extracted by the detection model. The detection score of the image to be detected is calculated based on the weight matrix and the first score of the image type, thereby reducing the dependence on the training dataset of the detection model.
It reduces the training cost of image detection models, improves detection accuracy, reduces dependence on training datasets, and simplifies the data acquisition process.
Smart Images

Figure CN114494745B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of image processing technology, and in particular relates to image detection methods, apparatus, terminal equipment and computer-readable storage media. Background Technology
[0002] With the development of deep learning technology, the application of deep learning-based image detection methods is becoming increasingly widespread. For example, in face detection applications, deep learning networks are used to detect faces in images to identify facial attributes such as gender, age, and facial features.
[0003] In existing technologies, the detection accuracy of deep learning-based image detection methods often depends on the training images used during the training process. If the facial attributes in the training images are unevenly distributed, or if the number of training images is small, the detection accuracy will be significantly reduced. In other words, deep learning networks are highly dependent on the training dataset, which increases the difficulty and time required for data collection and raises the cost of network training. Summary of the Invention
[0004] This application provides an image detection method, apparatus, terminal device, and computer-readable storage medium, which can reduce the dependence of deep learning networks on training datasets and lower the cost of network training.
[0005] In a first aspect, embodiments of this application provide an image detection method, including:
[0006] The image to be detected is input into the trained detection model to obtain the first feature data of the image to be detected.
[0007] Obtain a preset feature dictionary, which includes the second feature data of each of the multiple sample images extracted by the detection model;
[0008] A weight matrix is calculated based on the first feature data and the second feature data in the feature dictionary, wherein the weight matrix includes weights corresponding to the image types to which each of the multiple sample images belongs, and the weights are used to represent the similarity between the first feature data and the second feature data;
[0009] The detection score of the image to be detected is calculated based on the first score corresponding to the image type and the weight matrix;
[0010] The detection result of the image to be detected is determined based on the detection score.
[0011] In this embodiment, a weight matrix is calculated between the first feature data of the image to be detected and the second feature data of each sample image in a preset feature dictionary. The weights in the weight matrix represent the similarity between the first and second feature data. Since only sample images with high similarity to the image to be detected contribute features, the detection score of the image to be detected, calculated based on the first score corresponding to the image type and the weight matrix, can be used to characterize the detection result of the image to be detected. By using the feature data of a limited number of sample images in the feature dictionary to calculate the similarity between features and thus obtain the image detection result, the extensive training of the detection model is avoided, effectively reducing the dependence on the training dataset when training the detection model and lowering the training cost of the detection model.
[0012] In one possible implementation of the first aspect, obtaining the preset feature dictionary includes:
[0013] Obtain sample images corresponding to each of N image types, where N is a positive integer;
[0014] The sample images corresponding to each of the N image types are input into the detection model to obtain the second feature data of each sample image;
[0015] The feature dictionary is generated from the second feature data of the sample images corresponding to each of the N image types.
[0016] In one possible implementation of the first aspect, calculating the weight matrix based on the first feature data and the second feature data in the feature dictionary includes:
[0017] By using the formula min{||Y-XD|| 2 Calculate the weight matrix, where Y represents the first feature data, X represents the weight matrix, and D represents the feature dictionary.
[0018] In one possible implementation of the first aspect, calculating the detection score of the image to be detected based on the first score corresponding to the image type and the weight matrix includes:
[0019] The second score is obtained by weighting the first score corresponding to each of the N image types with the weight matrix;
[0020] Calculate the sum of the absolute values of each element in the weight matrix to obtain the third score;
[0021] The detection score of the image to be detected is calculated based on the second score and the third score.
[0022] In one possible implementation of the first aspect, determining the detection result of the image to be detected based on the detection score includes:
[0023] Calculate the score difference between the first score and the detection score for each image type;
[0024] The image type corresponding to the smallest score difference is determined as the detection result of the image to be detected.
[0025] In one possible implementation of the first aspect, before inputting the image to be detected into the trained detection model to obtain the first feature data of the image to be detected, the method further includes:
[0026] Obtain multiple training images corresponding to each of the N image types;
[0027] A preset neural network is trained based on the multiple training images;
[0028] When the detection accuracy of the neural network reaches a preset accuracy, the detection model is obtained from the neural network, wherein the detection model is a sub-network in the neural network used to extract image features.
[0029] Secondly, embodiments of this application provide an image detection apparatus, comprising:
[0030] The feature acquisition unit is used to input the image to be detected into the trained detection model and acquire the first feature data of the image to be detected.
[0031] A dictionary acquisition unit is used to acquire a preset feature dictionary, wherein the feature dictionary includes the second feature data of each of the multiple sample images extracted by the detection model;
[0032] The weight calculation unit is used to calculate a weight matrix based on the first feature data and the second feature data in the feature dictionary, wherein the weight matrix includes weights corresponding to the image types to which the plurality of sample images belong, and the weights are used to represent the similarity between the first feature data and the second feature data;
[0033] A score calculation unit is used to calculate the detection score of the image to be detected based on the first score corresponding to the image type and the weight matrix;
[0034] An image detection unit is used to determine the detection result of the image to be detected based on the detection score.
[0035] Thirdly, embodiments of this application provide a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the computer program to implement the image detection method as described in any one of the first aspects above.
[0036] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, characterized in that the computer program, when executed by a processor, implements the image detection method as described in any one of the first aspects above.
[0037] Fifthly, embodiments of this application provide a computer program product that, when run on a terminal device, causes the terminal device to execute the image detection method described in any one of the first aspects.
[0038] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here. Attached Figure Description
[0039] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0040] Figure 1 This is a schematic diagram of the deep learning-based age detection process provided in an embodiment of this application;
[0041] Figure 2 This is a schematic flowchart of the image detection method provided in the embodiments of this application;
[0042] Figure 3 This is a schematic diagram of the image detection process provided in an embodiment of this application;
[0043] Figure 4 This is a structural block diagram of the image detection device provided in the embodiments of this application;
[0044] Figure 5 This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. Detailed Implementation
[0045] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0046] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0047] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0048] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0049] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0050] References to "one embodiment" or "some embodiments" in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized.
[0051] First, we will introduce the background technology of image detection methods based on deep learning.
[0052] In existing technologies, a large number of training images are typically collected, and a deep learning network is trained using these images to obtain the trained network. The trained network is then used to detect the images to be detected.
[0053] For example, see facial age detection. Figure 1 This is a schematic diagram of the deep learning-based age detection process provided in an embodiment of this application. First, multiple training images corresponding to each age group are collected, ensuring a uniform distribution of the number of training images across different age groups. Then, the training images are used to train a deep learning network (such as...). Figure 1 The deep learning PFLD network shown is trained to obtain the trained network. Then, as... Figure 1 As shown, the image to be detected is input into the trained deep learning pfld network to obtain the age prediction result.
[0054] The methods described above not only require collecting a large number of training images, but also ensuring that the number of training images corresponding to each age group is evenly distributed; otherwise, the detection accuracy of the trained network will be low. It is evident that the detection accuracy of existing image detection methods depends on the training data, and the collection of training data is difficult, time-consuming, and costly, resulting in high network training costs.
[0055] To address the aforementioned problems, embodiments of this application provide an image detection method. See also... Figure 2 This is a schematic flowchart of an image detection method provided in an embodiment of this application. It is intended as an example and not a limitation. The method may include the following steps:
[0056] S201, Input the image to be detected into the trained detection model to obtain the first feature data of the image to be detected.
[0057] The difference between the detection model in this application embodiment and the deep learning network in the prior art is that the existing deep learning network outputs image detection results, while the detection model in this application embodiment outputs image features (i.e. feature data) of the last feature extraction layer of the deep learning network.
[0058] In one embodiment, prior to S201, the method further includes:
[0059] Obtain multiple training images corresponding to each of the N image types; train a preset neural network based on the multiple training images; when the detection accuracy of the neural network reaches the preset accuracy, obtain the detection model from the neural network, wherein the detection model is a sub-network in the neural network used to extract image features.
[0060] For example, the pre-defined neural network includes a feature extraction subnetwork and a detection subnetwork. After an image is input into the neural network, the feature extraction subnetwork extracts the image's feature data, which is then input into the detection subnetwork, which identifies the detection result. During training, multiple training images are input into the neural network, and a loss value is calculated based on the output detection results and a pre-defined loss function. The neural network is then trained in reverse based on the loss value. When the detection accuracy of the neural network reaches a pre-defined accuracy, the feature extraction subnetwork in the neural network is determined as the detection model.
[0061] As can be seen from the above, the detection model in this embodiment is only used to extract feature data of the image and is not used to obtain the detection result of the image.
[0062] S202, obtain a preset feature dictionary, which includes the second feature data of each of the multiple sample images extracted by the detection model.
[0063] In the process of constructing the feature dictionary, the same detection model as in S201 is used, which can avoid large feature data errors caused by sampling different feature extraction networks.
[0064] In one embodiment, the process of constructing the feature dictionary may include:
[0065] Obtain sample images corresponding to each of the N image types; input the sample images corresponding to each of the N image types into the detection model to obtain the second feature data of each sample image; generate the feature dictionary from the second feature data of the sample images corresponding to each of the N image types. Wherein, N is a positive integer.
[0066] It should be noted that the N image types mentioned in this embodiment can be pre-defined. Accordingly, when training the detection model, it is also necessary to collect multiple training images corresponding to each of the N image types to train the preset neural network. When constructing the feature dictionary, it is also necessary to obtain sample images corresponding to the same N image types.
[0067] Taking facial age detection as an example, if we need to detect ages from 0 to 70, this equates to 71 image types, each corresponding to a specific age. When training the detection model, training images corresponding to each age range (0-70) are collected to train a pre-defined neural network. When constructing the feature dictionary, sample images corresponding to each age range (0-70) are collected.
[0068] In this embodiment of the application, the step of generating the feature dictionary can be achieved by arranging the second feature data corresponding to each sample image in a random order. Alternatively, the feature dictionary can be generated by arranging the second feature data corresponding to each sample image according to the order of N image types.
[0069] Continuing with the example of face age detection, we can take 100 sample images for each age group. Following the order of age, we generate a matrix from the second feature data of each of the 100 sample images corresponding to ages 0-70. This matrix is denoted as the feature dictionary. For example, the 100 sets of second feature data corresponding to age 0 are located in rows 0-99 of the matrix, the 100 sets of second feature data corresponding to age 1 are located in rows 100-199, and so on. This yields a 7100×M dimension matrix, denoted as the feature dictionary, where M is the dimension of a set of second feature data.
[0070] Of course, the above is just an example of generating a feature dictionary. It can also be arranged in the order of matrix columns or other orders. No specific restrictions are made here.
[0071] In existing technologies, feature dictionaries are typically constructed using features from the original image. Unlike existing feature dictionary construction methods, this application uses image features processed by a detection model to construct the feature dictionary. Compared to existing technologies, the method used in this application to construct the feature dictionary effectively reduces the dimensionality of the feature data; furthermore, the image features processed by the detection model are more representative and can better highlight the image's attribute features for subsequent detection.
[0072] It should be noted that the feature dictionary can be constructed during each image detection process, but this method results in low image detection efficiency. Alternatively, it can be constructed before step S201, allowing the pre-constructed feature dictionary to be directly obtained during each detection process, thus saving image detection time.
[0073] S203, calculate the weight matrix based on the first feature data and the second feature data in the feature dictionary.
[0074] The weight matrix includes weights corresponding to the image types of each of the multiple sample images, and the weights are used to represent the similarity between the first feature data and the second feature data.
[0075] In one embodiment, the weight matrix is calculated as follows:
[0076] By using the formula min{||Y-XD|| 2 Calculate the weight matrix, where Y represents the first feature data, X represents the weight matrix, and D represents the feature dictionary.
[0077] Using the above formula, when the calculated min value is less than the preset threshold, it can be considered that the XD corresponding to the min value can represent Y.
[0078] Since only sample images with high similarity share features, the weight matrix in this embodiment can be considered a sparse matrix. In this sparse matrix, a large number of elements are 0, and a small number of elements have non-zero values. The value of each element is its weight; the larger the value of an element, the more similar the second feature data corresponding to that element is to the first feature data, and thus the closer the image to be detected is to the image type corresponding to that element.
[0079] S204, calculate the detection score of the image to be detected based on the first score corresponding to the image type and the weight matrix.
[0080] In this embodiment, the first score corresponding to the image type is a preset value. Optionally, the first score corresponding to each image type can be set to the same value. For example, the first score corresponding to N image types can all be set to 1.
[0081] Taking facial age detection as an example, the first score corresponding to the image type can be set as the age value. For example, the first score for 0 years old (image type) is 0, the first score for 1 year old (image type) is 1, and so on.
[0082] In one embodiment, the detection score of the image to be detected is calculated as follows:
[0083] The second score is obtained by weighting the first score corresponding to each of the N image types with the weight matrix; the second score is then determined as the detection score of the image to be detected.
[0084] In one embodiment, the detection score of the image to be detected is calculated as follows:
[0085] The first score corresponding to each of the N image types is weighted by the weight matrix to obtain the second score; the sum of the absolute values of each element in the weight matrix is calculated to obtain the third score; and the detection score of the image to be detected is calculated based on the second score and the third score.
[0086] Specifically, the detection score of the image to be detected can be calculated using the following formula:
[0087] Through formula Calculate the detection score for the image to be detected. Where w i For the i-th element (i.e., the i-th weight) in the weight matrix, class i For w i The corresponding image category, where H is the number of elements in the weight matrix.
[0088] Continuing with the example of face age detection, as shown above, in the feature dictionary, the 100 sets of second feature data corresponding to age 0 are located in rows 0-99 of the matrix, the 100 sets of second feature data corresponding to age 1 are located in rows 100-199, and so on. Calculating the detection score is equivalent to multiplying the weights of the elements in rows 0-99 by 0 (corresponding to age 0), multiplying the weights of the elements in rows 100-199 by 1 (corresponding to age 1), and so on. Then, all the calculated products are added together, and finally, the result is divided by the sum of the absolute values of all elements in the weight matrix to obtain the detection score.
[0089] S205, determine the detection result of the image to be detected based on the detection score.
[0090] As described in S204, when the first scores corresponding to various image types are the same, one implementation of S205 is to: determine the numerical range to which the detection score belongs; and determine the image type corresponding to the numerical range as the detection result of the image to be detected.
[0091] For example, we can pre-define that the image type is I for a value range of 0-50, and the image type is II for a value range of 51-100. If the detection score is 40, then the detection result of the image to be detected is I.
[0092] Taking face age detection as an example, the first score corresponding to the image type is set as the age value. The age corresponding to the detection score can be determined as the detection result of the image to be detected. For example, if the detection score is 50, then the detection result of the image to be detected is 50 years old.
[0093] In practical applications, the following situation may occur: the calculated detection score does not correspond to a specific age. For example, the detection score is 40.2, but the ages are all integers. To solve this problem, in one embodiment, S205 is implemented as follows:
[0094] Calculate the score difference between the first score and the detection score for each image type; determine the image type corresponding to the smallest score difference as the detection result of the image to be detected.
[0095] For example, if the detection score is 40.2, the difference between it and the first score 40 is 0.2, and the difference between it and the first score 41 is 0.8, then the image type 41 corresponding to 41 is determined as the detection result of the image to be detected.
[0096] The above methods can ensure the validity of the test results.
[0097] In this embodiment, a weight matrix is calculated between the first feature data of the image to be detected and the second feature data of each sample image in a preset feature dictionary. The weights in the weight matrix represent the similarity between the first and second feature data. Since only sample images with high similarity to the image to be detected contribute features, the detection score of the image to be detected, calculated based on the first score corresponding to the image type and the weight matrix, can be used to characterize the detection result of the image to be detected. This method utilizes feature data from a limited set of sample images in the feature dictionary to calculate the similarity between features. Because both the first feature data and the feature dictionary are obtained through the same detection model, even if the training accuracy of the detection model is low, accurate image features can still be detected through subsequent feature comparison. This avoids extensive training of the detection model, effectively reducing the dependence on the training dataset when training the detection model and lowering the training cost of the detection model.
[0098] In this embodiment of the application, the training images used in the process of training the preset neural network can also be used as sample images when constructing the feature dictionary, which can further reduce the cost of collecting the dataset.
[0099] The following section uses facial age detection as an example to illustrate the complete image detection process. (See also...) Figure 3 This is a schematic diagram of the image detection process provided in an embodiment of this application. Figure 3 As shown, firstly, a deep learning model (detection model) is trained using training images to obtain a trained deep learning model. The trained deep learning model then learns image features (second feature data) for age-related images and uses these features to construct a feature dictionary containing feature data for each age group from 0 to 70 years old, corresponding to step S202 above. During detection, the image to be predicted is input into the trained deep learning model to obtain the image features (first feature data) of the image to be detected, corresponding to step S201 above. Based on the feature dictionary, the image features of the image to be detected are learned to obtain a detection score for the image to be detected, corresponding to steps S203-S204 above. Finally, the age prediction result of the image to be detected is determined based on this detection score, corresponding to step S205 above.
[0100] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0101] Corresponding to the image detection method described in the above embodiments, Figure 4 This is a structural block diagram of the image detection device provided in the embodiments of this application. For ease of explanation, only the parts related to the embodiments of this application are shown.
[0102] Reference Figure 4 The device includes:
[0103] The feature acquisition unit 41 is used to input the image to be detected into the trained detection model and acquire the first feature data of the image to be detected.
[0104] The dictionary acquisition unit 42 is used to acquire a preset feature dictionary, which includes the second feature data of each of the multiple sample images extracted by the detection model.
[0105] The weight calculation unit 43 is used to calculate a weight matrix based on the first feature data and the second feature data in the feature dictionary, wherein the weight matrix includes weights corresponding to the image types to which the multiple sample images belong, and the weights are used to represent the similarity between the first feature data and the second feature data.
[0106] The score calculation unit 44 is used to calculate the detection score of the image to be detected based on the first score corresponding to the image type and the weight matrix.
[0107] Image detection unit 45 is used to determine the detection result of the image to be detected based on the detection score.
[0108] Optionally, dictionary retrieval unit 42 is also used for:
[0109] Obtain sample images corresponding to each of N image types, where N is a positive integer;
[0110] The sample images corresponding to each of the N image types are input into the detection model to obtain the second feature data of each sample image;
[0111] The feature dictionary is generated from the second feature data of the sample images corresponding to each of the N image types.
[0112] Optionally, the weight calculation unit 43 is also used for:
[0113] By using the formula min{||Y-XD|| 2 Calculate the weight matrix, where Y represents the first feature data, X represents the weight matrix, and D represents the feature dictionary.
[0114] Optionally, the fraction calculation unit 44 is also used for:
[0115] The second score is obtained by weighting the first score corresponding to each of the N image types with the weight matrix;
[0116] Calculate the sum of the absolute values of each element in the weight matrix to obtain the third score;
[0117] The detection score of the image to be detected is calculated based on the second score and the third score.
[0118] Optionally, the image detection unit 45 is also used for:
[0119] Calculate the score difference between the first score and the detection score for each image type;
[0120] The image type corresponding to the smallest score difference is determined as the detection result of the image to be detected.
[0121] Optionally, device 4 also includes:
[0122] The model training unit 46 is used to input the image to be detected into the trained detection model, obtain multiple training images corresponding to each of the N image types; train a preset neural network based on the multiple training images; and when the detection accuracy of the neural network reaches the preset accuracy, obtain the detection model from the neural network, wherein the detection model is a sub-network in the neural network used to extract image features.
[0123] It should be noted that the information interaction and execution process between the above-mentioned devices / units are based on the same concept as the method embodiments of this application. For details on their specific functions and technical effects, please refer to the method embodiments section, and they will not be repeated here.
[0124] in addition, Figure 4 The image detection device shown can be a software unit, a hardware unit, or a combination of software and hardware built into an existing terminal device. It can also be integrated into the terminal device as an independent component, or exist as a standalone terminal device.
[0125] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0126] Figure 5This is a schematic diagram of the structure of the terminal device provided in the embodiments of this application. For example... Figure 5 As shown, the terminal device 5 in this embodiment includes: at least one processor 50 ( Figure 5 (Only one is shown) a processor, a memory 51, and a computer program 52 stored in the memory 51 and executable on the at least one processor 50, wherein the processor 50 executes the computer program 52 to implement the steps in any of the above-described image detection method embodiments.
[0127] The terminal device may be a desktop computer, laptop, handheld computer, or cloud server, etc. This terminal device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that... Figure 5 This is merely an example of terminal device 5 and does not constitute a limitation on terminal device 5. It may include more or fewer components than shown in the figure, or combine certain components, or different components, such as input / output devices, network access devices, etc.
[0128] The processor 50 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0129] In some embodiments, the memory 51 may be an internal storage unit of the terminal device 5, such as a hard disk or memory of the terminal device 5. In other embodiments, the memory 51 may be an external storage device of the terminal device 5, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the terminal device 5. Furthermore, the memory 51 may include both internal and external storage units of the terminal device 5. The memory 51 is used to store the operating system, applications, boot loader, data, and other programs, such as the program code of the computer program. The memory 51 can also be used to temporarily store data that has been output or will be output.
[0130] This application also provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps described in the various method embodiments above.
[0131] This application provides a computer program product that, when run on a terminal device, enables the terminal device to implement the steps described in the various method embodiments above.
[0132] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of this application can be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include at least: any entity or device capable of carrying computer program code to a device / terminal equipment, a recording medium, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium. Examples include USB flash drives, portable hard drives, magnetic disks, or optical disks. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electrical carrier signals or telecommunication signals.
[0133] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0134] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0135] In the embodiments provided in this application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0136] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0137] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. An image detection method, characterized in that, include: The image to be detected is input into the trained detection model to obtain the first feature data of the image to be detected. Obtain sample images corresponding to each of N image types, where N is a positive integer; The sample images corresponding to each of the N image types are input into the detection model to obtain the second feature data of each sample image; According to the arrangement order of the N image types, the second feature data of the sample images corresponding to each of the N image types are used to generate a feature dictionary; A weight matrix is calculated based on the first feature data and the second feature data in the feature dictionary. The weight matrix includes weights corresponding to the image types of multiple sample images, and the weights are used to represent the similarity between the first feature data and the second feature data. The second score is obtained by weighting the first score corresponding to each of the N image types with the weight matrix; Calculate the sum of the absolute values of each element in the weight matrix to obtain the third score; The detection score of the image to be detected is calculated based on the second score and the third score; Calculate the score difference between the first score and the detection score for each image type; wherein, when the image type is age, the first score for each image type is the age value corresponding to the image type; The image type corresponding to the smallest score difference is determined as the detection result of the image to be detected.
2. The image detection method as described in claim 1, characterized in that, The step of calculating the weight matrix based on the first feature data and the second feature data in the feature dictionary includes: Through formula Calculate the weight matrix, where, This represents the first feature data. Represents the weight matrix, This refers to the feature dictionary.
3. The image detection method as described in claim 1, characterized in that, Before inputting the image to be detected into the trained detection model to obtain the first feature data of the image to be detected, the method further includes: Obtain multiple training images corresponding to each of the N image types; A preset neural network is trained based on the multiple training images; When the detection accuracy of the neural network reaches a preset accuracy, the detection model is obtained from the neural network, wherein the detection model is a sub-network in the neural network used to extract image features.
4. An image detection device, characterized in that, include: The feature acquisition unit is used to input the image to be detected into the trained detection model and acquire the first feature data of the image to be detected. A dictionary acquisition unit is used to acquire a preset feature dictionary, wherein the feature dictionary includes the second feature data of each of the multiple sample images extracted by the detection model; The weight calculation unit is used to calculate a weight matrix based on the first feature data and the second feature data in the feature dictionary, wherein the weight matrix includes weights corresponding to the image types to which the plurality of sample images belong, and the weights are used to represent the similarity between the first feature data and the second feature data; A score calculation unit is used to calculate the detection score of the image to be detected based on the first score corresponding to the image type and the weight matrix; An image detection unit is used to determine the detection result of the image to be detected based on the detection score; The dictionary acquisition unit is also used for: Obtain sample images corresponding to each of N image types, where N is a positive integer; The sample images corresponding to each of the N image types are input into the detection model to obtain the second feature data of each sample image; The feature dictionary is generated by using the second feature data of the sample images corresponding to each of the N image types in the order of their arrangement. The fraction calculation unit is also used for: The second score is obtained by weighting the first score corresponding to each of the N image types with the weight matrix; Calculate the sum of the absolute values of each element in the weight matrix to obtain the third score; The detection score of the image to be detected is calculated based on the second score and the third score; The image detection unit is also used for: Calculate the score difference between the first score and the detection score for each image type; wherein, when the image type is age, the first score for each image type is the age value corresponding to the image type; The image type corresponding to the smallest score difference is determined as the detection result of the image to be detected.
5. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the method as described in any one of claims 1 to 3.
6. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Image characteristic sparse reconstruction based image classification method
CN103646256A
Image classification method and device of embedded terminal and embedded terminal
CN112861934A