Image recognition method, device, storage medium and electronic device
By performing data enhancement on the target image and updating the model parameters using the comparison results of the two recognition models, the problem of low network performance of the deep learning model is solved, and more efficient LOGO recognition is achieved.
Patent Information
- Application Number
- CN202210578525.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-25
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2042-05-25
AI Technical Summary
In the existing technology, the deep learning model in the field of logo recognition lacks sufficient labeled data, resulting in low network performance and difficulty in effective improvement.
By performing data enhancement on the target image, a first image and a second image are generated, and they are input into the first recognition model and the second recognition model respectively. The cosine distance between the output results of the two is calculated, and the model parameters are updated according to the comparison results until the classification result is output when the comparison result is less than the threshold.
The network performance of the deep learning model has been improved, and the accuracy and stability of LOGO recognition have been enhanced.
Smart Images

Figure CN114972865B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computers, and in particular to an image recognition method, device, storage medium and electronic equipment. Background Art
[0002] Deep learning is currently the most common technology used in the field of artificial intelligence. Its most basic approach is called supervised learning, in which all data is manually annotated. This annotation is used to guide the training of deep learning neural networks, enabling them to meet specific requirements. Over time, deep learning has spawned many other learning methods, including self-supervised learning, whose main idea is to supervise its own learning. A neural network is given two different variations of the same image (such as one rotated and one mirrored), so that the network's output can determine that the two inputs are from the same image. The primary problem self-supervised learning addresses is the low network performance caused by the scarcity of manually annotated data. In the field of logo recognition, existing techniques separate logo detection and recognition, handling the latter separately. Instead of using classification, a search-based approach is used. A binary classification detector is first trained to determine the logo's location in the image. The logo is then fed into a search network to retrieve the category of the most similar logo. However, labeled data is required for training, and the number of LOGO datasets currently available in academia is very limited and their quality is very poor, which results in insufficient improvement in the performance of network training results. Summary of the Invention
[0003] Embodiments of the present invention provide an image recognition method, apparatus, storage medium, and electronic device to at least solve the technical problem of low network performance of a training model.
[0004] According to one aspect of an embodiment of the present invention, there is provided an image recognition method, comprising: acquiring a target image, wherein the target image contains an object to be classified; performing data enhancement on the target image to obtain a first image and a second image; inputting the first image into a first recognition model to obtain a first output result and determining a classification result of the target image based on the first output result, and inputting the second image into a second recognition model to obtain a second output result; acquiring a comparison result between the first output result and the second output result; and outputting the classification result of the target image when the comparison result is less than a threshold value.
[0005] According to another aspect of an embodiment of the present invention, an image recognition device is provided, including: a first acquisition module, used to acquire a target image, wherein the target image contains an object to be classified; a processing module, used to perform data enhancement on the target image to obtain a first image and a second image; an input module, used to input the first image into a first recognition model to obtain a first output result and determine a classification result of the target image based on the first output result, and input the second image into a second recognition model to obtain a second output result; a second acquisition module, used to obtain a comparison result between the first output result and the second output result; and an output module, used to output the classification result of the target image when the comparison result is less than a threshold value.
[0006] As an optional example, the above-mentioned processing module includes: a first rotation unit, used to rotate the above-mentioned target image by a first degree to obtain a first rotated image; a first flipping unit, used to flip the above-mentioned first rotated image horizontally or vertically to obtain a first flipped image; a first cropping unit, used to randomly crop the above-mentioned first flipped image to obtain the above-mentioned first image; a second rotation unit, used to rotate the above-mentioned target image by a second degree to obtain a second rotated image; a second flipping unit, used to flip the above-mentioned second rotated image horizontally or vertically to obtain a second flipped image; and a second cropping unit, used to randomly crop the above-mentioned second flipped image to obtain the above-mentioned second image.
[0007] As an optional example, the second acquisition module includes: a calculation unit, configured to calculate a cosine distance between the first output result and the second output result to obtain the comparison result.
[0008] As an optional example, the apparatus further includes: an updating module, configured to update the model parameters of the first recognition model and the second recognition model when the comparison result is greater than or equal to the threshold.
[0009] As an optional example, the above-mentioned update module includes: a first adjustment unit, used to adjust the model parameters of the above-mentioned first recognition model; a first recognition unit, used to use the adjusted above-mentioned first recognition model to recognize the above-mentioned first image to obtain the above-mentioned first output result; a second adjustment unit, used to continue adjusting the model parameters of the above-mentioned first recognition model when the above-mentioned target image includes the above-mentioned object to be classified, when the above-mentioned comparison result is still greater than or equal to the above-mentioned threshold, or when the above-mentioned classification result is different from the above-mentioned annotation result, until the above-mentioned comparison result is less than the above-mentioned threshold and the above-mentioned classification result is the same as the above-mentioned annotation result.
[0010] As an optional example, the above-mentioned update module includes: a third adjustment unit, used to adjust the model parameters of the above-mentioned first recognition model; a second recognition unit, used to use the adjusted above-mentioned first recognition model to recognize the above-mentioned first image to obtain the above-mentioned first output result; a fourth adjustment unit, used to continue adjusting the model parameters of the above-mentioned first recognition model when the above-mentioned target image does not include the above-mentioned object to be classified and the above-mentioned comparison result is still greater than or equal to the above-mentioned threshold, until the above-mentioned comparison result is less than the above-mentioned threshold.
[0011] As an optional example, the above-mentioned update module includes: an acquisition unit, used to obtain the updated model parameters of the above-mentioned first recognition model and the current model parameters of the above-mentioned second recognition model after update; a processing unit, used to update the above-mentioned second recognition model according to the updated model parameters of the above-mentioned first recognition model and the current model parameters of the above-mentioned second recognition model, and obtain the updated model parameters of the above-mentioned second recognition model.
[0012] As an optional example, the above-mentioned processing unit includes: a first processing sub-unit, used to multiply the updated model parameters of the above-mentioned first recognition model by a first value to obtain the first model parameters; a second processing sub-unit, used to multiply the current model parameters of the above-mentioned second recognition model by a second value to obtain the second model parameters, wherein the sum of the above-mentioned first value and the above-mentioned second value is 1; a third processing sub-unit, used to sum the above-mentioned first model parameters and the above-mentioned second model parameters to obtain the updated model parameters of the above-mentioned second recognition model.
[0013] According to another aspect of the embodiments of the present invention, a storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the image recognition method is executed.
[0014] According to another aspect of an embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the image recognition method through the computer program.
[0015] The above-mentioned image recognition method of the present application can be used in the process of computer vision of deep learning technology. In an embodiment of the present invention, a target image is obtained, wherein the above-mentioned target image contains an object to be classified; data enhancement is performed on the above-mentioned target image to obtain a first image and a second image; the above-mentioned first image is input into a first recognition model to obtain a first output result and the classification result of the above-mentioned target image is determined based on the above-mentioned first output result, and the above-mentioned second image is input into a second recognition model to obtain a second output result; a comparison result between the above-mentioned first output result and the above-mentioned second output result is obtained; and when the above-mentioned comparison result is less than a threshold, the classification result of the above-mentioned target image is output. Since in the above-mentioned method, the target image is recognized by the first recognition model and the second recognition model to obtain a comparison result, the first recognition model and the second recognition model are continuously updated according to the comparison result until the comparison result is less than the threshold, and the classification result is output, thereby achieving the purpose of improving the network performance of the first recognition model and the second recognition model, and then solving the technical problem of low network performance of the training model. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:
[0017] Figure 1 is a flow chart of an optional image recognition method according to an embodiment of the present invention;
[0018] Figure 2 is a specific flow chart of an optional image recognition method according to an embodiment of the present invention;
[0019] Figure 3 is a schematic structural diagram of an optional image recognition device according to an embodiment of the present invention;
[0020] Figure 4 is a schematic diagram of an optional electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0021] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0022] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0023] According to a first aspect of an embodiment of the present invention, a method for recognizing an image is provided. Optionally, as follows: Figure 1 As shown, the above method includes:
[0024] S102, obtaining a target image, wherein the target image contains an object to be classified;
[0025] S104, performing data enhancement on the target image to obtain a first image and a second image;
[0026] S106, inputting the first image into a first recognition model to obtain a first output result and determining a classification result of the target image based on the first output result, and inputting the second image into a second recognition model to obtain a second output result;
[0027] S108, obtaining a comparison result between the first output result and the second output result;
[0028] S110: When the comparison result is less than the threshold, output the classification result of the target image.
[0029] Optionally, in this embodiment, the target image can be an image with a product logo and include the classification result to which the product logo belongs. For example, if the target image is a product logo composed of multiple letters, the classification result belongs to the letter class. The first recognition model and the second recognition model are two models with the same structure. The difference is that the parameters of the second recognition model are steadily updated by the parameters of the first recognition model, and the parameters of the first recognition model are obtained by back propagation through the comparison results. The first output result and the second output result are two vectors, and the comparison result is the cosine distance of the two vectors. The smaller the cosine distance of the two vectors, the more similar the two models are, and the better the network performance of the second recognition model.
[0030] Optionally, in this embodiment, a target image containing an object to be classified is obtained, and the target image is rotated at different angles, flipped, randomly cropped, and the like to obtain different first and second images. The first image is input into a first recognition model to obtain a first output result and a classification result of the target image. The second image is input into a second recognition model to obtain a second output result, wherein the first output result and the second output result are two different vectors. The cosine distance between the first output result and the second output result is calculated to obtain a comparison result. When the comparison result is less than a threshold, it indicates that the network performance of the second recognition model is very good. At this time, the classification result output by the first recognition model is the classification result of the target image, and this classification result is output. For example, if the threshold is 0.3, the classification result output by the first recognition model is a letter class, the calculated comparison result is 0.2, the comparison result is less than the threshold, and the output result is a letter class.
[0031] Optionally, in this embodiment, the target image is identified by the first recognition model and the second recognition model to obtain a comparison result, and the first recognition model and the second recognition model are continuously updated according to the comparison result until the comparison result is less than a threshold, and the classification result is output, thereby achieving the purpose of improving the network performance of the first recognition model and the second recognition model, and further solving the technical problem of low network performance of the training model.
[0032] As an optional example, performing data augmentation on the target image to obtain the first image and the second image includes:
[0033] Performing an angular rotation of a first degree on the target image to obtain a first rotated image;
[0034] flipping the first rotated image horizontally or vertically to obtain a first flipped image;
[0035] Randomly crop the first flipped image to obtain a first image;
[0036] Performing an angular rotation of a second degree on the target image to obtain a second rotated image;
[0037] flipping the second rotated image horizontally or vertically to obtain a second flipped image;
[0038] The second flipped image is randomly cropped to obtain a second image.
[0039] Optionally, in this embodiment, the first degree can be 30 degrees, 90 degrees, or 120 degrees, and the second degree can be 40 degrees, 70 degrees, or 150 degrees. The target image is first rotated 90 degrees by the first degree, then flipped horizontally, and finally a portion of the image is randomly cropped to obtain the first image. The target image is first rotated 150 degrees by the second degree, then flipped vertically, and finally a portion of the image is randomly cropped to obtain the second image. This increases the richness of the training images and allows for better training of the first and second recognition models.
[0040] As an optional example, obtaining a comparison result between the first output result and the second output result includes:
[0041] Calculate the cosine distance between the first output result and the second output result to obtain a comparison result.
[0042] Optionally, in this embodiment, the cosine distance between two different vectors of the first output result and the second output result, that is, the comparison result, is calculated, which can be 0.2, 0.5, or 0.8. The smaller the cosine distance, the more similar the two vectors are, that is, the more similar the two models are, and the better the network performance of the two recognition models.
[0043] As an optional example, the above method further includes:
[0044] When the comparison result is greater than or equal to the threshold, the model parameters of the first recognition model and the second recognition model are updated.
[0045] Optionally, in this embodiment, the threshold value is a critical condition for the stability of the two models. When the comparison result is greater than or equal to the threshold value, it indicates that the two models are unstable and require further training and updating. When the comparison result is less than the threshold value, it indicates that the two models are stable and do not require further training and updating. For example, if the threshold value is 0.3 and the comparison result is 0.4, the comparison result is greater than the threshold value, and the model parameters of the first recognition model and the second recognition model need to be updated.
[0046] As an optional example, when the comparison result is greater than or equal to the threshold, updating the model parameters of the first recognition model includes:
[0047] adjusting model parameters of the first recognition model;
[0048] Recognize the first image using the adjusted first recognition model to obtain a first output result;
[0049] When the target image includes the object to be classified, when the comparison result is still greater than or equal to the threshold, or when the classification result is different from the annotation result, continue to adjust the model parameters of the first recognition model until the comparison result is less than the threshold and the classification result is the same as the annotation result.
[0050] Optionally, in this embodiment, the model parameters of the first recognition model are adjusted to obtain the adjusted first recognition model, and the first image is input into the adjusted first recognition model to obtain a first output result, a recognition result, and a classification result. When the target image includes the object to be classified, the comparison result is greater than or equal to the threshold, or the classification result is different from the labeling result, the network performance of the first recognition model is not stable enough, and the model parameters of the first recognition model are adjusted in a loop until the recognition result is less than the threshold and the classification result is the same as the labeling result. The network performance of the first recognition model is stable, and there is no need to update and adjust the model parameters of the first recognition model.
[0051] As an optional example, when the comparison result is greater than or equal to the threshold, updating the model parameters of the first recognition model includes:
[0052] adjusting model parameters of the first recognition model;
[0053] Recognize the first image using the adjusted first recognition model to obtain a first output result;
[0054] When the target image does not include the object to be classified and the comparison result is still greater than or equal to the threshold, the model parameters of the first recognition model are continuously adjusted until the comparison result is less than the threshold.
[0055] Optionally, in this embodiment, the model parameters of the first recognition model are adjusted to obtain the adjusted first recognition model, and the first image is input into the adjusted first recognition model to obtain a first output result, a recognition result, and a classification result. When the target image does not include the object to be classified and the comparison result is greater than or equal to the threshold, the network performance of the first recognition model is not stable enough, and the model parameters of the first recognition model are adjusted in a loop until the recognition result is less than the threshold and the network performance of the first recognition model is stable, and there is no need to update and adjust the model parameters of the first recognition model.
[0056] As an optional example, when the comparison result is greater than or equal to the threshold, updating the model parameters of the second recognition model includes:
[0057] Obtain updated model parameters of the updated first recognition model and current model parameters of the second recognition model;
[0058] The second recognition model is updated according to the updated model parameters of the first recognition model and the current model parameters of the second recognition model to obtain updated model parameters of the second recognition model.
[0059] Optionally, in this embodiment, after the performance of the updated first recognition model stabilizes, the updated model parameters of the updated first recognition model and the current model parameters of the second recognition model are obtained, and the second recognition model is updated according to the updated model parameters of the first recognition model and the current model parameters of the second recognition model to obtain the updated model parameters of the second recognition model.
[0060] As an optional example, updating the second recognition model according to the updated model parameters of the first recognition model and the current model parameters of the second recognition model to obtain the updated model parameters of the second recognition model includes:
[0061] multiplying the updated model parameters of the first recognition model by the first value to obtain first model parameters;
[0062] multiplying a current model parameter of the second recognition model by a second value to obtain a second model parameter, wherein a sum of the first value and the second value is 1;
[0063] The first model parameters and the second model parameters are summed to obtain updated model parameters of the second recognition model.
[0064] Optionally, in this embodiment, the sum of the first value and the second value is 1, and the first value and the second value can be 0.2 and 0.8, 0.3 and 0.7. For example, when the first value is 0.2 and the second value is 0.8, the updated parameter of the first recognition model is multiplied by the first value 0.2, and the current model parameter of the second recognition parameter is multiplied by the second value 0.8. The sum of the two products is used as the updated model parameter of the second recognition model.
[0065] Optionally, in conjunction with an example, the present application relates to an image recognition method, which recognizes a target image through a first recognition model and a second recognition model to obtain a comparison result, and continuously updates the first recognition model and the second recognition model according to the comparison result until the comparison result is less than a threshold, and then outputs a classification result. The specific process is as follows: Figure 2 shown.
[0066] 1. Input the target image and generate two images after data enhancement, that is, the target image is rotated at different angles, flipped horizontally or vertically, randomly cropped, and other operations.
[0067] 2. The first image is input to the first recognition model, and the second image is input to the second recognition model. After the two images pass through different models, the first output result and the second output result are output. The first recognition model outputs the classification result of the target image.
[0068] The first and second recognition models have identical structures. The difference is that the model parameters of the second recognition model are steadily updated using the model parameters of the first recognition model. The model parameters of the second recognition model are obtained by backpropagating the first and second output results. The update of the second recognition model is the sum of the current model parameters of the second recognition model multiplied by 0.8 and the updated model parameters of the first recognition model multiplied by 0.2.
[0069] 3. Calculate the cosine distance between the first output result and the second output result, that is, the comparison result. The smaller the cosine distance, the more similar the results obtained by the two models for the same image, and the more stable the algorithm.
[0070] 4. The first recognition model determines whether the input target image has a labeling result. If so and the comparison result is less than the threshold, it outputs the classification result of the target image.
[0071] It should be noted that for the aforementioned method embodiments, for simplicity of description, they are all expressed as a series of action combinations. However, those skilled in the art should be aware that the present invention is not limited by the order of the actions described, because according to the present invention, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present invention.
[0072] According to another aspect of the embodiment of the present application, an image recognition device is also provided, such as Figure 3 As shown, including:
[0073] A first acquisition module 302 is configured to acquire a target image, wherein the target image contains an object to be classified;
[0074] A processing module 304 is configured to perform data enhancement on the target image to obtain a first image and a second image;
[0075] An input module 306 is configured to input the first image into a first recognition model to obtain a first output result and determine a classification result of the target image based on the first output result, and input the second image into a second recognition model to obtain a second output result;
[0076] A second acquisition module 308 is used to obtain a comparison result between the first output result and the second output result;
[0077] The output module 310 is configured to output the classification result of the target image when the comparison result is less than a threshold.
[0078] Optionally, in this embodiment, the target image can be an image with a product logo and include the classification result to which the product logo belongs. For example, if the target image is a product logo composed of multiple letters, the classification result belongs to the letter class. The first recognition model and the second recognition model are two models with the same structure. The difference is that the parameters of the second recognition model are steadily updated by the parameters of the first recognition model, and the parameters of the first recognition model are obtained by back propagation through the comparison results. The first output result and the second output result are two vectors, and the comparison result is the cosine distance of the two vectors. The smaller the cosine distance of the two vectors, the more similar the two models are, and the better the network performance of the second recognition model.
[0079] Optionally, in this embodiment, a target image containing an object to be classified is obtained, and the target image is rotated at different angles, flipped, randomly cropped, and the like to obtain different first and second images. The first image is input into a first recognition model to obtain a first output result and a classification result of the target image. The second image is input into a second recognition model to obtain a second output result, wherein the first output result and the second output result are two different vectors. The cosine distance between the first output result and the second output result is calculated to obtain a comparison result. When the comparison result is less than a threshold, it indicates that the network performance of the second recognition model is very good. At this time, the classification result output by the first recognition model is the classification result of the target image, and this classification result is output. For example, if the threshold is 0.3, the classification result output by the first recognition model is a letter class, the calculated comparison result is 0.2, the comparison result is less than the threshold, and the output result is a letter class.
[0080] Optionally, in this embodiment, the target image is identified by the first recognition model and the second recognition model to obtain a comparison result, and the first recognition model and the second recognition model are continuously updated according to the comparison result until the comparison result is less than a threshold, and the classification result is output, thereby achieving the purpose of improving the network performance of the first recognition model and the second recognition model, and further solving the technical problem of low network performance of the training model.
[0081] As an optional example, the processing module includes:
[0082] a first rotation unit, configured to perform an angular rotation of a first degree on the target image to obtain a first rotated image;
[0083] a first flipping unit, configured to flip the first rotated image horizontally or vertically to obtain a first flipped image;
[0084] A first cropping unit, configured to randomly crop the first flipped image to obtain a first image;
[0085] a second rotation unit, configured to rotate the target image by a second degree to obtain a second rotated image;
[0086] a second flipping unit, configured to flip the second rotated image horizontally or vertically to obtain a second flipped image;
[0087] The second cropping unit is configured to randomly crop the second flipped image to obtain a second image.
[0088] Optionally, in this embodiment, the first degree can be 30 degrees, 90 degrees, or 120 degrees, and the second degree can be 40 degrees, 70 degrees, or 150 degrees. The target image is first rotated 90 degrees by the first degree, then flipped horizontally, and finally a portion of the image is randomly cropped to obtain the first image. The target image is first rotated 150 degrees by the second degree, then flipped vertically, and finally a portion of the image is randomly cropped to obtain the second image. This increases the richness of the training images and allows for better training of the first and second recognition models.
[0089] As an optional example, the second acquisition module includes:
[0090] The calculation unit is used to calculate the cosine distance between the first output result and the second output result to obtain a comparison result.
[0091] Optionally, in this embodiment, the cosine distance between two different vectors of the first output result and the second output result, that is, the comparison result, is calculated, which can be 0.2, 0.5, or 0.8. The smaller the cosine distance, the more similar the two vectors are, that is, the more similar the two models are, and the better the network performance of the two recognition models.
[0092] As an optional example, the above device further includes:
[0093] The updating module is used to update the model parameters of the first recognition model and the second recognition model when the comparison result is greater than or equal to the threshold.
[0094] Optionally, in this embodiment, the threshold value is a critical condition for the stability of the two models. When the comparison result is greater than or equal to the threshold value, it indicates that the two models are unstable and require further training and updating. When the comparison result is less than the threshold value, it indicates that the two models are stable and do not require further training and updating. For example, if the threshold value is 0.3 and the comparison result is 0.4, the comparison result is greater than the threshold value, and the model parameters of the first recognition model and the second recognition model need to be updated.
[0095] As an optional example, the update module includes:
[0096] A first adjustment unit, configured to adjust model parameters of the first recognition model;
[0097] a first recognition unit, configured to recognize the first image using the adjusted first recognition model to obtain a first output result;
[0098] The second adjustment unit is used to continue adjusting the model parameters of the first recognition model when the target image includes the object to be classified and the comparison result is still greater than or equal to the threshold, or when the classification result is different from the annotation result, until the comparison result is less than the threshold and the classification result is the same as the annotation result.
[0099] Optionally, in this embodiment, the model parameters of the first recognition model are adjusted to obtain the adjusted first recognition model, and the first image is input into the adjusted first recognition model to obtain a first output result, a recognition result, and a classification result. When the target image includes the object to be classified, the comparison result is greater than or equal to the threshold, or the classification result is different from the labeling result, the network performance of the first recognition model is not stable enough, and the model parameters of the first recognition model are adjusted in a loop until the recognition result is less than the threshold and the classification result is the same as the labeling result. The network performance of the first recognition model is stable, and there is no need to update and adjust the model parameters of the first recognition model.
[0100] As an optional example, the update module includes:
[0101] a third adjustment unit, configured to adjust model parameters of the first recognition model;
[0102] a second recognition unit, configured to recognize the first image using the adjusted first recognition model to obtain a first output result;
[0103] The fourth adjustment unit is configured to, when the target image does not include the object to be classified and the comparison result is still greater than or equal to the threshold, continue adjusting the model parameters of the first recognition model until the comparison result is less than the threshold.
[0104] Optionally, in this embodiment, the model parameters of the first recognition model are adjusted to obtain the adjusted first recognition model, and the first image is input into the adjusted first recognition model to obtain a first output result, a recognition result, and a classification result. When the target image does not include the object to be classified and the comparison result is greater than or equal to the threshold, the network performance of the first recognition model is not stable enough, and the model parameters of the first recognition model are adjusted in a loop until the recognition result is less than the threshold and the network performance of the first recognition model is stable, and there is no need to update and adjust the model parameters of the first recognition model.
[0105] As an optional example, the update module includes:
[0106] an acquiring unit, configured to acquire updated model parameters of the updated first recognition model and current model parameters of the second recognition model;
[0107] The processing unit is configured to update the second recognition model according to the updated model parameters of the first recognition model and the current model parameters of the second recognition model to obtain the updated model parameters of the second recognition model.
[0108] Optionally, in this embodiment, after the performance of the updated first recognition model stabilizes, the updated model parameters of the updated first recognition model and the current model parameters of the second recognition model are obtained, and the second recognition model is updated according to the updated model parameters of the first recognition model and the current model parameters of the second recognition model to obtain the updated model parameters of the second recognition model.
[0109] As an optional example, the processing unit includes:
[0110] a first processing subunit, configured to multiply an updated model parameter of the first recognition model by a first value to obtain a first model parameter;
[0111] a second processing subunit, configured to multiply a current model parameter of the second recognition model by a second value to obtain a second model parameter, wherein a sum of the first value and the second value is 1;
[0112] The third processing subunit is configured to sum the first model parameters and the second model parameters to obtain updated model parameters of the second recognition model.
[0113] Optionally, in this embodiment, the sum of the first value and the second value is 1, and the first value and the second value can be 0.2 and 0.8, 0.3 and 0.7. For example, when the first value is 0.2 and the second value is 0.8, the updated parameter of the first recognition model is multiplied by the first value 0.2, and the current model parameter of the second recognition parameter is multiplied by the second value 0.8. The sum of the two products is used as the updated model parameter of the second recognition model.
[0114] For other examples of this embodiment, please refer to the above examples and will not be repeated here.
[0115] Figure 4 is a structural block diagram of an optional electronic device according to an embodiment of the present application, such as Figure 4 As shown, it includes a processor 402, a communication interface 404, a memory 406 and a communication bus 408, wherein the processor 402, the communication interface 404 and the memory 406 communicate with each other through the communication bus 408, wherein,
[0116] Memory 406, for storing computer programs;
[0117] The processor 402 is configured to execute the computer program stored in the memory 406 to implement the following steps:
[0118] Acquire a target image, wherein the target image contains an object to be classified;
[0119] Performing data enhancement on the target image to obtain a first image and a second image;
[0120] Inputting the first image into a first recognition model to obtain a first output result and determining a classification result of the target image based on the first output result, and inputting the second image into a second recognition model to obtain a second output result;
[0121] Obtaining a comparison result between the first output result and the second output result;
[0122] When the comparison result is less than the threshold, the classification result of the target image is output.
[0123] Optionally, in this embodiment, the communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 4 The use of only one thick line in the figure does not mean that there is only one bus or only one type of bus. The communication interface is used for communication between the above electronic devices and other devices.
[0124] The memory may include RAM, or may include non-volatile memory, such as at least one disk memory. Alternatively, the memory may also be at least one storage device located away from the aforementioned processor.
[0125] As an example, the memory 406 may include, but is not limited to, the first acquisition module 302, processing module 304, input module 306, second acquisition module 308, and output module 310 in the image recognition device. Furthermore, the memory 406 may also include, but is not limited to, other module units in the request processing device, which will not be described in detail in this example.
[0126] The above-mentioned processor can be a general-purpose processor, including but not limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0127] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0128] It can be understood by those skilled in the art that Figure 4 The structure shown is for illustration only. The device for implementing the above-mentioned image recognition method may be a terminal device, which may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (MID), a PAD, or other terminal devices. Figure 4 It does not limit the structure of the above electronic device. For example, the electronic device may also include Figure 4 More or fewer components (such as network interfaces, display devices, etc.) shown in, or with Figure 4 Different configurations shown.
[0129] A person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which can include: a flash drive, ROM, RAM, a magnetic disk or an optical disk, etc.
[0130] According to another aspect of the embodiments of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned image recognition method are executed.
[0131] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing the hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0132] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.
[0133] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above-mentioned computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the existing technology, or all or part of the technical solution can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes a number of instructions for causing one or more computer devices (such as personal computers, servers, or network devices) to execute all or part of the steps of the methods described in various embodiments of the present invention.
[0134] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0135] In the several embodiments provided in this application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, and can be electrical or other forms.
[0136] The units described as separate components may or may not be physically separate, and 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 these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0137] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0138] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as within the scope of protection of the present invention.
Claims
1. A method for image recognition, characterized in that: include: Acquire a target image, wherein the target image contains an object to be classified; Performing data enhancement on the target image to obtain a first image and a second image; Inputting the first image into a first recognition model to obtain a first output result and determining a classification result of the target image based on the first output result, inputting the second image into a second recognition model to obtain a second output result, wherein the first recognition model and the second recognition model are two models with the same structure, the parameters of the second recognition model are updated by the parameters of the first recognition model, and the parameters of the first recognition model are obtained by back propagation through the comparison result of the first output result and the second output result; Obtaining a comparison result between the first output result and the second output result; When the comparison result is less than a threshold value, outputting the classification result of the target image; When the comparison result is greater than or equal to the threshold, the model parameters of the first recognition model and the second recognition model are updated, including: adjusting the model parameters of the first recognition model; using the adjusted first recognition model to recognize the first image to obtain the first output result; when the target image includes the object to be classified, when the comparison result is still greater than or equal to the threshold, or the classification result is different from the annotation result, continue to adjust the model parameters of the first recognition model until the comparison result is less than the threshold and the classification result is the same as the annotation result; obtain the updated model parameters of the updated first recognition model and the current model parameters of the second recognition model; update the second recognition model according to the updated model parameters of the first recognition model and the current model parameters of the second recognition model to obtain the updated model parameters of the second recognition model.
2. The method according to claim 1, characterized in that Performing data enhancement on the target image to obtain the first image and the second image includes: Performing an angular rotation of a first degree on the target image to obtain a first rotated image; flipping the first rotated image horizontally or vertically to obtain a first flipped image; Randomly cropping the first flipped image to obtain the first image; performing an angular rotation of a second degree on the target image to obtain a second rotated image; flipping the second rotated image horizontally or vertically to obtain a second flipped image; The second flipped image is randomly cropped to obtain the second image.
3. The method according to claim 1, characterized in that The obtaining of a comparison result between the first output result and the second output result includes: A cosine distance between the first output result and the second output result is calculated to obtain the comparison result.
4. The method according to claim 1, wherein When the comparison result is greater than or equal to the threshold, updating the model parameters of the first recognition model includes: adjusting model parameters of the first recognition model; recognizing the first image using the adjusted first recognition model to obtain the first output result; In a case where the target image does not include the object to be classified, when the comparison result is still greater than or equal to the threshold, the model parameters of the first recognition model are continuously adjusted until the comparison result is less than the threshold.
5. The method according to claim 1, wherein The updating of the second recognition model according to the updated model parameters of the first recognition model and the current model parameters of the second recognition model to obtain the updated model parameters of the second recognition model includes: multiplying the updated model parameter of the first recognition model by a first value to obtain a first model parameter; multiplying a current model parameter of the second recognition model by a second value to obtain a second model parameter, wherein a sum of the first value and the second value is 1; The first model parameters and the second model parameters are summed to obtain updated model parameters of the second recognition model.
6. An image recognition device, characterized in that: include: A first acquisition module is used to acquire a target image, wherein the target image contains an object to be classified; a processing module, configured to perform data enhancement on the target image to obtain a first image and a second image; an input module, configured to input the first image into a first recognition model to obtain a first output result and determine a classification result of the target image based on the first output result, and input the second image into a second recognition model to obtain a second output result, wherein the first recognition model and the second recognition model are two models of identical structure, the parameters of the second recognition model are updated by the parameters of the first recognition model, and the parameters of the first recognition model are obtained by backpropagation through a comparison result of the first output result and the second output result; a second obtaining module, configured to obtain a comparison result between the first output result and the second output result; An output module is used to output the classification result of the target image when the comparison result is less than a threshold; and to update the model parameters of the first recognition model and the second recognition model when the comparison result is greater than or equal to the threshold, including: adjusting the model parameters of the first recognition model; using the adjusted first recognition model to recognize the first image to obtain the first output result; when the target image includes the object to be classified, when the comparison result is still greater than or equal to the threshold, or the classification result is different from the annotation result, continue to adjust the model parameters of the first recognition model until the comparison result is less than the threshold and the classification result is the same as the annotation result; obtain the updated model parameters of the updated first recognition model and the current model parameters of the second recognition model; update the second recognition model according to the updated model parameters of the first recognition model and the current model parameters of the second recognition model to obtain the updated model parameters of the second recognition model.
7. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is executed.
8. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 5 through the computer program.
Citation Information
Patent Citations
Image recognition apparatus, image recognition program, and image recognition method
CN101425141A
Target object recognition method and device, storage medium and electronic device
CN112633297A