CN114219051A - Image classification method, classification model training method and device and electronic equipment - Google Patents
Image classification method, classification model training method and device and electronic equipment Download PDFInfo
- Publication number
- CN114219051A CN114219051A CN202210164297.XA CN202210164297A CN114219051A CN 114219051 A CN114219051 A CN 114219051A CN 202210164297 A CN202210164297 A CN 202210164297A CN 114219051 A CN114219051 A CN 114219051A
- Authority
- CN
- China
- Prior art keywords
- training
- probability
- image
- patterns
- neural network
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/24—Classification techniques
- G06F18/241—Classification techniques relating to the classification model, e.g. parametric or non-parametric approaches
- G06F18/2415—Classification techniques relating to the classification model, e.g. parametric or non-parametric approaches based on parametric or probabilistic models, e.g. based on likelihood ratio or false acceptance rate versus a false rejection rate
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/21—Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
- G06F18/214—Generating training patterns; Bootstrap methods, e.g. bagging or boosting
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/23—Clustering techniques
- G06F18/232—Non-hierarchical techniques
- G06F18/2321—Non-hierarchical techniques using statistics or function optimisation, e.g. modelling of probability density functions
- G06F18/23213—Non-hierarchical techniques using statistics or function optimisation, e.g. modelling of probability density functions with fixed number of clusters, e.g. K-means clustering
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/004—Artificial life, i.e. computing arrangements simulating life
- G06N3/006—Artificial life, i.e. computing arrangements simulating life based on simulated virtual individual or collective life forms, e.g. social simulations or particle swarm optimisation [PSO]
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/04—Architecture, e.g. interconnection topology
- G06N3/045—Combinations of networks
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06N—COMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
- G06N3/00—Computing arrangements based on biological models
- G06N3/02—Neural networks
- G06N3/08—Learning methods
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- Evolutionary Computation (AREA)
- Life Sciences & Earth Sciences (AREA)
- Artificial Intelligence (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Molecular Biology (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Bioinformatics & Computational Biology (AREA)
- Software Systems (AREA)
- Health & Medical Sciences (AREA)
- Biomedical Technology (AREA)
- Biophysics (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Evolutionary Biology (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Probability & Statistics with Applications (AREA)
- Image Analysis (AREA)
Abstract
The application provides an image classification method, a classification model training method and device and electronic equipment. The method comprises the following steps: acquiring an image to be recognized, wherein the image to be recognized comprises an object to be recognized; inputting an image to be recognized into a preset first neural network, and acquiring a first probability that an object to be recognized is a solenopsis invicta; inputting the image to be recognized into a preset second neural network, and acquiring a second probability that the object to be recognized is a red imported fire ant nest; and determining the category of the object to be identified according to the magnitude relation among the first probability, the second probability and the preset probability value. By the method, the problem that the deep learning network in the prior art is difficult to directly identify the image of the solenopsis invicta and the image of the nest of the solenopsis invicta can be solved.
Description
Technical Field
The present application relates to the field of image processing technologies, and in particular, to an image classification method, a training method and device for a classification model, and an electronic device.
Background
At present, the monitoring, prevention and control work of the red imported fire ants still mainly adopts manual work, such as: the footprints and the nests of the red fire ants need to be surveyed one by one manually and then killed correspondingly. In order to monitor the occurrence of red fire ants rapidly, it is necessary to adopt an automatic monitoring device, namely, the occurrence of red fire ants is automatically recognized by adopting an image recognition method in artificial intelligence, but the popularization and the application of deep learning in the field of plant diseases and insect pests are not smooth at present, the main reason is that the application in the field is mostly in a subdivided field and customized, the current mainstream deep learning network is difficult to be directly used in actual projects, enterprises need to continuously test and improve network structure parameters to be applied to the projects, but the mode consumes time and labor cost very much.
Disclosure of Invention
An object of the embodiments of the present application is to provide an image classification method, a training method and device for a classification model, and an electronic device, so as to solve the problem that a deep learning network in the prior art is difficult to be directly used for identifying a solenopsis invicta image and a solenopsis invicta nest image.
The invention is realized by the following steps:
in a first aspect, an embodiment of the present application provides an image classification method, where the method includes: acquiring an image to be recognized, wherein the image to be recognized comprises an object to be recognized; inputting the image to be recognized into a preset first neural network, and acquiring a first probability that the object to be recognized is a solenopsis invicta; inputting the image to be recognized into a preset second neural network, and acquiring a second probability that the object to be recognized is a solenopsis invicta ant nest; determining the category of the object to be identified according to the magnitude relation among the first probability, the second probability and a preset probability value; the first neural network is obtained by performing mean clustering on a preset number of training patterns to obtain membership probability corresponding to training patterns belonging to the class of the solenopsis invicta and training image features corresponding to the training patterns; the second neural network is obtained by performing mean value clustering on training patterns with preset number to obtain membership probability corresponding to the training patterns belonging to the category of the ant nest of the red fire ants and training image features corresponding to the training patterns.
In the embodiment of the application, the first neural network is obtained by performing mean clustering on training patterns with preset number to obtain membership probability corresponding to the training patterns belonging to the class of the solenopsis invicta and training image features corresponding to the training patterns; the second neural network is obtained by performing mean value clustering on training patterns with preset number to obtain membership probability corresponding to the training patterns belonging to the category of the ant nest of the red fire ants and training image features corresponding to the training patterns. Therefore, after the image to be recognized is respectively input into the first neural network and the second neural network, the first neural network and the second neural network can directly recognize the image to be recognized, so that the first probability that the object to be recognized is the red fire ant and the second probability that the object to be recognized is the nest of the red fire ant can be respectively obtained. And the category of the object to be identified (namely the object to be identified is the solenopsis invicta, or the nest of the solenopsis invicta, or other categories) is determined according to the magnitude relation among the first probability, the second probability and the preset probability value, so that the identification of a plurality of objects can be realized. In addition, compare in the enterprise need to test the current degree of depth learning network constantly and improve the network structure parameter after, can apply to the project of monitoring the red imported fire ant emergence condition, above-mentioned mode can be directly applied to in this project to the human cost and the time cost of enterprise have been reduced.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the determining the category of the object to be identified according to a magnitude relationship between the first probability, the second probability, and a preset probability value includes: if the first probability and the second probability are both greater than the preset probability value and the first probability is greater than the second probability, determining that the object to be identified is the solenopsis invicta; and if the first probability and the second probability are both greater than the preset probability value and the first probability is smaller than the second probability, determining that the object to be identified is the solenopsis invicta ant nest.
In this embodiment of the application, when both the first probability and the second probability are greater than the preset probability values, it indicates that both the solenopsis invicta image and the solenopsis invicta nest image exist on the image to be recognized, that is, a plurality of objects exist on the image to be recognized. Therefore, the category of the object to be recognized in the image to be recognized can be rapidly and accurately determined through the magnitude relation between the first probability and the second probability.
With reference to the technical solution provided by the first aspect, in some possible implementations, the method further includes: if the first probability and the second probability are both smaller than the preset probability value, calling a preset recognition model to recognize the image to be recognized, and acquiring the category of the object to be recognized.
In this embodiment of the application, when the first probability and the second probability are smaller than the preset probability values, it indicates that the objects to be identified are solenopsis invicta and solenopsis invicta nest with lower probability, and may be other types of objects. At the moment, the preset identification model can be called to further identify the image to be identified, so that when the possibility that the object to be identified is a solenopsis invicta or a solenopsis invicta nest in the image to be identified is low, the category of the image to be identified is determined again through the identification model, and the object identification breadth is improved.
With reference to the technical solution provided by the first aspect, in some possible implementations, the method further includes: acquiring training patterns with the preset number and image characteristics corresponding to the training patterns, wherein the training patterns comprise solenopsis invicta patterns and solenopsis invicta nest patterns; performing mean clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern; classifying the training patterns according to the classification label vectors to judge whether the training patterns are solenopsis invicta patterns or solenopsis invicta nest patterns; training an initial first neural network by using a first training set to obtain the first neural network; the first training set comprises image features corresponding to the determined solenopsis invicta patterns and membership probability corresponding to the determined solenopsis invicta patterns.
In this application embodiment, through above-mentioned mode, can obtain the categorised label vector of every training pattern fast, avoid classifying and mark each training pattern through artificial mode to can judge each training pattern for red imported fire ant pattern or red imported fire ant nest pattern according to each categorised label vector, and then can obtain first training set fast. Furthermore, by improving the efficiency of acquiring the first training set, the efficiency of acquiring the first neural network is improved.
With reference to the technical solution provided by the first aspect, in some possible implementations, the method further includes: training an initial second neural network by using a second training set to obtain the second neural network; and the second training set comprises image characteristics corresponding to the ant nest patterns judged to be the red ants and membership probability corresponding to the ant nest patterns judged to be the red ants.
In the embodiment of the application, the second training set can be quickly acquired through the method, so that the efficiency of acquiring the second neural network is improved.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the obtaining the preset number of training patterns includes: acquiring the collection images with the preset number, wherein the collection images comprise solenopsis invicta images and solenopsis invicta nest images; sequentially carrying out low-cap transformation and binarization processing on each collected image to obtain the preset number of binarized images; and segmenting each binary image to obtain the training pattern.
In the embodiment of the application, the dark target can be highlighted from the bright background by performing low-cap transformation on the acquired collected images, namely, the solenopsis invicta or the solenopsis invicta nest is highlighted from the background of each collected image, so that the subsequent acquisition of the training pattern is facilitated. In addition, binarization processing is carried out on the collected image after low-hat transformation is completed, and the image after binarization processing is segmented, so that the training pattern can be quickly and accurately obtained.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the performing mean clustering on the training patterns to obtain a class label vector and a membership probability corresponding to each training pattern includes: s301: clustering the training patterns into two classes to obtain a classification label vector corresponding to each training pattern, wherein the two classes are the solenopsis invicta and the solenopsis invicta nest; s302: solving a preset cost function by adopting a Lagrange multiplier method to obtain an equation of a clustering center point and an equation of a membership probability matrix, wherein the membership probability matrix represents the probability of clustering each training pattern into a corresponding class, and comprises a membership probability corresponding to each training pattern; s303: and updating the initialized membership probability matrix and the clustering center point, calculating an error value according to the updated membership probability matrix value and the updated membership probability matrix value at the last time, and repeating the step S303 until the error value is smaller than a preset error threshold value to obtain the membership probability corresponding to each training pattern.
With reference to the technical solution provided by the first aspect, in some possible implementation manners, the image features include an area, a perimeter, a length, a width, and an average gray value of an image corresponding to each training pattern.
In the embodiment of the application, because the image features include the area, the perimeter, the length, the width and the average gray value of the image corresponding to the training pattern, when the first neural network and the second neural network are used for processing the image to be recognized, the features of the object to be recognized in the image to be recognized can be extracted from the five dimensions, so that the recognition accuracy can be improved, namely, the accuracy of the first probability and the second probability output by the first neural network and the second neural network is improved.
In a second aspect, an embodiment of the present application provides a method for training a classification model, where the classification model includes a first neural network, a second neural network, and a classification layer, and the method includes: acquiring training patterns with a preset number and image characteristics corresponding to the training patterns, wherein the training patterns comprise a first object pattern and a second object pattern; performing mean clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern; classifying the training patterns according to the classification label vectors to judge the training patterns to be first object patterns or second object patterns; training an initial first neural network by using a first training set to obtain the first neural network; the first training set comprises image features corresponding to the first object image and membership probability corresponding to the first object image; training an initial second neural network by using a second training set to obtain the second neural network; the second training set comprises image features corresponding to the second object image and membership probability corresponding to the second object image; the classification layer is used for determining the category of an object to be recognized in the image to be recognized according to the magnitude relation among the first probability output by the first neural network, the second probability output by the second neural network and a preset probability value.
In the embodiment of the application, the first neural network and the second neural network which directly identify the image to be identified can be trained through the method, namely the first neural network can directly identify the probability that the object to be identified in the image to be identified is the first object, and the second neural network can directly output the probability that the object to be identified in the image to be identified is the second object. And the classification layer can rapidly and accurately determine the category of the object to be identified (namely, the object to be identified is the solenopsis invicta, or the solenopsis invicta ant nest or other categories) according to the magnitude relation among the first probability, the second probability and the preset probability value, and can realize the identification of a plurality of objects.
With reference to the technical solution provided by the second aspect, in some possible implementation manners, the obtaining a preset number of training patterns includes: acquiring the preset number of collected images, wherein the collected images comprise a first object image and a second object image; sequentially carrying out low-cap transformation and binarization processing on each collected image to obtain the preset number of binarized images; and segmenting each binary image to obtain the training pattern.
In the embodiment of the application, by performing low-hat transformation on the acquired collected images, a dark object can be highlighted from a bright background, that is, a first object or a second object is highlighted from the background of each collected image, so that subsequent acquisition of a training pattern is facilitated. In addition, binarization processing is carried out on the collected image after low-hat transformation is completed, and the image after binarization processing is segmented, so that the training pattern can be quickly and accurately obtained.
With reference to the technical solution provided by the second aspect, in some possible implementations, the performing low-hat transformation on each collected image includes: performing graying processing on each collected image to obtain each collected image after the graying processing; performing expansion processing on each collected image after the graying processing by using a circular template with a preset radius value to obtain each collected image after the expansion processing; performing corrosion treatment on each collected image subjected to the expansion treatment by using a circular template with a preset radius value to obtain each collected image subjected to the corrosion treatment; and subtracting each corresponding collected image from each collected image after the corrosion treatment to obtain an image obtained by performing low-cap transformation on each collected image.
With reference to the technical solution provided by the second aspect, in some possible implementation manners, the performing mean clustering on the training patterns to obtain a class label vector and a membership probability corresponding to each training pattern includes: s401: clustering the training patterns into two classes to obtain a classification label vector corresponding to each training pattern, wherein the two classes are a first object and a second object; s402: solving a preset cost function by adopting a Lagrange multiplier method to obtain an equation of a clustering center point and an equation of a membership probability matrix, wherein the membership probability matrix represents the probability of clustering each training pattern into a corresponding class, and comprises a membership probability corresponding to each training pattern; s403: and updating the initialized membership probability matrix and the clustering center point, calculating an error value according to the updated membership probability matrix value and the updated membership probability matrix value at the last time, and repeating the step S403 until the error value is smaller than a preset error threshold value to obtain the membership probability corresponding to each training pattern.
With reference to the technical solution provided by the second aspect, in some possible implementation manners, the training an initial first neural network by using a first training set to obtain the first neural network includes: s501: inputting the image characteristics determined to correspond to the first object image into the input layer; s502: calculating the output of the hidden layer according to the image characteristics, the connection weights of the input layer and the hidden layer and the threshold value of the hidden layer; s503: calculating the output of the output layer according to the output of the hidden layer, the connection weights of the hidden layer and the output layer and the threshold value of the output layer to obtain the probability value output by the output layer; s504: calculating a loss value according to the probability value and the membership probability corresponding to the first object image, and adjusting each parameter value of the first neural network according to the loss value; repeating the steps S502-S504 until the loss value is in a preset range or meets a preset iteration number, and obtaining final parameter values, wherein the parameter values comprise connection weights of the input layer and the hidden layer, connection weights of the hidden layer and the output layer, a hidden layer threshold value and a threshold value of the output layer.
In combination with the technical solution provided by the second aspect, in some possible implementations, the second neural network includes an input layer, a hidden layer, and an output layer; the training of the initial second neural network by using the second training set to obtain the second neural network comprises the following steps: s601: inputting the image characteristics corresponding to the second object image into the output layer; s602: calculating the output of the hidden layer according to the image characteristics, the connection weights of the input layer and the hidden layer and the threshold value of the hidden layer; s603: calculating the output of the output layer according to the output of the hidden layer, the connection weights of the hidden layer and the output layer and the threshold value of the output layer to obtain the probability value output by the output layer; s604: calculating a loss value according to the probability value and the membership probability corresponding to the second object image, and adjusting each parameter value of the second neural network according to the loss value; repeating the steps S602 to S604 until the loss value is within a preset range or meets a preset iteration number, and obtaining final parameter values, where the parameter values include connection weights of the input layer and the hidden layer, connection weights of the hidden layer and the output layer, a hidden layer threshold, and a threshold of the output layer.
In combination with the technical solution provided by the second aspect, in some possible implementations, the first object is a red imported fire ant, and the second object is a nest of red imported fire ant.
In the embodiment of the application, the first object is set to be the red fire ant, the second object is set to be the nest of the red fire ant, the trained classification model can directly identify the object to be identified in the image to be identified, and therefore the first probability that the object to be identified is the red fire ant and the second probability that the object to be identified is the nest of the red fire ant can be respectively obtained. And the classification layer can quickly determine the category of the object to be identified (namely, the object to be identified is the solenopsis invicta, or the nest of the solenopsis invicta, or other categories) according to the magnitude relation among the first probability, the second probability and the preset probability value, and can realize the identification of a plurality of objects.
With reference to the technical solution provided by the second aspect, in some possible implementation manners, the image features include an area, a perimeter, a length, a width, and an average gray value of an image corresponding to each training pattern.
In a third aspect, an embodiment of the present application provides an image classification apparatus, including: the device comprises a first acquisition module, a second acquisition module and a recognition module, wherein the first acquisition module is used for acquiring an image to be recognized, and the image to be recognized comprises an object to be recognized; the first processing module is used for inputting the image to be recognized into a preset first neural network and acquiring a first probability that the object to be recognized is a solenopsis invicta; inputting the image to be recognized into a preset second neural network, and acquiring a second probability that the object to be recognized is a solenopsis invicta ant nest; the classification module is used for determining the category of the object to be identified according to the magnitude relation among the first probability, the second probability and a preset probability value; the first neural network is obtained by performing mean clustering on a preset number of training patterns to obtain membership probability corresponding to training patterns belonging to the class of the solenopsis invicta and training image features corresponding to the training patterns; the second neural network is obtained by performing mean value clustering on training patterns with preset number to obtain membership probability corresponding to the training patterns belonging to the category of the ant nest of the red fire ants and training image features corresponding to the training patterns.
In a fourth aspect, an embodiment of the present application provides an apparatus for training a classification model, where the classification model includes a first neural network, a second neural network, and a classification layer, the apparatus includes: the second acquisition module is used for acquiring training patterns with preset number and image characteristics corresponding to the training patterns, wherein the training patterns comprise a first object pattern and a second object pattern; the second processing module is used for carrying out mean value clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern; classifying the training patterns according to the classification label vectors to judge the training patterns to be first object patterns or second object patterns; the training module is used for training an initial first neural network by utilizing a first training set to obtain the first neural network; the first training set comprises image features corresponding to the patterns of the solenopsis invicta, and membership probability corresponding to the patterns of the solenopsis invicta; training an initial second neural network by using a second training set to obtain the second neural network; the second training set comprises image features corresponding to the ant nest patterns judged to be the red ants and membership probability corresponding to the ant nest patterns judged to be the red ants; the classification layer is used for determining the category of an object to be recognized in the image to be recognized according to the magnitude relation between the first probability output by the first neural network, the second probability output by the second neural network and a preset probability value.
In a fifth aspect, an embodiment of the present application provides an electronic device, including: a processor and a memory, the processor and the memory connected; the memory is used for storing programs; the processor is configured to invoke a program stored in the memory, to perform a method as provided in the foregoing first aspect embodiment and/or in combination with some possible implementations of the foregoing first aspect embodiment, or to perform a method as provided in the foregoing second aspect embodiment and/or in combination with some possible implementations of the foregoing second aspect embodiment.
In a sixth aspect, embodiments of the present application provide a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, performs the method as provided in the foregoing first aspect embodiment and/or in combination with some possible implementations of the foregoing first aspect embodiment, or performs the method as provided in the foregoing second aspect embodiment and/or in combination with some possible implementations of the foregoing second aspect embodiment.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments of the present application will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and that those skilled in the art can also obtain other related drawings based on the drawings without inventive efforts.
Fig. 1 is a flowchart illustrating steps of a method for training a classification model according to an embodiment of the present disclosure.
Fig. 2 is a schematic diagram of a neural network according to an embodiment of the present disclosure.
Fig. 3 is a flowchart illustrating steps of an image classification method according to an embodiment of the present disclosure.
Fig. 4 is a block diagram of an image classification apparatus according to an embodiment of the present disclosure.
Fig. 5 is a block diagram of a training apparatus for a classification model according to an embodiment of the present disclosure.
Fig. 6 is a block diagram of an electronic device according to an embodiment of the present disclosure.
Detailed Description
The technical solutions in the embodiments of the present application will be described below with reference to the drawings in the embodiments of the present application.
In view of the difficulty in directly identifying the image of the red fire ant and the image of the nest of the red fire ant in the deep learning network in the prior art, the inventors of the present application have conducted research and propose the following embodiments to improve the above problems.
The embodiment of the application provides a training method of a classification model, wherein the classification model comprises a first neural network, a second neural network and a classification layer, the first neural network and the second neural network are respectively used for identifying an image to be identified and respectively obtaining the probability that an object to be identified in the image to be identified is a first object and a second object, and the classification layer is used for determining the category of the object to be identified in the image to be identified according to the magnitude relation among a first probability output by the first neural network, a second probability output by the second neural network and a preset probability value. The following describes specific procedures and steps of a classification model training method with reference to fig. 1.
It should be noted that the training method of the classification model provided in the embodiment of the present application is not limited to the order shown in fig. 1 and the following.
Step S101: the method comprises the steps of obtaining training patterns with preset number and image characteristics corresponding to the training patterns, wherein the training patterns comprise a first object pattern and a second object pattern.
Wherein, the first object and the second object can be two objects with association, such as: red fire ants and their nests, bees and honeycombs, etc.; the first object and the second object may also be two objects without association, such as: elephant and pine tree, flower and house, airplane and water cup, etc., without limitation. The image features may include an area, a perimeter, a length, a width, and an average gray value of the image corresponding to each training pattern.
Specifically, obtaining the training patterns of the preset number may include: acquiring a preset number of collected images, wherein the collected images comprise a first object image and a second object image; sequentially carrying out low-cap transformation and binarization processing on each collected image to obtain a preset number of binarized images; and segmenting each binary image to obtain a training pattern.
Wherein, the preset number can be selected according to the actual situation, such as: the method includes selecting 1000 first object images and 1000 second object images, that is, the sum of the first object images and the second object images is 1000, where the first object images and the second object images may be 500, and the number of the first object images and the number of the second object images may also be set according to actual situations (that is, the number of the first object images and the number of the second object images may not be equal). It should be noted that, the larger the number of the selected first object images and the second object images, the more beneficial the subsequent training of the classification model is, but the calculation amount is also increased correspondingly, so the number of the collected images can be set according to the actual needs. The collected image may be an image subjected to an image normalization process, which may be performed by a technique commonly used in the art.
In addition, the above low-hat transform is the difference between the image after the closing operation and the original image, and the purpose of the low-hat transform is to highlight the dark objects in each collected image from the bright background, and the mathematical expression is as follows:
in the formula (1), the first and second groups,in order to perform the closed operation,as an original figure, the picture is taken as a picture,is a structural element of the compound and is a structural element,the image after the low-hat operation is carried out.
Specifically, the above low-hat transforming each collected image may include: carrying out graying processing on each collected image to obtain each collected image after graying processing; using a circular template with a preset radius value (i.e. the above structural elements) for each collected image after the graying processing) Performing expansion processing to obtain each collected image after the expansion processing; corroding each collected image subjected to the expansion treatment by using a circular template with a preset radius value to obtain each collected image subjected to the corrosion treatment; and subtracting the collected images corresponding to the collected images after the corrosion treatment to obtain images obtained by performing low-hat conversion on the collected images. The closed-loop operation refers to a process of sequentially performing expansion processing and erosion processing for each collected image. In addition, the predetermined radius value is the structural elementIs typically a relatively small value, such as: the predetermined radius value may be 5 pixels.
After the preset number of training patterns and the image features corresponding to the training patterns are obtained, the method may continue to execute step S102.
Step S102: and performing mean clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern.
Specifically, step S102 may specifically include: s401: clustering the training patterns into two classes to obtain a classification label vector corresponding to each training pattern, wherein the two classes are a first object and a second object; s402: solving a preset cost function by adopting a Lagrange multiplier method to obtain an equation of a clustering center point and an equation of a membership probability matrix, wherein the membership probability matrix represents the probability of clustering each training pattern into a corresponding class, and the membership probability matrix comprises the membership probability corresponding to each training pattern; s403: and updating the initialized membership probability matrix and the clustering center point, calculating an error value according to the updated membership probability matrix value and the last updated membership probability matrix value, and repeating the step S403 until the error value is smaller than a preset error threshold value to obtain the membership probability corresponding to each training pattern. And the classification label vector is a class corresponding to the class clustered by the training pattern.
The above process of obtaining the classification label vector and the membership probability is described below with reference to the formulas. After the training patterns are clustered into two classes, a membership probability matrix can be constructed. Wherein the membership probability matrix is initialized randomlyComprises the following steps:
in the formula (2), the first and second groups,,,for the number of training samples that are input,to be a category of the same,as to the total number of categories,。
the cost function is:
in the formula (3), the first and second groups,is shown asThe center point of each cluster (i.e., the classification label vector), and,is a blurring coefficient, and,is the number of training samples input (i.e. theIs that the above-mentioned),Is the number of the centers of the clusters,is shown asThe number of the samples is one,representing a sampleTo the cluster central pointMembership probability (i.e. of)Belong toProbability of (d).A metric representing data similarity (distance), commonly the euclidean norm (i.e., euclidean norm, L2 norm, euclidean distance), is common.
Solving a preset cost function by adopting a Lagrange multiplier methodObtaining a cluster center pointEquation of (2) and membership probability matrixThe equation of (a) is:
it should be noted that, the formula for calculating the error value according to the updated membership probability matrix value and the updated membership probability matrix value at the last time is as follows:
wherein the content of the first and second substances,in order to be able to perform the number of iterations,is a predetermined error threshold value, andis a constant value.
After obtaining the class label vector and membership probability corresponding to each training pattern, the method may continue to step S103.
Step S103: and classifying the training patterns according to the classification label vector to judge that the training patterns are first object patterns or second object patterns.
In step S102, the classification label corresponding to each training pattern is obtained, so that the category of each training pattern can be determined according to the classification label corresponding to each training pattern, that is, the training pattern is determined to be the first object pattern or the second object pattern.
After determining the category to which each training pattern belongs, the method may continue to step S104.
Step S104: and training the initial first neural network by using a first training set to obtain the first neural network.
The first training set comprises image features corresponding to the first object image and membership probability corresponding to the first object image.
Fig. 2 is a schematic diagram of a neural network according to an embodiment of the present application, where circles in the diagram represent nodes,for each of the input data, the data is,for each output data. Specifically, the first neural network includes an input layer, a hidden layer, and an output layer, and step S104 may specifically include: s501: inputting the image characteristics determined to correspond to the first object image into the input layer; s502: calculating the output of the hidden layer according to the image characteristics, the connection weights of the input layer and the hidden layer and the threshold value of the hidden layer; s503: calculating the output of the output layer according to the output of the hidden layer, the connection weights of the hidden layer and the output layer and the threshold value of the output layer to obtain the probability value of the output layer; s504: calculating a loss value according to the probability value and the membership probability corresponding to the first object image, and adjusting each parameter value of the first neural network according to the loss value; and repeating the steps S502-S504 until the loss value is in a preset range or meets the preset iteration times to obtain final parameter values, wherein the parameter values comprise connection weights of the input layer and the hidden layer, connection weights of the hidden layer and the output layer, a hidden layer threshold value and a threshold value of the output layer.
Note that the number of input layer nodes of the first neural network is determined by the dimension of the input feature (i.e., the number of image features). Therefore, when the image features include the area, perimeter, length, width, and mean gray value of the image corresponding to each training pattern, the input layer may include 5 nodes, and the 5 nodes are used to select each feature of the image corresponding to each training pattern.
The number of nodes of the output layer of the first neural network is determined by the number of classes to be distinguished by the first neural network, and since the output layer of the first neural network is used for outputting a probability value, the output layer may include 1 node.
The number of hidden layer nodes of the first neural network can be determined by an empirical formula, which comprises the following specific formula:
wherein the content of the first and second substances,to be hiddenThe number of nodes of the hidden layer,in order to input the number of nodes of the layer,as the number of nodes of the output layer,is a tuning constant between 1 and 10. Therefore, when the number of input layer nodes is 5, and the number of output layer nodes is 1,can be any integer from 3 to 12, such as:it may be 10, i.e. the number of hidden layer nodes is 10.
After the number of nodes of the input layer, the number of nodes of the output layer and the number of nodes of the hidden layer of the first neural network are set, the output of the hidden layer can be calculated, namely, the output of the hidden layer can be calculated according to the image characteristics of the training pattern and the connection weights of the input layer and the hidden layerAnd hidden layer thresholdComputing the output of the hidden layerThe specific calculation formula is as follows:
wherein the content of the first and second substances,,for the hidden activation function, the specific formula is as follows:
output in calculating hidden layerThen according to the output of the hidden layerConnection weights of hidden layer and output layerAnd output layer thresholdCan calculate the output of the output layer(i.e., the probability value of the output layer), it is calculated as follows:
according to the output of the output layerMembership probability corresponding to the first object patternLoss value can be calculatedThe calculation formula is as follows:
according to loss valueThe connection weights of the input layer and the hidden layer of the first neural network can be adjustedAnd each connection weight of the hidden layer and the output layerThe specific adjustment formula is as follows:
according to loss valueHidden layer threshold of first neural network can be adjustedAnd output layer thresholdThe specific adjustment formula is as follows:
and repeating the steps until the loss value is in a preset range or meets the preset iteration times, and obtaining the final parameter values.
Step S105: and training the initial second neural network by using a second training set to obtain a second neural network.
And the second training set comprises image characteristics corresponding to the second object image and membership probability corresponding to the second object image.
Specifically, the second neural network includes an input layer, a hidden layer, and an output layer, and step S105 may specifically include: s601: inputting the image characteristics corresponding to the second object image into the output layer; s602: calculating the output of the hidden layer according to the image characteristics, the connection weights of the input layer and the hidden layer and the threshold value of the hidden layer; s603: calculating the output of the output layer according to the output of the hidden layer, the connection weights of the hidden layer and the output layer and the threshold value of the output layer to obtain the probability value of the output layer; s604: calculating a loss value according to the probability value and the membership probability corresponding to the second object image, and adjusting each parameter value of the second neural network according to the loss value; and repeating the steps S602 to S604 until the loss value is in a preset range or meets a preset iteration number, and obtaining final parameter values, wherein the parameter values comprise connection weights of the input layer and the hidden layer, connection weights of the hidden layer and the output layer, a hidden layer threshold value and a threshold value of the output layer.
It should be noted that, the specific training process and structure of the second neural network may refer to the specific training process and structure of the first neural network in step S104, which is avoided to be described in detail, and therefore, the description is not repeated here.
It should be noted that, after determining the category to which each training pattern belongs, the first neural network and the second neural network may be trained at the same time (i.e., step S104 and step S105 are executed at the same time); or training the first neural network first and then training the second neural network (i.e. performing step S104 and then step S105); the second neural network may be trained first, and then the first neural network is trained (i.e. step S105 is executed first, and then step S104 is executed), which is not limited herein.
In summary, through the steps S101 to S105, a first neural network and a second neural network that directly identify the image to be identified can be trained, that is, the first neural network can directly identify the probability that the object to be identified in the image to be identified is the first object, and the second neural network can directly output the probability that the object to be identified in the image to be identified is the second object. And the classification layer can rapidly and accurately determine the type of the object to be identified according to the magnitude relation among the first probability, the second probability and the preset probability value, and can identify a plurality of objects.
In addition, the first object and the second object can be set as different classes of objects according to actual conditions, so that the training method of the classification model can be applied to various scenes, such as: the method can be applied to scenes of the solenopsis invicta and the solenopsis invicta nest, namely the training patterns are solenopsis invicta patterns and solenopsis invicta nest patterns, and correspondingly, the collected images comprise solenopsis invicta images and solenopsis invicta nest images.
After training the classification model according to the above training method, the classification model can be used to classify images, such as: when the training patterns are the red fire ant patterns and the red fire ant nest patterns, the trained classification model can be used for identifying the object to be identified in the image to be identified, and judging whether the object to be identified is the red fire ant or not, or the red fire ant nest or other categories.
The embodiment of the application also provides an image classification method, which is used for identifying the category of the object to be identified in the image to be identified, namely judging whether the object to be identified is a solenopsis invicta, or a solenopsis invicta nest or other categories. It should be noted that, the image classification method is completed by the above classification model executing corresponding operations. The following describes a specific flow and steps of an image classification method with reference to fig. 3.
It should be noted that the image classification method provided in the embodiment of the present application is not limited to the order shown in fig. 3 and below.
Step S201: and acquiring an image to be recognized, wherein the image to be recognized comprises an object to be recognized.
The image to be recognized is an image subjected to image normalization processing, and the normalization processing can adopt technical means commonly used in the field.
After acquiring the image to be recognized, the method may continue to execute step S202, or step S203, or simultaneously execute step S202 or step S203.
Step S202: and inputting the image to be recognized into a preset first neural network, and acquiring a first probability that the object to be recognized is the solenopsis invicta.
The first neural network is obtained by performing mean clustering on a preset number of training patterns, obtaining membership probability corresponding to the training patterns belonging to the class of the solenopsis invicta, and training image features corresponding to the training patterns. The specific training process corresponding to the first neural network may refer to the foregoing steps S101 to S104, which is omitted for brevity and will not be described here again.
Step S203: and inputting the image to be recognized into a preset second neural network, and acquiring a second probability that the object to be recognized is the solenopsis invicta ant nest.
The second neural network is obtained by performing mean clustering on a preset number of training patterns, obtaining membership probability corresponding to the training patterns belonging to the class of the ant nest of the solenopsis invicta, and training image features corresponding to the training patterns. The specific training process corresponding to the second neural network can refer to the aforementioned steps S101-S103 and S105, which is omitted for brevity and will not be described here again.
It should be noted that, the image to be recognized may be simultaneously input into the preset first neural network and the second neural network, so as to obtain the probabilities that the objects to be recognized are solenopsis invicta and solenopsis invicta nests, respectively (i.e., step S202 and step S203 are performed simultaneously); or inputting the image to be recognized into a preset first neural network, and then inputting the image to be recognized into a preset second neural network (i.e. step S202 is executed first, and step S203 is executed later); the image to be recognized may be input into the preset second neural network first, and then the image to be recognized may be input into the preset first neural network (i.e., step S203 is executed first, and then step S202 is executed), which is not limited herein.
Step S204: and determining the category of the object to be identified according to the magnitude relation among the first probability, the second probability and the preset probability value.
The preset probability value can be selected according to actual conditions, such as: the preset probability value may be 0.5, or 0.6, or 0.7. It should be noted that the greater the preset probability value is set, the higher the accuracy of judging whether the object to be recognized in the image to be recognized is a solenopsis invicta or a solenopsis invicta nest can be improved.
Specifically, if the first probability and the second probability are both greater than a preset probability value and the first probability is greater than the second probability, determining that the object to be identified is a solenopsis invicta; and if the first probability and the second probability are both greater than the preset probability value and the first probability is smaller than the second probability, determining that the object to be identified is the solenopsis invicta ant nest. For example: when the first probability is 0.6, the second probability is 0.7 and the preset probability value is 0.5, the object to be identified in the image to be identified is a red imported fire ant nest; or when the first probability is 0.8, the second probability is 0.7 and the preset probability value is 0.5, the object to be identified in the image to be identified is the solenopsis invicta.
In this embodiment of the application, when both the first probability and the second probability are greater than the preset probability values, it indicates that both the solenopsis invicta image and the solenopsis invicta nest image exist on the image to be recognized, that is, a plurality of objects exist on the image to be recognized. Therefore, the category of the object to be recognized in the image to be recognized can be quickly and accurately determined through the magnitude relation between the first probability and the second probability.
Further, if the first probability is greater than a preset probability value and the second probability is less than the preset probability value, determining that the object to be identified is the first object; and if the first probability is smaller than the preset probability value and the second probability value is larger than the preset probability value, determining that the object to be identified is the second object. For example: when the first probability is 0.6, the second probability is 0.2 and the preset probability value is 0.5, the object to be identified in the image to be identified is a solenopsis invicta; or when the first probability is 0.4, the second probability is 0.7 and the preset probability value is 0.5, the object to be identified in the image to be identified is the ant nest of the solenopsis invicta.
In the embodiment of the application, by the above manner, the category of the image to be recognized can be quickly and accurately judged according to the magnitude relation among the first probability, the second probability and the preset probability value.
Optionally, if the first probability and the second probability are both smaller than the preset probability value, calling a preset identification model to identify the image to be identified, and acquiring the category of the object to be identified.
The recognition model may be an existing recognition model, for example: resnet50_ vd _ animals. Where resnet50_ vd _ animals is a recognition model well known to those skilled in the art and will not be described here. When the image to be recognized is recognized by using the resnet50_ vd _ animals, the object to be recognized in the image to be recognized can be recognized as the corresponding other animal class or non-animal class. It should be noted that other recognition models can be selected according to actual situations, and are not limited herein.
In the embodiment of the application, when the first probability and the second probability are smaller than the preset probability values, the preset recognition model can be called to further recognize the image to be recognized, so that when the possibility that the object to be recognized in the image to be recognized is a solenopsis invicta or a solenopsis invicta nest is low, the category of the image to be recognized is determined again through the recognition model.
Referring to fig. 4, based on the same inventive concept, an embodiment of the present application further provides an image classification apparatus, where the apparatus 100 includes: a first acquisition module 101, a first processing module 102 and a classification module 103.
The first obtaining module 101 is configured to obtain an image to be recognized, where the image to be recognized includes an object to be recognized.
The first processing module 102 is configured to input an image to be recognized into a preset first neural network, and obtain a first probability that an object to be recognized is a solenopsis invicta; and inputting the image to be recognized into a preset second neural network, and acquiring a second probability that the object to be recognized is the solenopsis invicta ant nest.
The classification module 103 is configured to determine a category of the object to be identified according to a size relationship between the first probability, the second probability and a preset probability value; the first neural network is obtained by performing mean clustering on a preset number of training patterns to obtain membership probability corresponding to training patterns belonging to the class of the solenopsis invicta and training image features corresponding to the training patterns; the second neural network is obtained by performing mean value clustering on training patterns with preset number to obtain membership probability corresponding to the training patterns belonging to the category of the ant nest of the red fire ants and training image features corresponding to the training patterns.
Optionally, the classification module 103 is specifically configured to determine that the object to be identified is a solenopsis invicta if the first probability and the second probability are both greater than a preset probability value, and the first probability is greater than the second probability; and if the first probability and the second probability are both greater than the preset probability value and the first probability is smaller than the second probability, determining that the object to be identified is the solenopsis invicta ant nest.
Optionally, the classification module 103 is further configured to, if both the first probability and the second probability are smaller than a preset probability value, call a preset recognition model to recognize the image to be recognized, and acquire the category of the object to be recognized.
Optionally, the image classification device 100 further includes a construction module 104, where the construction module 104 is configured to obtain training patterns of a preset number and image features corresponding to the training patterns, where the training patterns include solenopsis invicta patterns and solenopsis invicta nest patterns; carrying out mean value clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern; classifying the training patterns according to the classification label vectors to judge whether the training patterns are solenopsis invicta patterns or solenopsis invicta nest patterns; training an initial first neural network by using a first training set to obtain a first neural network; the first training set comprises image features corresponding to the patterns of the solenopsis invicta, and membership probability corresponding to the patterns of the solenopsis invicta.
Optionally, the constructing module 104 is further configured to train the initial second neural network by using a second training set, so as to obtain a second neural network; and the second training set comprises image characteristics corresponding to the ant nest patterns judged to be the red ants and membership probability corresponding to the ant nest patterns judged to be the red ants.
Optionally, the construction module 104 is specifically configured to obtain a preset number of collected images, where the collected images include solenopsis invicta images and solenopsis invicta nest images; sequentially carrying out low-cap transformation and binarization processing on each collected image to obtain a preset number of binarized images; and segmenting each binary image to obtain a training pattern.
Optionally, the building block 104 is specifically configured to, in S301: clustering the training patterns into two classes to obtain a classification label vector corresponding to each training pattern, wherein the two classes are solenopsis invicta and solenopsis invicta ant nests; s302: solving a preset cost function by adopting a Lagrange multiplier method to obtain an equation of a clustering center point and an equation of a membership probability matrix, wherein the membership probability matrix represents the probability of clustering each training pattern into a corresponding class, and the membership probability matrix comprises the membership probability corresponding to each training pattern; s303: and updating the initialized membership probability matrix and the clustering center point, calculating an error value according to the updated membership probability matrix value and the last updated membership probability matrix value, and repeating the step S303 until the error value is smaller than a preset error threshold value to obtain the membership probability corresponding to each training pattern.
Referring to fig. 5, based on the same inventive concept, an embodiment of the present application further provides an apparatus 200 for training a classification model, where the apparatus 200 includes: a second acquisition module 201, a second processing module 202 and a training module 203.
The second obtaining module 201 is configured to obtain a preset number of training patterns and image features corresponding to the training patterns, where the training patterns include a first object pattern and a second object pattern.
The second processing module 202 is configured to perform mean clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern; classifying the training patterns according to the classification label vectors to judge the training patterns to be first object patterns or second object patterns;
a training module 203, configured to train an initial first neural network by using a first training set to obtain a first neural network; the first training set comprises image features corresponding to the first object image and membership probability corresponding to the first object image; training the initial second neural network by using a second training set to obtain a second neural network; the second training set comprises image features corresponding to the second object image and membership probability corresponding to the second object image; the classification layer is used for determining the category of the object to be recognized in the image to be recognized according to the magnitude relation between the first probability output by the first neural network, the second probability output by the second neural network and the preset probability value.
Optionally, the second obtaining module 201 is specifically configured to obtain a preset number of collected images, where the collected images include a first object image and a second object image; sequentially carrying out low-cap transformation and binarization processing on each collected image to obtain a preset number of binarized images; and segmenting each binary image to obtain a training pattern.
Optionally, the second obtaining module 201 is specifically configured to perform graying processing on each collected image to obtain each collected image after the graying processing; performing expansion processing on each collected image after the graying processing by using a circular template with a preset radius value to obtain each collected image after the expansion processing; corroding each collected image subjected to the expansion treatment by using a circular template with a preset radius value to obtain each collected image subjected to the corrosion treatment; and subtracting the collected images corresponding to the collected images after the corrosion treatment to obtain images obtained by performing low-hat conversion on the collected images.
Optionally, the second processing module 202 is configured to, in S401: clustering the training patterns into two classes to obtain a classification label vector corresponding to each training pattern, wherein the two classes are a first object and a second object; s402: solving a preset cost function by adopting a Lagrange multiplier method to obtain an equation of a clustering center point and an equation of a membership probability matrix, wherein the membership probability matrix represents the probability of clustering each training pattern into a corresponding class, and the membership probability matrix comprises the membership probability corresponding to each training pattern; s403: and updating the initialized membership probability matrix and the clustering center point, calculating an error value according to the updated membership probability matrix value and the last updated membership probability matrix value, and repeating the step S403 until the error value is smaller than a preset error threshold value to obtain the membership probability corresponding to each training pattern.
Optionally, the first neural network includes an input layer, a hidden layer, and an output layer, and the training module 203 is specifically configured to, in S501: inputting the image characteristics determined to correspond to the first object image into the input layer; s502: calculating the output of the hidden layer according to the image characteristics, the connection weights of the input layer and the hidden layer and the threshold value of the hidden layer; s503: calculating the output of the output layer according to the output of the hidden layer, the connection weights of the hidden layer and the output layer and the threshold value of the output layer to obtain the probability value of the output layer; s504: calculating a loss value according to the probability value and the membership probability corresponding to the first object image, and adjusting each parameter value of the first neural network according to the loss value; and repeating the steps S502-S504 until the loss value is in a preset range or meets the preset iteration times to obtain final parameter values, wherein the parameter values comprise connection weights of the input layer and the hidden layer, connection weights of the hidden layer and the output layer, a hidden layer threshold value and a threshold value of the output layer.
Optionally, the second neural network includes an input layer, a hidden layer, and an output layer, and the training module 203 is specifically configured to, in S601: inputting the image characteristics corresponding to the second object image into the output layer; s602: calculating the output of the hidden layer according to the image characteristics, the connection weights of the input layer and the hidden layer and the threshold value of the hidden layer; s603: calculating the output of the output layer according to the output of the hidden layer, the connection weights of the hidden layer and the output layer and the threshold value of the output layer to obtain the probability value of the output layer; s604: calculating a loss value according to the probability value and the membership probability corresponding to the second object image, and adjusting each parameter value of the second neural network according to the loss value; and repeating the steps S602 to S604 until the loss value is in a preset range or meets a preset iteration number, and obtaining final parameter values, wherein the parameter values comprise connection weights of the input layer and the hidden layer, connection weights of the hidden layer and the output layer, a hidden layer threshold value and a threshold value of the output layer.
Referring to fig. 6, based on the same inventive concept, an exemplary block diagram of an electronic device 300 according to an embodiment of the present application is provided, where the electronic device 300 can be used to implement the image classification method or the classification model training method. In the embodiment of the present application, the electronic Device 300 may be, but is not limited to, a Personal Computer (PC), a smart phone, a tablet PC, a Personal Digital Assistant (PDA), a Mobile Internet Device (MID), and the like. Structurally, electronic device 300 may include a processor 310 and a memory 320.
The processor 310 and the memory 320 are electrically connected, directly or indirectly, to enable data transmission or interaction, for example, the components may be electrically connected to each other via one or more communication buses or signal lines. The processor 310 may be an integrated circuit chip having signal processing capabilities. The Processor 310 may also be a general-purpose Processor, for example, a Central Processing Unit (CPU), a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a discrete gate or transistor logic device, or a discrete hardware component, which can implement or execute the methods, steps, and logic blocks disclosed in the embodiments of the present Application. Further, a general purpose processor may be a microprocessor or any conventional processor or the like.
The Memory 320 may be, but is not limited to, a Random Access Memory (RAM), a Read Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (EPROM), and an electrically Erasable Programmable Read-Only Memory (EEPROM). The memory 320 is used for storing a program, and the processor 310 executes the program after receiving an execution instruction.
It should be understood that the structure shown in fig. 6 is merely an illustration, and the electronic device 300 provided in the embodiments of the present application may have fewer or more components than those shown in fig. 6, or may have a different configuration than that shown in fig. 6. Further, the components shown in fig. 6 may be implemented by software, hardware, or a combination thereof.
It should be noted that, as those skilled in the art can clearly understand, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
Based on the same inventive concept, embodiments of the present application further provide a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed, the computer program performs the methods provided in the above embodiments.
The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that includes one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
In addition, units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
Furthermore, the functional modules in the embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
In this document, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions.
The above description is only an example of the present application and is not intended to limit the scope of the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims (20)
1. A method of image classification, the method comprising:
acquiring an image to be recognized, wherein the image to be recognized comprises an object to be recognized;
inputting the image to be recognized into a preset first neural network, and acquiring a first probability that the object to be recognized is a solenopsis invicta;
inputting the image to be recognized into a preset second neural network, and acquiring a second probability that the object to be recognized is a solenopsis invicta ant nest;
determining the category of the object to be identified according to the magnitude relation among the first probability, the second probability and a preset probability value;
the first neural network is obtained by performing mean clustering on a preset number of training patterns to obtain membership probability corresponding to training patterns belonging to the class of the solenopsis invicta and training image features corresponding to the training patterns; the second neural network is obtained by performing mean value clustering on training patterns with preset number to obtain membership probability corresponding to the training patterns belonging to the category of the ant nest of the red fire ants and training image features corresponding to the training patterns.
2. The method according to claim 1, wherein the determining the category of the object to be identified according to the magnitude relation among the first probability, the second probability and a preset probability value comprises:
if the first probability and the second probability are both greater than the preset probability value and the first probability is greater than the second probability, determining that the object to be identified is the solenopsis invicta;
and if the first probability and the second probability are both greater than the preset probability value and the first probability is smaller than the second probability, determining that the object to be identified is the solenopsis invicta ant nest.
3. The method of claim 1, further comprising:
if the first probability and the second probability are both smaller than the preset probability value, calling a preset recognition model to recognize the image to be recognized, and acquiring the category of the object to be recognized.
4. The method of claim 1, further comprising:
acquiring training patterns with the preset number and image characteristics corresponding to the training patterns, wherein the training patterns comprise solenopsis invicta patterns and solenopsis invicta nest patterns;
performing mean clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern;
classifying the training patterns according to the classification label vectors to judge whether the training patterns are solenopsis invicta patterns or solenopsis invicta nest patterns;
training an initial first neural network by using a first training set to obtain the first neural network; the first training set comprises image features corresponding to the determined solenopsis invicta patterns and membership probability corresponding to the determined solenopsis invicta patterns.
5. The method of claim 4, further comprising:
training an initial second neural network by using a second training set to obtain the second neural network; and the second training set comprises image characteristics corresponding to the ant nest patterns judged to be the red ants and membership probability corresponding to the ant nest patterns judged to be the red ants.
6. The method of claim 4, wherein the obtaining the preset number of training patterns comprises:
acquiring the collection images with the preset number, wherein the collection images comprise solenopsis invicta images and solenopsis invicta nest images;
sequentially carrying out low-cap transformation and binarization processing on each collected image to obtain the preset number of binarized images;
and segmenting each binary image to obtain the training pattern.
7. The method of claim 4, wherein the performing mean clustering on the training patterns to obtain class label vectors and membership probabilities corresponding to each of the training patterns comprises:
s301: clustering the training patterns into two classes to obtain a classification label vector corresponding to each training pattern, wherein the two classes are the solenopsis invicta and the solenopsis invicta nest;
s302: solving a preset cost function by adopting a Lagrange multiplier method to obtain an equation of a clustering center point and an equation of a membership probability matrix, wherein the membership probability matrix represents the probability of clustering each training pattern into a corresponding class, and comprises a membership probability corresponding to each training pattern;
s303: and updating the initialized membership probability matrix and the clustering center point, calculating an error value according to the updated membership probability matrix value and the updated membership probability matrix value at the last time, and repeating the step S303 until the error value is smaller than a preset error threshold value to obtain the membership probability corresponding to each training pattern.
8. The method of any of claims 1-7, wherein the image features include an area, a perimeter, a length, a width, and an average grayscale value for each of the training patterns corresponding to an image.
9. A method for training a classification model, wherein the classification model comprises a first neural network, a second neural network and a classification layer, the method comprising:
acquiring training patterns with a preset number and image characteristics corresponding to the training patterns, wherein the training patterns comprise a first object pattern and a second object pattern;
performing mean clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern;
classifying the training patterns according to the classification label vectors to judge the training patterns to be first object patterns or second object patterns;
training an initial first neural network by using a first training set to obtain the first neural network; the first training set comprises image features corresponding to the first object image and membership probability corresponding to the first object image;
training an initial second neural network by using a second training set to obtain the second neural network; the second training set comprises image features corresponding to the second object image and membership probability corresponding to the second object image;
the classification layer is used for determining the category of an object to be recognized in the image to be recognized according to the magnitude relation among the first probability output by the first neural network, the second probability output by the second neural network and a preset probability value.
10. The method of claim 9, wherein the obtaining a predetermined number of training patterns comprises:
acquiring the preset number of collected images, wherein the collected images comprise a first object image and a second object image;
sequentially carrying out low-cap transformation and binarization processing on each collected image to obtain the preset number of binarized images;
and segmenting each binary image to obtain the training pattern.
11. The method of claim 10, wherein said low-hat transforming each of said collected images comprises:
performing graying processing on each collected image to obtain each collected image after the graying processing;
performing expansion processing on each collected image after the graying processing by using a circular template with a preset radius value to obtain each collected image after the expansion processing;
performing corrosion treatment on each collected image subjected to the expansion treatment by using a circular template with a preset radius value to obtain each collected image subjected to the corrosion treatment;
and subtracting each corresponding collected image from each collected image after the corrosion treatment to obtain an image obtained by performing low-cap transformation on each collected image.
12. The method of claim 9, wherein the performing mean clustering on the training patterns to obtain class label vectors and membership probabilities corresponding to each of the training patterns comprises:
s401: clustering the training patterns into two classes to obtain a classification label vector corresponding to each training pattern, wherein the two classes are a first object and a second object;
s402: solving a preset cost function by adopting a Lagrange multiplier method to obtain an equation of a clustering center point and an equation of a membership probability matrix, wherein the membership probability matrix represents the probability of clustering each training pattern into a corresponding class, and comprises a membership probability corresponding to each training pattern;
s403: and updating the initialized membership probability matrix and the clustering center point, calculating an error value according to the updated membership probability matrix value and the updated membership probability matrix value at the last time, and repeating the step S403 until the error value is smaller than a preset error threshold value to obtain the membership probability corresponding to each training pattern.
13. The method of claim 9, wherein the first neural network comprises an input layer, a hidden layer, and an output layer, and wherein training an initial first neural network with a first training set to obtain the first neural network comprises:
s501: inputting the image characteristics determined to correspond to the first object image into the input layer;
s502: calculating the output of the hidden layer according to the image characteristics, the connection weights of the input layer and the hidden layer and the threshold value of the hidden layer;
s503: calculating the output of the output layer according to the output of the hidden layer, the connection weights of the hidden layer and the output layer and the threshold value of the output layer to obtain the probability value output by the output layer;
s504: calculating a loss value according to the probability value and the membership probability corresponding to the first object image, and adjusting each parameter value of the first neural network according to the loss value; repeating the steps S502-S504 until the loss value is in a preset range or meets a preset iteration number, and obtaining final parameter values, wherein the parameter values comprise connection weights of the input layer and the hidden layer, connection weights of the hidden layer and the output layer, a hidden layer threshold value and a threshold value of the output layer.
14. The method of claim 9, wherein the second neural network comprises an input layer, a hidden layer, and an output layer; the training of the initial second neural network by using the second training set to obtain the second neural network comprises the following steps:
s601: inputting the image characteristics corresponding to the second object image into the output layer;
s602: calculating the output of the hidden layer according to the image characteristics, the connection weights of the input layer and the hidden layer and the threshold value of the hidden layer;
s603: calculating the output of the output layer according to the output of the hidden layer, the connection weights of the hidden layer and the output layer and the threshold value of the output layer to obtain the probability value output by the output layer;
s604: calculating a loss value according to the probability value and the membership probability corresponding to the second object image, and adjusting each parameter value of the second neural network according to the loss value; repeating the steps S602 to S604 until the loss value is within a preset range or meets a preset iteration number, and obtaining final parameter values, where the parameter values include connection weights of the input layer and the hidden layer, connection weights of the hidden layer and the output layer, a hidden layer threshold, and a threshold of the output layer.
15. The method of any one of claims 9-14, wherein the first subject is a red fire ant and the second subject is a nest of red fire ant ants.
16. The method of any of claims 9-14, wherein the image features include an area, a perimeter, a length, a width, and an average grayscale value for each of the training patterns corresponding to an image.
17. An image classification apparatus, characterized in that the apparatus comprises:
the device comprises a first acquisition module, a second acquisition module and a recognition module, wherein the first acquisition module is used for acquiring an image to be recognized, and the image to be recognized comprises an object to be recognized;
the first processing module is used for inputting the image to be recognized into a preset first neural network and acquiring a first probability that the object to be recognized is a solenopsis invicta; inputting the image to be recognized into a preset second neural network, and acquiring a second probability that the object to be recognized is a solenopsis invicta ant nest;
the classification module is used for determining the category of the object to be identified according to the magnitude relation among the first probability, the second probability and a preset probability value; the first neural network is obtained by performing mean clustering on a preset number of training patterns to obtain membership probability corresponding to training patterns belonging to the class of the solenopsis invicta and training image features corresponding to the training patterns; the second neural network is obtained by performing mean value clustering on training patterns with preset number to obtain membership probability corresponding to the training patterns belonging to the category of the ant nest of the red fire ants and training image features corresponding to the training patterns.
18. An apparatus for training a classification model, wherein the classification model includes a first neural network, a second neural network, and a classification layer, the apparatus comprising:
the second acquisition module is used for acquiring training patterns with preset number and image characteristics corresponding to the training patterns, wherein the training patterns comprise a first object pattern and a second object pattern;
the second processing module is used for carrying out mean value clustering on the training patterns to obtain a classification label vector and a membership probability corresponding to each training pattern; classifying the training patterns according to the classification label vectors to judge the training patterns to be first object patterns or second object patterns;
the training module is used for training an initial first neural network by utilizing a first training set to obtain the first neural network; the first training set comprises image features corresponding to the patterns of the solenopsis invicta, and membership probability corresponding to the patterns of the solenopsis invicta; training an initial second neural network by using a second training set to obtain the second neural network; the second training set comprises image features corresponding to the ant nest patterns judged to be the red ants and membership probability corresponding to the ant nest patterns judged to be the red ants; the classification layer is used for determining the category of an object to be recognized in the image to be recognized according to the magnitude relation between the first probability output by the first neural network, the second probability output by the second neural network and a preset probability value.
19. An electronic device, comprising: a processor and a memory, the processor and the memory connected;
the memory is used for storing programs;
the processor is configured to run a program stored in the memory, to perform a method according to any of claims 1-8, or to perform a method according to any of claims 9-16.
20. A computer-readable storage medium, having stored thereon a computer program which, when executed by a computer, performs the method of any of claims 1-8 or the method of any of claims 9-16.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210164297.XA CN114219051B (en) | 2022-02-23 | 2022-02-23 | Image classification method, classification model training method and device and electronic equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210164297.XA CN114219051B (en) | 2022-02-23 | 2022-02-23 | Image classification method, classification model training method and device and electronic equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN114219051A true CN114219051A (en) | 2022-03-22 |
CN114219051B CN114219051B (en) | 2022-05-06 |
Family
ID=80709252
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210164297.XA Active CN114219051B (en) | 2022-02-23 | 2022-02-23 | Image classification method, classification model training method and device and electronic equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114219051B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP7384506B1 (en) | 2023-02-14 | 2023-11-21 | ファームコネクト カンパニー リミテッド | Insect individual identification device using learning |
Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103530620A (en) * | 2013-10-30 | 2014-01-22 | 华北电力大学 | Method for identifying bird nest on electric transmission line tower |
CN106250835A (en) * | 2016-07-26 | 2016-12-21 | 国网福建省电力有限公司 | Bird's Nest recognition methods on the transmission line of electricity of feature based identification |
CN107886127A (en) * | 2017-11-10 | 2018-04-06 | 深圳市唯特视科技有限公司 | A kind of histopathology image classification method based on convolutional neural networks |
CN107945162A (en) * | 2017-11-23 | 2018-04-20 | 华南农业大学 | Detection recognition method based on computer vision technique to flourishing ant nest |
CN110082135A (en) * | 2019-03-14 | 2019-08-02 | 中科恒运股份有限公司 | Equipment fault recognition methods, device and terminal device |
CN110188801A (en) * | 2019-05-10 | 2019-08-30 | 深圳灵图慧视科技有限公司 | Image-recognizing method, device, electronic equipment and storage medium |
CN112215845A (en) * | 2020-12-03 | 2021-01-12 | 虎丘影像(苏州)有限公司 | Medical image information identification method, device and system based on multi-neural network |
CN112508034A (en) * | 2020-11-03 | 2021-03-16 | 精英数智科技股份有限公司 | Freight train fault detection method and device and electronic equipment |
CN113536000A (en) * | 2021-07-14 | 2021-10-22 | 西安工程大学 | Mask RCNN-based power transmission iron tower bird-involved fault state identification and evaluation method |
CN113569769A (en) * | 2021-07-30 | 2021-10-29 | 仲恺农业工程学院 | Red fire ant nest remote identification and positioning method based on deep neural network |
CN114022713A (en) * | 2021-11-10 | 2022-02-08 | 重庆紫光华山智安科技有限公司 | Model training method, system, device and medium |
-
2022
- 2022-02-23 CN CN202210164297.XA patent/CN114219051B/en active Active
Patent Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103530620A (en) * | 2013-10-30 | 2014-01-22 | 华北电力大学 | Method for identifying bird nest on electric transmission line tower |
CN106250835A (en) * | 2016-07-26 | 2016-12-21 | 国网福建省电力有限公司 | Bird's Nest recognition methods on the transmission line of electricity of feature based identification |
CN107886127A (en) * | 2017-11-10 | 2018-04-06 | 深圳市唯特视科技有限公司 | A kind of histopathology image classification method based on convolutional neural networks |
CN107945162A (en) * | 2017-11-23 | 2018-04-20 | 华南农业大学 | Detection recognition method based on computer vision technique to flourishing ant nest |
CN110082135A (en) * | 2019-03-14 | 2019-08-02 | 中科恒运股份有限公司 | Equipment fault recognition methods, device and terminal device |
CN110188801A (en) * | 2019-05-10 | 2019-08-30 | 深圳灵图慧视科技有限公司 | Image-recognizing method, device, electronic equipment and storage medium |
CN112508034A (en) * | 2020-11-03 | 2021-03-16 | 精英数智科技股份有限公司 | Freight train fault detection method and device and electronic equipment |
CN112215845A (en) * | 2020-12-03 | 2021-01-12 | 虎丘影像(苏州)有限公司 | Medical image information identification method, device and system based on multi-neural network |
CN113536000A (en) * | 2021-07-14 | 2021-10-22 | 西安工程大学 | Mask RCNN-based power transmission iron tower bird-involved fault state identification and evaluation method |
CN113569769A (en) * | 2021-07-30 | 2021-10-29 | 仲恺农业工程学院 | Red fire ant nest remote identification and positioning method based on deep neural network |
CN114022713A (en) * | 2021-11-10 | 2022-02-08 | 重庆紫光华山智安科技有限公司 | Model training method, system, device and medium |
Non-Patent Citations (4)
Title |
---|
KAMLESH BORANA 等: "Bird Species Identifier using Convolutional Neural Network", 《INTERNATIONAL JOURNAL OF ENGINEERING RESEARCH & TECHNOLOGY (IJERT)》 * |
W. B. WU 等: "DETECTION OF SOLENOPSIS INVICTA(HYMENOPTERA: FORMICIDAE) NESTS USING SPECTRAL DATA", 《FLORIDA ENTOMOLOGIST》 * |
吴伟斌 等: "基于计算机视觉技术的红火蚁蚁巢探测", 《河南农业大学学报》 * |
邱志斌 等: "基于目标检测的电网涉鸟故障相关鸟种智能识别", 《电网技术》 * |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP7384506B1 (en) | 2023-02-14 | 2023-11-21 | ファームコネクト カンパニー リミテッド | Insect individual identification device using learning |
Also Published As
Publication number | Publication date |
---|---|
CN114219051B (en) | 2022-05-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111523621B (en) | Image recognition method and device, computer equipment and storage medium | |
WO2020098606A1 (en) | Node classification method, model training method, device, apparatus, and storage medium | |
CN110874550A (en) | Data processing method, device, equipment and system | |
CN110672323B (en) | Bearing health state assessment method and device based on neural network | |
CN111738351A (en) | Model training method and device, storage medium and electronic equipment | |
CN110929785B (en) | Data classification method, device, terminal equipment and readable storage medium | |
CN112163637B (en) | Image classification model training method and device based on unbalanced data | |
CN111368911B (en) | Image classification method and device and computer readable storage medium | |
CN111178364A (en) | Image identification method and device | |
CN114219051B (en) | Image classification method, classification model training method and device and electronic equipment | |
CN114358249A (en) | Target recognition model training method, target recognition method and device | |
CN111652320B (en) | Sample classification method and device, electronic equipment and storage medium | |
CN116206208B (en) | Forestry plant diseases and insect pests rapid analysis system based on artificial intelligence | |
CN111352926A (en) | Data processing method, device, equipment and readable storage medium | |
CN109934352B (en) | Automatic evolution method of intelligent model | |
CN112115996B (en) | Image data processing method, device, equipment and storage medium | |
CN113449712B (en) | Goat face identification method based on improved Alexnet network | |
CN113537339B (en) | Method and system for identifying symbiotic or associated minerals based on multi-label image classification | |
CN114492657A (en) | Plant disease classification method and device, electronic equipment and storage medium | |
CN111523598A (en) | Image recognition method based on neural network and visual analysis | |
CN113326805B (en) | Human body cover updating method and device, electronic equipment and storage medium | |
CN115514621B (en) | Fault monitoring method, electronic device and storage medium | |
CN111625672B (en) | Image processing method, image processing device, computer equipment and storage medium | |
CN116757338B (en) | Crop yield prediction method, device, electronic equipment and storage medium | |
CN117155706B (en) | Network abnormal behavior detection method and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |