Disclosure of Invention
The invention mainly aims to provide an image identification method, an image identification device, image identification equipment and a storage medium, and aims to solve the technical problem of low image identification accuracy rate in the prior art.
In order to achieve the above object, the present invention provides an image recognition method, comprising the steps of:
acquiring an image to be identified, and carrying out normalization processing on each image in the image to be identified to obtain a normalized image set;
determining a normalization matrix corresponding to the image to be identified according to the normalization image set;
determining the category label of each image in the image to be identified according to the normalization matrix and a pre-trained convolutional neural network model;
and marking each image in the images to be recognized according to the category label of each image so as to finish the recognition of the images to be recognized.
Optionally, before the obtaining of the image to be identified and the normalization processing of each image in the image to be identified to obtain the normalized image set, the method further includes:
acquiring an original image, and dividing the original image into a training image set and a test image set;
training an initial convolutional neural network model according to the training image set;
when the training error of the initial convolutional neural network model is converged, obtaining an error convergence convolutional neural network model;
determining a test error according to the test image set and the error convergence convolutional neural network model;
when the test error is smaller than or equal to a preset error, acquiring a labeled image;
determining the prediction accuracy of the labeled image according to the labeled image and the error convergence convolutional neural network model;
judging whether the prediction accuracy is smaller than a preset accuracy;
and if the prediction accuracy is not less than the preset accuracy, taking the error convergence convolutional neural network model as a pre-trained convolutional neural network model.
Optionally, after determining whether the prediction accuracy is smaller than a preset accuracy, the method further includes:
if the prediction accuracy is smaller than a preset accuracy, obtaining an image with a prediction error in the labeled image;
and taking the image with the wrong prediction as an original image, returning to execute the step of obtaining the original image, dividing the original image into a training image and a testing image, and taking an error convergence convolutional neural network model when the prediction accuracy is greater than or equal to a preset accuracy as a pre-trained convolutional neural network model.
Optionally, the determining a normalization matrix corresponding to the image to be identified according to the normalization image set includes:
carrying out size reconstruction on each normalized image in the normalized image set to obtain a normalized reconstructed image set;
and determining a normalization matrix corresponding to the image to be identified according to the normalization reconstructed image set.
Optionally, the determining the category label of each image in the image to be recognized according to the normalization matrix and a pre-trained convolutional neural network model includes:
inputting the normalization matrix into a pre-trained convolutional neural network model so that the pre-trained convolutional neural network model performs batch classification on the normalization matrix;
when the batch classification is finished, obtaining the category label of each image in the images to be identified
Optionally, the marking, according to the category label of each image, each image in the images to be recognized to complete recognition of the images to be recognized includes:
marking each image in the images to be identified according to the category label of each image;
and storing the marked images into a database to complete the identification of the image to be identified.
Optionally, the dividing the original image into a training image and a test image includes:
and dividing the original image into a training image and a test image according to a preset proportion.
In addition, to achieve the above object, the present invention also provides an image recognition apparatus, comprising:
the acquisition module is used for acquiring images to be identified and normalizing each image in the images to be identified to obtain a normalized image set;
the determining module is used for determining a normalization matrix corresponding to the image to be identified according to the normalization image set;
the class label determining module is used for determining class labels of all images in the images to be recognized according to the normalized matrix and a pre-trained convolutional neural network model;
and the marking module is used for marking each image in the images to be identified according to the category label of each image so as to finish the identification of the images to be identified.
Further, to achieve the above object, the present invention also provides an image recognition apparatus comprising: a memory, a processor and an image recognition program stored on the memory and executable on the processor, the image recognition program being configured to implement the steps of the image recognition method as described above.
Furthermore, to achieve the above object, the present invention also proposes a storage medium having stored thereon an image recognition program which, when executed by a processor, implements the steps of the image recognition method as described above.
The method comprises the steps of obtaining an image to be identified, and carrying out normalization processing on each image in the image to be identified to obtain a normalized image set; determining a normalization matrix corresponding to the image to be identified according to the normalization image set; determining the category label of each image in the image to be identified according to the normalization matrix and a pre-trained convolutional neural network model; the images in the images to be recognized are marked according to the category labels of the images, and the recognition of the images to be recognized is completed.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a schematic structural diagram of an image recognition device in a hardware operating environment according to an embodiment of the present invention.
As shown in fig. 1, the image recognition apparatus may include: a processor 1001, such as a Central Processing Unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display), an input unit such as a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a Wireless interface (e.g., a Wireless-Fidelity (WI-FI) interface). The Memory 1005 may be a Random Access Memory (RAM) or a Non-Volatile Memory (NVM), such as a disk Memory. The memory 1005 may alternatively be a storage device separate from the processor 1001.
Those skilled in the art will appreciate that the configuration shown in fig. 1 does not constitute a limitation of the image recognition apparatus, and may include more or less components than those shown, or combine certain components, or a different arrangement of components.
As shown in fig. 1, a memory 1005, which is a storage medium, may include therein an operating system, a data storage module, a network communication module, a user interface module, and an image recognition program.
In the image recognition apparatus shown in fig. 1, the network interface 1004 is mainly used for data communication with a network server; the user interface 1003 is mainly used for data interaction with a user; the processor 1001 and the memory 1005 of the image recognition apparatus of the present invention may be provided in the image recognition apparatus which calls the image recognition program stored in the memory 1005 through the processor 1001 and executes the image recognition method provided by the embodiment of the present invention.
An embodiment of the present invention provides an image recognition method, and referring to fig. 2, fig. 2 is a flowchart illustrating a first embodiment of the image recognition method according to the present invention.
In this embodiment, the image recognition method includes the following steps:
step S10: acquiring an image to be identified, and carrying out normalization processing on each image in the image to be identified to obtain a normalized image set.
It should be noted that the execution main body of the embodiment may be a computing service device with data processing, network communication, and program running functions, such as a tablet computer, a personal computer, a mobile phone, or an upper computer, or an electronic device, an image recognition device, and the like capable of implementing the above functions. The present embodiment and the following embodiments are described below by taking an image recognition apparatus as an example, and are not to be construed as limiting the present embodiment.
It can be understood that the image to be recognized is an unidentified image uploaded by a user, the image to be recognized includes a plurality of images, and at least one of a legal image and an illegal image is included in the image to be recognized.
It should be understood that each pixel of the image may be represented by three primary color components of red, green and blue, the normalization process is a process of calculating an average value of the red, green and blue components of each pixel of the image, respectively, subtracting the average value from the value of the red, green and blue components of each pixel, and dividing the result by the variance corresponding to each pixel color, and the normalization process is performed on the image to obtain a normalized image corresponding to the image, and the normalized images corresponding to the images form a normalized image set.
Step S20: and determining a normalization matrix corresponding to the image to be identified according to the normalization image set.
It can be understood that the normalized images in the normalized image set are subjected to image size reconstruction processing, the normalized images can be processed into normalized images with uniform sizes after the size reconstruction processing, a matrix with a preset size can be randomly cut out from the normalized images with uniform sizes, the size of the matrix can be set according to a specific scene, and after each image in the normalized image set is subjected to the processing, the processed normalized images are combined to obtain a normalized matrix corresponding to the image to be identified.
Step S30: and determining the class label of each image in the image to be recognized according to the normalization matrix and a pre-trained convolutional neural network model.
It should be understood that the class label is a label capable of distinguishing the class of the image to be identified according to a set standard, the pre-trained convolutional neural network model is a convolutional neural network model which is in accordance with a use standard after being trained and tested, the normalization matrix is input into the pre-trained convolutional neural network model, and the pre-trained convolutional neural network model identifies the normalization matrix to obtain the class label of each corresponding normalized image in the normalization matrix.
Step S40: and marking each image in the images to be identified according to the category label of each image to finish the identification of the images to be identified.
It can be understood that each image has a category label, the category labels correspond to the image categories one by one, and the images can be labeled as different pictures according to the category labels, such as legal pictures and illegal pictures, color pictures and black and white pictures, and the like, which can be determined according to specific usage scenarios, which is not limited in this embodiment.
In particular implementations, for example: acquiring various images to be processed uploaded to a server by a user, processing the images in the images to be processed by a third party Python library, converting the images in the images to be processed from UINT8 integer data to FLOAT32 floating point data of 0 to 1, carrying out normalization processing by using the color average value and variance of the images in the images to be processed to obtain a normalized image set, reconstructing the size of the normalized images in the normalized image set to be a uniform size of 256 × 256, randomly cutting out a matrix of 224 × 224 size from each normalized image after the size is reconstructed, merging all the normalized images subjected to the processing into a four-dimensional floating point matrix, if 32 images exist in the images to be processed, expressing the size of the four-dimensional floating point matrix to be 32 × 3 × 224, wherein the four-dimensional floating point matrix is a normalized matrix, and inputting the convolution matrix into a pre-trained neural network model, the pre-trained convolutional neural network model may be a pre-trained RESNEXT50 convolutional neural network model, the model processes input data to obtain a category label of each image in the image to be recognized, the category label may be represented by 0 and 1, an image with the category label of 1 may be labeled as an illegal image according to the category label of each image, and an image with the category label of 0 is labeled as a legal image, thereby completing image recognition of the image to be recognized.
Further, in order to obtain the category label of each image more accurately, the step S30 includes: inputting the normalization matrix into a pre-trained convolutional neural network model so that the pre-trained convolutional neural network model performs batch classification on the normalization matrix; and when the batch classification is finished, obtaining the category label of each image in the images to be identified.
It can be understood that the normalization matrix corresponding to the image to be recognized is input into the pre-trained convolutional neural network model, the pre-trained convolutional neural network model performs batch classification on the input normalization matrix, and the batch classification is performed by performing batch labeling classification on the input normalization matrix, where the batch classification may be batch two classification, that is, the input normalization matrix data is divided into two classes, one class may be represented by 1, and the other class may be represented by 0, after the above processing, each image is obtained with a class label, for example, the class label 1 represents an illegal picture, the class label 0 represents a legal picture, and other symbols may also be used to represent class labels, such as letters, symbols, and the like, which is not limited in this embodiment.
Further, in order to improve the efficiency of image recognition, the step S40 includes: marking each image in the images to be identified according to the category label of each image; and storing the marked images into a database to complete the identification of the image to be identified.
It can be understood that the image is marked as a specific image according to the label category of the image, for example, if the label category of a certain image is 1, the image is marked as an illegal image, if the label category of a certain image is 0, the image is marked as a legal image, each image in the image data to be processed is marked, and the image after the marking is stored in the database, so that the identification of the image to be identified is completed.
In the embodiment, a normalized image set is obtained by acquiring an image to be identified and normalizing each image in the image to be identified; determining a normalization matrix corresponding to the image to be identified according to the normalization image set; determining the category label of each image in the image to be identified according to the normalization matrix and a pre-trained convolutional neural network model; the image identification of the image to be identified is completed by performing normalization processing on the image in the image to be identified, determining a normalization matrix corresponding to the image to be identified according to the image after the normalization processing, determining an image label according to the normalization matrix and a pre-trained convolutional neural network, and marking each image according to the image label.
Referring to fig. 3, fig. 3 is a flowchart illustrating an image recognition method according to a second embodiment of the present invention.
Based on the first embodiment, in this embodiment, before the step S10, the method further includes:
step S01: an original image is acquired and divided into a training image set and a test image set.
It should be understood that the original image is an image selected for training and testing the initial convolutional neural network model, the original image may be a certain number of legal images and illegal images collected from the network, and the proportion of the legal images and illegal images in the original image can be controlled to be balanced during the collection process, so as to achieve better training and testing effects.
It should be understood that the training image set is a set of images used to train the initial convolutional neural network, and the test image set is a set of images used to test the accuracy of the trained initial convolutional neural network.
Step S02: and training an initial convolutional neural network model according to the training image set.
It should be appreciated that the initial convolutional neural network model is trained and parameter optimized by inputting a set of training images into the initial convolutional neural network model.
Step S03: and when the training error of the initial convolutional neural network model is converged, obtaining an error converged convolutional neural network model.
It can be understood that, in the process of training the initial convolutional neural network model, when the value of the error function of the initial convolutional neural network model is smaller than the preset error value, the training error of the initial convolutional neural network model is converged, and at this stage, the training of the model is completed, so as to obtain the error-converged convolutional neural network model.
Step S04: and determining a test error according to the test image set and the error convergence convolutional neural network model.
It can be understood that the test image set is input into the error convergence convolutional neural network model, the class label of each image in the test image set can be obtained after the error convergence convolutional neural network model is processed, the images with the class labels are examined, the pictures marked by the error convergence convolutional neural network with the class labels are marked out, and then the test error of the error convergence convolutional neural network can be obtained according to the number of the total test image data.
Step S05: and when the test error is less than or equal to a preset error, acquiring labeled image data.
It should be understood that when the test error of the error convergence convolutional neural network model is less than or equal to the preset error, the tagged image data is obtained, and the tagged image data may be data with an image tag that is manually screened and identified, that is, each image in the image data is marked with an image tag after being manually reviewed, for example, is marked as a legal image or an illegal image.
It can be understood that when the test error is greater than the preset error, new original image data can be continuously acquired, and the convolutional neural network model is trained and tested until the test error is less than or equal to the preset error.
Step S06: and determining the prediction accuracy of the labeled image according to the labeled image and the error convergence convolutional neural network model.
It should be understood that the labeled image is input into the error converging convolutional neural network, the error converging convolutional neural network model processes the input labeled image and labels the input labeled image, and the prediction accuracy of the error converging convolutional neural network model is determined according to the labeled image of the input error converging convolutional neural network model and the class label of the image data output by the error converging convolutional neural network model, for example: and (3) the data of the labeled images are 100 labeled images, and after the data are processed by an error convergence convolutional neural network model, the category labels of 5 images are inconsistent with the original labels, so that the prediction accuracy is 95%.
Step S07: and judging whether the prediction accuracy is smaller than a preset accuracy.
It should be understood that the preset accuracy is an accuracy that is preset to meet the current usage scenario, and different usage scenarios have different requirements on the accuracy of the model, and the preset accuracy may be set according to a specific usage scenario in this embodiment.
Step S08: and if the prediction accuracy is not less than the preset accuracy, taking the error convergence convolutional neural network model as a pre-trained convolutional neural network model.
It can be understood that if the preset accuracy is not less than the preset accuracy, the error convergence convolutional neural network model is represented to meet the current use scenario, and the error convergence convolutional neural network model is used on line as a pre-trained convolutional neural network model.
Further, in order to improve the accuracy of image recognition, after the step S07, the method further includes: if the prediction accuracy is smaller than a preset accuracy, obtaining an image with a prediction error in the labeled image; and taking the image with the wrong prediction as an original image, returning to execute the step of obtaining the original image, dividing the original image into a training image set and a testing image set, and taking an error convergence convolutional neural network model when the prediction accuracy is greater than or equal to a preset accuracy as a pre-trained convolutional neural network model.
It should be understood that if the prediction accuracy is smaller than the preset accuracy, it indicates that the model cannot meet the current use scenario, at this time, an image with a prediction error in the labeled image is collected, the step of obtaining an original image is executed in a return mode, the original image is divided into a training image set and a testing image set, iterative training is performed on the initial convolutional neural network model until the prediction accuracy of the error convergence convolutional neural network model is greater than or equal to the preset accuracy, and at this time, the corresponding error convergence convolutional neural network model is used on line as the convolutional neural network model which is trained in advance.
It can be understood that, in order to save the time of model training and improve the efficiency of model training, if the prediction accuracy is less than the preset accuracy, an image with a prediction error in the labeled image is obtained, the image with the prediction error is divided into a training image set and a test image set, the error convergence convolutional neural network model obtained last time is used as an initial convolutional neural network model for iterative training, until the prediction accuracy is greater than or equal to the preset accuracy, the corresponding error convergence convolutional neural network model is used online as the pre-trained convolutional neural network model.
Further, in order to improve the picture recognition accuracy, the dividing the original image into a training image set and a testing image set includes: and dividing the original image set into a training image set and a test image set according to a preset proportion.
It should be understood that the preset ratio may be determined according to a specific application scenario, for example, if the preset ratio is 10:1, the ratio of the training image set to the test image set in the original image set is divided into 10:1, and may also be set to other ratios according to the specific application scenario.
In the embodiment, the original image is divided into the training image set and the testing image set, when the initial convolutional neural network model is subjected to error convergence after being trained by the training image data, the testing error of the error convergence convolutional neural network is determined according to the testing image set, when the test error is less than or equal to the preset error, the prediction accuracy of the label image test error convergence convolutional neural network model is used, when the prediction accuracy is greater than or equal to the preset accuracy, the error convergence convolutional neural network model is used on line as a pre-trained convolutional neural network model, when the prediction accuracy is smaller than the preset accuracy, iterative training is carried out on the error convergence convolutional neural network model by using the image with the wrong prediction, the technical problem of low model image identification accuracy in the prior art is solved, and the model training efficiency and the image identification accuracy are improved.
Referring to fig. 4, fig. 4 is a flowchart illustrating an image recognition method according to a third embodiment of the present invention.
Based on the foregoing embodiments, in this embodiment, the step S20 includes:
step S201: and carrying out size reconstruction on each normalized image in the normalized image set to obtain a normalized reconstructed image set.
It should be understood that after performing the size reconstruction of each normalized image in the normalized image set, the images in the normalized image set have a uniform size, and a normalized reconstructed image set is obtained, for example, the images in the normalized image set may be reconstructed to a size of 256 × 256.
Step S202: and determining a normalization matrix corresponding to the image to be identified according to the normalization reconstructed image set.
It should be understood that a matrix with a preset size is randomly cut out from the planning reconstructed images in the normalized reconstructed image set, and after all the normalized reconstructed images are processed, the processed images are combined into a four-dimensional floating point matrix, which is the normalized matrix.
In the embodiment, the normalized image is subjected to size reconstruction, and the image subjected to size reconstruction is cut and finally combined into the four-dimensional floating point matrix, so that the efficiency of image identification is improved.
Furthermore, an embodiment of the present invention further provides a storage medium, on which an image recognition program is stored, and the image recognition program, when executed by a processor, implements the steps of the image recognition method as described above.
Referring to fig. 5, fig. 5 is a block diagram of an image recognition apparatus according to a first embodiment of the present invention.
As shown in fig. 5, an image recognition apparatus according to an embodiment of the present invention includes: an acquisition module 10, a determination module 20, a category label determination module 30, and a labeling module 40.
The acquisition module 10 is configured to acquire an image to be identified, and perform normalization processing on each image in the image to be identified to obtain a normalized image set;
a determining module 20, configured to determine, according to the normalized image set, a normalized matrix corresponding to the image to be identified;
a category label determination module 30, configured to determine a category label of each image in the image to be identified according to the normalization matrix and a pre-trained convolutional neural network model;
and the marking module 40 is configured to mark each image in the images to be recognized according to the category label of each image, so as to complete recognition of the images to be recognized.
In this embodiment, an obtaining module 10 obtains an image to be identified, and performs normalization processing on each image in the image to be identified to obtain a normalized image set; the determining module 20 determines a normalization matrix corresponding to the image to be identified according to the normalization image set; the category label determining module 30 determines a category label of each image in the image to be recognized according to the normalized matrix and a pre-trained convolutional neural network model; the labeling module 40 labels each image in the image to be recognized according to the category label of each image to complete the recognition of the image to be recognized, because the image in the image to be recognized is normalized, the normalization matrix corresponding to the image to be recognized is determined according to the image after the normalization processing, the image label is determined according to the normalization matrix and the pre-trained convolutional neural network, and each image is labeled according to the image label, the recognition of the image to be recognized is completed, the technical problem of high misjudgment rate when a large number of images are recognized in the prior art is solved, and the accuracy of the image recognition is improved.
A second embodiment of the image recognition apparatus of the present invention is proposed based on the above-described first embodiment of the image recognition apparatus of the present invention.
In this embodiment, the obtaining module 10 is further configured to obtain an original image, and divide the original image into a training image set and a testing image set; training an initial convolutional neural network model according to the training image set; when the training error of the initial convolutional neural network model is converged, obtaining an error convergence convolutional neural network model; determining a test error according to the test image set and the error convergence convolutional neural network model; when the test error is smaller than or equal to a preset error, acquiring a labeled image; determining the prediction accuracy of the labeled image according to the labeled image and the error convergence convolutional neural network model; judging whether the prediction accuracy is smaller than a preset accuracy; and if the prediction accuracy is not less than the preset accuracy, taking the error convergence convolutional neural network model as a pre-trained convolutional neural network model.
The obtaining module 10 is further configured to obtain an image with a prediction error in the labeled image if the prediction accuracy is smaller than a preset accuracy; and taking the image with the wrong prediction as an original image, returning to execute the step of obtaining the original image, dividing the original image into a training image and a testing image, and taking an error convergence convolutional neural network model when the prediction accuracy is greater than or equal to a preset accuracy as a pre-trained convolutional neural network model.
The determining module 20 is further configured to perform size reconstruction on each normalized image in the normalized image set to obtain a normalized reconstructed image set; and determining a normalization matrix corresponding to the image to be identified according to the normalization reconstructed image set.
The class label determining module 30 is further configured to input the normalization matrix into a pre-trained convolutional neural network model, so that the pre-trained convolutional neural network model performs batch classification on the normalization matrix; and when the batch classification is finished, obtaining the category label of each image in the images to be identified.
The marking module 40 is further configured to mark each image in the images to be identified according to the category label of each image; and storing the marked images into a database to complete the identification of the image to be identified.
The obtaining module 10 is further configured to divide the original image into a training image and a test image according to a preset ratio.
Other embodiments or specific implementation manners of the image recognition apparatus of the present invention may refer to the above method embodiments, and are not described herein again.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or system. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or system that comprises the element.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., a rom/ram, a magnetic disk, an optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.