A poultry chicken breed identification method and device
By applying the object detection model and classification model in chicken breed recognition, combining convolutional neural network and residual network, and using the self-attention mechanism to classify breeds, the problem of low accuracy and automation of chicken breed classification in the existing technology is solved, and more efficient and accurate chicken breed recognition is achieved.
Patent Information
- Application Number
- CN202311664099.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-06
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2043-12-06
AI Technical Summary
It is difficult to accurately classify chicken breeds in the prior art, especially due to the complexity of chicken breeds and interference with background information, resulting in low degree of automation and low classification efficiency.
The method based on the object detection model and classification model is adopted to identify the position of the chicken through prediction labeling boxes, and feature information is extracted using convolutional neural networks and residual networks, and breed classification is performed in combination with the self-attention mechanism.
It improves the accuracy and automation of chicken breed identification, reduces manual participation, and enhances the generalization ability and classification efficiency of the model.
Smart Images

Figure CN117593764B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image recognition, and in particular to a poultry chicken breed classification method and device. Background Art
[0002] Chicken is one of the most common poultry in the world and is widely raised to provide meat and egg products. In the agriculture and food industry, chicken and eggs are one of the main sources of protein. There are many types of chickens, each with unique characteristics and uses. Therefore, chicken breed identification is of great significance to the agriculture and food industry. At present, most of the classification of chicken breeds and genders is done by manual detection, which requires huge labor and time costs and is easily affected by subjective judgment and human errors.
[0003] The methods of automatic processing of computer images mainly include the following:
[0004] 1. The method based on threshold segmentation, which divides the pixels in the image into two or more different categories according to their grayscale values or color values by setting one or more thresholds. It has the problems of low recall rate, poor noise resistance, and high requirements for image quality.
[0005] Second, the edge detection method, which is generally based on detection algorithms such as Sobel, Canny and Prewitt, focuses on detecting edges and contours in the image to segment different objects. However, it is difficult to detect edges for images with complex backgrounds and is easily affected by noise interference.
[0006] 3. Region growing-based method: This method is an image segmentation method based on similarity properties. It takes seed pixels as the starting point and gradually merges similar pixels to form connected regions until there are no more pixels to be merged, thus achieving image region segmentation. This method requires manually giving a seed point to each region to be extracted in advance and is sensitive to noise data.
[0007] Fourth, methods based on artificial intelligence such as deep learning. After building a network model, this method can automatically extract features from images through large-scale data training, thereby achieving more accurate image processing, and can be applied to tasks such as image classification, object detection and segmentation. However, it requires a large amount of data and computing resources, and the model is a black box and difficult to explain.
[0008] Currently, there are few classification methods directly applied to chicken breeds, and chicken breeds are complex. Individuals of different breeds or different genders of the same breed have high similarity, and existing detection methods are difficult to accurately classify targets. The content of the captured pictures is complex and there is interference from background information. In addition, the existing methods have a low degree of automation, poor scalability, and low classification efficiency. Summary of the invention
[0009] In view of the defects in the prior art, the present invention provides a poultry chicken breed identification method to solve the problem that the current chicken breeds are complex and it is difficult to accurately classify targets based on existing detection methods.
[0010] In a first aspect, the present invention provides a poultry chicken breed identification method, comprising:
[0011] Get poultry chicken images;
[0012] Based on the pre-built target detection model, the position information of the chicken in the image is identified and annotated through the predicted annotation box to obtain the target detection image;
[0013] Based on a pre-trained classification model, the target detection image is classified by species; the classification model is based on a convolutional neural network, and a residual network is added to extract feature information, and the feature information is used for species classification after being adjusted by a self-attention mechanism.
[0014] It can be seen from the above technical scheme that a poultry chicken breed identification method provided by the present invention can first identify the position of the chicken based on the target detection model, and mark the chicken with a labeling box, which can reduce interference and improve processing accuracy; at the same time, the present invention integrates the attention mechanism into the residual network model to extract image depth information, and the human participation is low.
[0015] Optionally, the training method of the target detection model includes:
[0016] Acquire a real processed image; the real processed image is an image pre-processed to form a real annotation frame;
[0017] Inputting the real processed image into the target detection model to obtain a predicted annotation box;
[0018] Comparing the real annotation box with the predicted annotation box, and calculating the total loss of the predicted annotation box;
[0019] The total loss is back-propagated to update the model parameters, and the target detection model is obtained by iterative training.
[0020] Optionally, it also includes: the total loss of the predicted annotation box Calculated according to the following formula:
[0021] ,
[0022] in, is the classification loss, is the confidence loss, For the positioning loss, , , are the weights of the three losses respectively;
[0023] The classification loss and classification loss The following formula is used for calculation:
[0024] ,
[0025] Where y=0 or 1 indicates whether the predicted annotation box is marked with a chicken, and p indicates the probability that the predicted annotation box is marked with a chicken;
[0026] ,
[0027] in To predict the consistency parameter representation of the aspect ratio of the annotation box, is a weight parameter, which indicates the proportion of the aspect ratio of the predicted annotation box in the loss; is the center point of the real rectangular frame, To predict the center point of the rectangular box, is the Euclidean distance between the center point of the real rectangular box and the predicted rectangular box, It is the diagonal distance between the minimum enclosed area of the real rectangular box and the predicted rectangular box;
[0028] ,
[0029] in, and Refers to the area of the real rectangular box and the predicted rectangular box. Represents the intersection area of the real rectangular box and the predicted rectangular box, Represents the union area of the real rectangular box and the predicted rectangular box;
[0030] ,
[0031] ,
[0032] in , is the width and height of the real rectangular box, , To predict the width and height of the rectangular box.
[0033] Optionally, classifying the target detection image by species based on the pre-trained classification model includes:
[0034] Extract feature information based on residual blocks;
[0035] The feature information is concatenated to form an overall input vector , get the overall input vector The self-attention mechanism output vector ;
[0036] Based on the output vector A class score is calculated for each class and converted into a probability distribution for each class.
[0037] Optionally, the probability distribution calculation formula for each category is:
[0038]
[0039] in, Representative The category scores of the categories, represents the natural exponential operation on the category scores, Represents the output after normalization The probability distribution of the categories, This represents a total of K categories in this classification task. Represents the sum of the natural index results for the overall category scores.
[0040] Optionally, the training method of the classification model includes:
[0041] Inputting the sample image into the classification model to obtain the model classification result;
[0042] Calculate the classification loss value of the model classification result and the real classification based on the classification loss function;
[0043] The classification model is obtained by back-propagating the classification loss value to update the model parameters and iteratively training.
[0044] Optionally, the classification loss function
[0045] ,
[0046] in, is the number of sample images, is the number of categories, Represents a sample image Belongs to category Tags, Represents a sample image Belongs to category probability.
[0047] Optionally, before the target detection image is input into the classification model, data enhancement processing is further performed, including:
[0048] Rotation: According to random rotation angle Perform an affine transformation on the pixel position.
[0049]
[0050]
[0051] in and Respectively represent the pixel coordinates before and after the formula transformation, In the predetermined parameters within the scope;
[0052] Flip: According to the predetermined flip probability parameters , flip the image horizontally;
[0053] Color regularization: adjusting the color channels of the target detection image;
[0054] Random cropping: according to the predetermined cropping image size And the area ratio of the cropping area , crop the target detection image and scale it to a specified size.
[0055] Optionally, it also includes:
[0056] The target detection image is visualized to obtain a related heat map, which is used to determine the poultry characteristics associated with the classified species; the heat map is determined by gradient information.
[0057] In a second aspect, the present invention provides a poultry chicken breed identification device, comprising:
[0058] An image acquisition module, used for acquiring poultry chicken images;
[0059] The target detection module is used to identify the location information of the chicken in the image based on the pre-trained target detection model and annotate it through the predicted annotation box to obtain the target detection image;
[0060] A classification module is used to classify the target detection image into species based on a pre-trained classification model; the classification model is based on a convolutional neural network and a residual network is added to extract feature information, and the feature information is used for species classification after being adjusted by a self-attention mechanism.
[0061] Optionally, a target detection model training module is also included, which is specifically used to:
[0062] Acquire a real processed image; the real processed image is an image pre-processed to form a real annotation frame;
[0063] Inputting the real processed image into the target detection model to obtain a predicted annotation box;
[0064] Comparing the real annotation box with the predicted annotation box, and calculating the total loss of the predicted annotation box;
[0065] The total loss is back-propagated to update the model parameters, and the target detection model is obtained by iterative training.
[0066] Optionally, the target detection model training module is further used to calculate the total loss of the predicted annotation box according to the following formula: :
[0067] ,
[0068] in, is the classification loss, is the confidence loss, For the positioning loss, , , are the weights of the three losses respectively;
[0069] The classification loss and classification loss The following formula is used for calculation:
[0070] ,
[0071] Where y=0 or 1 indicates whether the predicted annotation box is marked with a chicken, and p indicates the probability that the predicted annotation box is marked with a chicken;
[0072] ,
[0073] in To predict the consistency parameter representation of the aspect ratio of the annotation box, is a weight parameter, which indicates the proportion of the aspect ratio of the predicted annotation box in the loss; is the center point of the real rectangular frame, To predict the center point of the rectangular box, is the Euclidean distance between the center point of the real rectangular box and the predicted rectangular box, It is the diagonal distance between the minimum enclosed area of the real rectangular box and the predicted rectangular box;
[0074] ,
[0075] in, and Refers to the area of the real rectangular box and the predicted rectangular box. Represents the intersection area of the real rectangular box and the predicted rectangular box, Represents the union area of the real rectangular box and the predicted rectangular box;
[0076] ,
[0077] ,
[0078] in , is the width and height of the real rectangular box, , To predict the width and height of the rectangular box.
[0079] Optionally, the classification module is specifically used to:
[0080] Extract feature information based on residual blocks;
[0081] The feature information is concatenated to form an overall input vector , get the overall input vector The self-attention mechanism output vector ;
[0082] Based on the output vector A class score is calculated for each class and converted into a probability distribution for each class.
[0083] Optionally, in the classification module, the probability distribution calculation formula for each category is:
[0084]
[0085] in, Representative The category scores of the categories, represents the natural exponential operation on the category scores, Represents the output after normalization The probability distribution of the categories, This represents a total of K categories in this classification task. Represents the sum of the natural index results for the overall category scores.
[0086] Optionally, a classification model training module is also included, which is specifically used to:
[0087] Inputting the sample image into the classification model to obtain the model classification result;
[0088] Calculate the classification loss value of the model classification result and the real classification based on the classification loss function;
[0089] The classification model is obtained by back-propagating the classification loss value to update the model parameters and iteratively training.
[0090] Optionally, in the classification module, the classification loss function
[0091] ,
[0092] in, is the number of sample images, is the number of categories, Represents a sample image Belongs to category Tags, Represents a sample image Belongs to category probability.
[0093] Optionally, a data enhancement processing module is also included, which is specifically used to:
[0094] Rotation: According to random rotation angle Perform an affine transformation on the pixel position.
[0095]
[0096]
[0097] in and Respectively represent the pixel coordinates before and after the formula transformation, In the predetermined parameters within the scope;
[0098] Flip: According to the predetermined flip probability parameters , flip the image horizontally;
[0099] Color regularization: adjusting the color channels of the target detection image;
[0100] Random cropping: according to the predetermined cropping image size And the area ratio of the cropping area , crop the target detection image and scale it to a specified size.
[0101] Optionally, the classification module is further used to:
[0102] The target detection image is visualized to obtain a related heat map, which is used to determine the poultry characteristics associated with the classified species; the heat map is determined by gradient information.
[0103] In a third aspect, an embodiment of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of any of the above methods when executing the computer program.
[0104] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium having computer program instructions stored thereon, which implement the steps of any of the above methods when executed by a processor.
[0105] By adopting the above technical solution, the present application has the following beneficial effects:
[0106] The present invention can identify the position of the chicken based on the target detection model, and mark the chicken through the predicted annotation box, which can reduce interference and improve processing accuracy. At the same time, the present invention integrates the attention mechanism into the residual network model to extract image depth information, and the human involvement is low.
[0107] The target detection model of the present invention compares the real annotation box with the predicted annotation box during training. The loss of the predicted annotation box reflects the gap between the predicted position and the real position. The model parameters are updated through the back-propagation process and iterative training is performed to continuously improve the model performance, so that the predicted position gradually approaches the position of the real annotation box.
[0108] The classification model of the present invention extracts model features based on residual blocks and fuses the features through a self-attention mechanism, so that the obtained classification model is more flexible and has stronger generalization ability. BRIEF DESCRIPTION OF THE DRAWINGS
[0109] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the following is a brief introduction to the drawings required for the specific embodiments or the description of the prior art. In all the drawings, similar elements or parts are generally identified by similar reference numerals. In the drawings, the elements or parts are not necessarily drawn according to the actual scale.
[0110] Figure 1 A flow chart of a poultry chicken breed identification method provided by an embodiment of the present invention is shown;
[0111] Figure 2 A schematic diagram of a poultry chicken image provided by an embodiment of the present invention is shown;
[0112] Figure 3 A schematic diagram of a target detection image provided by an embodiment of the present invention is shown;
[0113] Figure 4 A flow chart of a method for training a target detection model provided by an embodiment of the present invention is shown;
[0114] Figure 5 A schematic diagram of the structure of a target detection model provided by an embodiment of the present invention is shown;
[0115] Figure 6 One of the structural schematic diagrams of the classification model provided by the embodiment of the present invention is shown;
[0116] Figure 7 The second structural diagram of the classification model provided by the embodiment of the present invention is shown;
[0117] Figure 8A schematic diagram of an association heat map provided by an embodiment of the present invention is shown;
[0118] Fig. 9 A structural block diagram of a poultry chicken breed identification device provided by an embodiment of the present invention is shown;
[0119] Fig.10 A structural block diagram of an electronic device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0120] The following embodiments of the technical solution of the present invention are described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and are therefore only used as examples, and cannot be used to limit the protection scope of the present invention.
[0121] It should be noted that, unless otherwise specified, the technical terms or scientific terms used in this application should have the common meanings understood by those skilled in the art to which the present invention belongs.
[0122] like Figure 1 As shown, this embodiment provides a poultry chicken breed identification method, comprising:
[0123] S101. Acquire poultry chicken images.
[0124] This embodiment requires collecting images of male and female individuals of various chicken breeds. In order to ensure the accuracy of target detection, it is necessary to avoid strong light exposure in the image shooting environment to cause bright spots, thereby affecting the target detection effect; secondly, ensure that the data set contains representative samples of various chicken breeds and different angles, which will help improve the generalization of the trained model; in addition, images of more chicken breeds should be collected as much as possible to further improve the model recognition effect.
[0125] Specifically, this embodiment collected 10 common chicken breeds, including 20 male and female breeds, and captured a total of 7966 valid images. The sample distribution is shown in Table 1. The sample images are shown in Table 1. Figure 2 shown.
[0126] Table 1
[0127]
[0128] After the image acquisition is completed, the collected images are preprocessed to eliminate images that do not meet the requirements, such as blurred images, severe exposure, etc., to ensure data quality. Then the data is denoised to improve the clarity of the image, and then all images are standardized to 2160*3840 to facilitate subsequent unified processing. In addition, in order to meet the needs of the subsequent target detection process, the position labels of the chickens in the image are annotated manually or automatically, and the outlines of the chickens are annotated using real annotation boxes.
[0129] In this embodiment, the LabelImg software package is used to label the image. Automatic labeling generally has errors, and the best method is to use manual labeling methods to produce high-quality label files.
[0130] The label format of the generated annotation file is:
[0131]
[0132] in, is the label number, the default is 0, is the coordinate of the target center position, is the width of the target rectangle. The height of the target rectangle.
[0133] Compared with automatic labeling, manual labeling can greatly improve the accuracy of the model. Therefore, this embodiment adopts a random sampling method to sample and label the data set. A total of 400 pictures of chickens of different breeds are labeled, and the data set is divided into 7:2:1, that is, 280 pictures are used as training sets, 80 pictures are used as validation sets, and 40 pictures are used as test sets.
[0134] S102. Figure 3 As shown, based on the pre-built target detection model, the position information of the chicken in the image is identified and annotated through the predicted annotation box to obtain the target detection image.
[0135] The target detection model used in this step is Figure 4 As shown, the training method includes:
[0136] S201. Obtain a real processed image. The real processed image is the image of the training set in step S101, which is an image that has been pre-annotated with the chicken outline by a real annotation box.
[0137] S202. Input the real processed image into the target detection model to obtain the predicted annotation box. The predicted annotation box is the output of the target detection model.
[0138] S203. Compare the real annotation box and the predicted annotation box, and calculate the total loss of the predicted annotation box.
[0139] S204. Update the model parameters based on the total loss back propagation, and iteratively train to obtain the target detection model.
[0140] The real annotation box is compared with the predicted annotation box. The loss of the predicted annotation box reflects the gap between the predicted position and the real position. The model parameters are updated through the back-propagation process and iterative training is performed to continuously improve the model performance, so that the predicted position is gradually close to the position of the real standard box.
[0141] Among them, the total loss of predicting the annotation box Calculated according to the following formula:
[0142] ,
[0143] in, is the classification loss, is the confidence loss, For the positioning loss, , , are the weights of the three losses respectively;
[0144] The classification loss and classification loss The following formula is used for calculation:
[0145] ,
[0146] Where y=0 or 1 indicates whether the predicted annotation box is marked with a chicken, and p indicates the probability that the predicted annotation box is marked with a chicken;
[0147] ,
[0148] in To predict the consistency parameter representation of the aspect ratio of the annotation box, is a weight parameter, which indicates the proportion of the aspect ratio of the predicted annotation box in the loss; is the center point of the real rectangular frame, To predict the center point of the rectangular box, is the Euclidean distance between the center point of the real rectangular box and the predicted rectangular box, It is the diagonal distance between the minimum enclosed area of the real rectangular box and the predicted rectangular box;
[0149] ,
[0150] in, and Refers to the area of the real rectangular box and the predicted rectangular box. Represents the intersection area of the real rectangular box and the predicted rectangular box, Represents the union area of the real rectangular box and the predicted rectangular box;
[0151] ,
[0152] ,
[0153] in , is the width and height of the real rectangular box, , To predict the width and height of the rectangular box.
[0154] The target detection model structure of this embodiment is shown in the attached figure. Figure 5 As shown, the model parameters Number of training rounds, The batch size for training, Training image size, parameter settings are as follows:
[0155] ,
[0156] Confidence threshold needs to be set when model inference and coverage threshold , where the confidence threshold is the confidence loss in the model loss function The weight of the confidence threshold is , a higher confidence threshold will filter more detection boxes, and only the detection boxes with higher confidence probability will be retained; the coverage threshold is the intersection loss in the model loss The lower the coverage, the lower the tolerance for overlap between detection frames. When the coverage threshold is 0, there will be no overlapping detection frames. The parameters in this embodiment are set as follows:
[0157] ,
[0158] The final model achieved 100% accuracy and recall on the validation set, and mAP reached 0.998, which can accurately detect and frame the location of the chicken in the image. The detection results of some test set models are as follows: Figure 3 shown.
[0159] S103. Based on the pre-trained classification model, the target detection image is classified by species; the classification model is based on a convolutional neural network, and a residual network is added to extract feature information, and the feature information is used for species classification after being adjusted by a self-attention mechanism.
[0160] Wherein, step S103 specifically includes:
[0161] S301. Extract feature information based on the residual block.
[0162] First, for the input target detection image, the residual network is introduced as a feature extractor, so that the model can extract relevant information from the image and perform subsequent operations better. In this process, the feature extraction process is realized through multiple convolutional layers and convolutional blocks. Each convolutional block gradually extracts and enriches the feature information of the image through a series of convolution operations, activation functions and residual connections. The basic unit of a convolutional block mainly consists of three parts: convolutional layer, batch normalization and activation operation.
[0163] The convolution layer uses filters to multiply the input target detection image element by element and adds the results to generate the output feature map. The overall calculation formula of the convolution layer is as follows:
[0164] ,
[0165] in, and Represent the values of the corresponding positions of input and output respectively, is the weight parameter of the convolution operation, that is, the filter, The bias term is used to adjust the output of the convolution operation. The image features at different positions are deeply extracted and summarized by performing a dot multiplication calculation between the input target detection image and the filter.
[0166] After that, the output of the convolutional layer is normalized through the batch normalization process, and the calculation formula is:
[0167] ,
[0168] in, and Represent the input and output of batch normalization, respectively. and Represent the mean and variance of the batch normalized input in the current channel, and is a small positive number to prevent division by zero and stabilize the calculation. In addition, batch normalization also includes learnable scaling and bias parameters, as follows:
[0169] ,
[0170] in, and These are the parameters learned and updated during the training process, with initial values of 1 and 0. This is the result of batch normalization.
[0171] Finally, ReLU is used as the activation function for the next step to introduce nonlinear transformation in the calculation process. The calculation formula is:
[0172] ,
[0173] in, is the output result of the above formula, is the output result of this process. When this process is executed, all negative input values become zero, and positive values remain unchanged.
[0174] The above three parts constitute the main structure of the convolution block. In order to build a deeper network structure, extract deeper image features, and avoid the gradient vanishing problem, the concept of residual connection is introduced on the basis of the convolution block and appropriate network structure modifications are made to make it the basic module of the residual network, namely the residual block.
[0175] The main convolution layer is based on the convolution block, which is also the part that needs to be trained in the layer-by-layer network. It includes two convolution operations, that is, adding a convolution layer and a normalization layer on the basis of the original convolution block.
[0176] The calculation formula for the first convolution process is
[0177] ,
[0178] It can be seen that it is a combination of the three calculation processes in the above convolutional block for learning feature representation, where Conv() represents the above convolutional layer, BN() represents the above batch normalization, and ReLU() represents the calculation using the ReLU function. In addition, is the output of the current convolution block and serves as the input of the next convolution operation. Refers to the image features that are input to the convolutional block.
[0179] The second convolution process is used to further process the features and output them. The calculation formula is:
[0180]
[0181] in, It is the final output of the entire convolutional layer and an important part of the output content of the residual block.
[0182] In addition, another core content of the residual block is the jump connection, which is to connect the input of the residual block The output of the main convolutional layer Directly add as the output of this part , the calculation formula is
[0183]
[0184] in is the output of the convolutional layer branch, and is the original input of the residual block, That is, the sum of the two, and then the ReLU activation function is used to get the final output, so that the network can better learn and represent complex features.
[0185] This structure of the residual block makes it easy to stack multiple residual blocks to build deep neural networks without worrying about the gradient vanishing problem. Gradients can be quickly propagated through skip connections without being diluted by the nonlinear operations of deep convolutional layers.
[0186] The residual blocks are stacked according to the network depth requirements, and different residual block groups are constructed to represent different stages of the network structure. In this way, the network can gradually extract and abstract the features of the image from low-level to high-level. Each stage can learn different levels of features, from local features to global features, giving the network a more powerful representation capability.
[0187] S302. Concatenate feature information to form an overall input vector , get the overall input vector The self-attention mechanism output vector .
[0188] Since extracting image information in convolutional neural networks only extracts image features in sequence by region, and cannot take into account the global image structure and the correlation between pixel information, the method introduces a self-attention mechanism to build the target detection model to adjust the feature sequence extracted by the front-end convolutional network. This mechanism gives the network a more powerful feature representation capability, allowing the network to better understand the internal correlation and global structure of the image.
[0189] The core idea of the self-attention mechanism is to use the query matrix , key matrix and the numerical matrix To construct an attention score matrix, we dynamically weight features based on the importance of specific positions.
[0190] First, for the image feature information extracted by the convolutional neural network, the features of all convolution blocks are concatenated into an overall input vector , and then we get , and , the calculation formula is
[0191]
[0192]
[0193]
[0194] in, , and are the parameters to be learned during training, and , and Each column in the matrix corresponds to an original input vector fed into the self-attention mechanism.
[0195] Then, the correlation between each two input vectors is calculated using the above formula, and the calculation results form the attention score matrix, which is calculated as follows:
[0196] ,
[0197] ,
[0198] in, represent The transposed matrix of and The correlation matrix between vectors is obtained by multiplying each column vector of the matrix. , Representatives The value at position (i,j) of the matrix is subjected to natural exponential operation. Represents the attention score matrix obtained in this process, It represents the sum of the values after the natural exponential operation of the data in the j-th column, so as to obtain the row-based normalized weight, thereby ensuring that the sum of the weights of each position in the row is 1.
[0199] Finally, the attention score matrix With numerical matrices The dot multiplication results in the final output matrix, which is calculated as follows:
[0200] ,
[0201] in, That is the resulting output matrix, in which each column vector corresponds one-to-one to the input vector.
[0202] By introducing the self-attention mechanism, we not only simply stack residual blocks to extract features, but also dynamically adjust the weights of features in specific areas, making the network more flexible and intelligent in capturing the internal correlation of the image, thereby improving the performance and generalization ability of the network.
[0203] S303. Based on output vector Calculate the class score for each class and convert the class scores into a probability distribution for each class.
[0204] Since the method provided in this embodiment needs to solve a classification task, a fully connected layer is added after the output of the residual block, and the category score is obtained after this layer. In order to convert the category score into the probability distribution of each category, the output of the fully connected layer is processed using a softmax activation function, and its calculation formula is as follows:
[0205] ,
[0206] in, Representative The category scores of the categories, represents the natural exponential operation on the category scores, Represents the output after normalization The probability distribution of the categories, This represents a total of K categories in this classification task. Represents the sum of the natural index results for the overall category scores.
[0207] The architecture of the classification model provided in this embodiment is as follows: Figure 6 and Figure 7 shown.
[0208] For the classification model of this embodiment, the training method includes:
[0209] S401. Input the sample image into the classification model to obtain the model classification result.
[0210] S402. Calculate the classification loss value between the model classification result and the actual classification based on the classification loss function.
[0211] The classification loss value of this step is based on the classification loss function Calculate the classification loss value by
[0212] ,
[0213] in, is the number of sample images, is the number of categories, Represents a sample image Belongs to category Tags, Represents a sample image Belongs to category probability.
[0214] S403. Back-propagate based on the classification loss value to update the model parameters, and iteratively train to obtain the classification model.
[0215] Use the calculation results of the above classification loss function and back propagate to calculate the gradient, then select the Adam optimizer to update the model parameters according to the gradient, repeat the above process continuously, update the iterative network parameters, and finally the network gradually converges to the optimal performance.
[0216] When training a classification model, the training process parameters is the training image size, is the training round, is the batch size for training, is the type of optimizer used in the training process, To control the number of rounds required for early stopping, Represents the type of loss function used during training. In this embodiment, the parameters are set as follows:
[0217]
[0218]
[0219] in, Refers to the cross entropy loss function, such as the classification loss function , the classification loss is calculated in each round according to the calculation formula of the classification loss, so that it tends to be minimized during the continuous training process, and the iteration is continuously repeated until the model gradually converges during the gradient descent process, and the performance and classification accuracy are gradually improved to obtain the final classification model.
[0220] In this embodiment, in order to improve the performance of the classification model, before the target detection image used to train the classification model is input into the classification model, it is also necessary to perform data enhancement processing on the image.
[0221] After the target detection is completed, the target detection image is immediately subjected to data enhancement processing to improve the diversity of the image, thereby improving the generalization of the final classification model. This allows the model to better adapt to different data changes and noise, making the training data more diverse, which helps to improve the robustness of the model and reduce the risk of overfitting, thereby improving the performance of the model. In this process, four data enhancement methods are mainly used: rotation, flipping, color regularization, and random cropping, including:
[0222] (1) Rotation: according to random rotation angle Perform an affine transformation on the pixel position.
[0223]
[0224]
[0225] in and Respectively represent the pixel coordinates before and after the formula transformation, In the predetermined parameters within the scope;
[0226] (2) Flip: According to the predetermined flip probability parameter , flip the image horizontally; this helps the model learn different directions of symmetrical objects while increasing data diversity.
[0227] (3) Color regularization: Adjust the color channels of the target detection image, such as brightness, saturation, and contrast, to change the color characteristics of the image. Use color balancing, brightness enhancement, and other techniques to make the model more generalizable to images under different lighting and color conditions, and reduce the impact of color differences on model performance.
[0228] (4) Random cropping: according to the predetermined cropped image size And the area ratio of the cropping area , crop the target detection image and scale it to the specified size. This helps the model learn the characteristics of the target at different positions and sizes, and provides the model with training data for pose uncertainty.
[0229] Among them, the rotation process The parameter limits the range of image rotation. This limits the probability of horizontal flipping of the image, and is the size of the image after cropping. Specify the relative size range of the cropping area. The two values in the tuple represent the ratio of the minimum size to the maximum size. The specific parameter settings are as follows:
[0230] ,
[0231] By processing the target detection images in this method through the above four data enhancement methods, the performance of the model is improved when facing images of different angles, different colors, etc. The above four data enhancement methods can be performed in a random order.
[0232] The poultry chicken breed identification method of this embodiment also includes: visualizing the target detection image to obtain a related heat map to determine the poultry features associated with the classified breed.
[0233] In order to more intuitively understand which features affect poultry classification, the breed identification method of this embodiment uses gradient weighted class activation mapping technology to explain the prediction process of the network model, and visualizes the image area that the classification model focuses on, to help the model evaluation process. During the model prediction process, the gradient information related to the target category predicted by the model is calculated. This gradient information represents the sensitivity of the model to the target category score, and can track the contribution of each pixel in the image to this category. Then, based on this gradient information, a heat map is generated, in which each pixel is assigned a weight, reflecting its importance to the model classification decision.
[0234] By observing the heat map of the model prediction process, such as Figure 8As shown, it can be seen that the classification model focuses on the head, feet and wings for the characteristics of this variety, which is consistent with the parts that manual classification focuses on. It can be seen that the classification basis of the model trained by this method is more reasonable, and its classification accuracy and recall rate exceed the existing methods, which meets the production needs.
[0235] In one embodiment, Fig. 9 As shown, a poultry chicken breed identification device 50 is provided, comprising:
[0236] An image acquisition module 501 is used to acquire poultry chicken images;
[0237] The target detection module 502 is used to identify the position information of the chicken in the image and annotate it through the predicted annotation box based on the pre-trained target detection model to obtain a target detection image;
[0238] The classification module 503 is used to classify the target detection image into species based on a pre-trained classification model; the classification model is based on a convolutional neural network, and a residual network is added to extract feature information, and the feature information is used for species classification after being adjusted by a self-attention mechanism.
[0239] The poultry chicken breed identification device 50 provided in the embodiment of the present application adopts the same inventive concept as the above-mentioned poultry chicken breed identification method and can achieve the same beneficial effects, which will not be repeated here.
[0240] Optionally, a target detection model training module is also included, which is specifically used to:
[0241] Acquire a real processed image; the real processed image is an image pre-processed to form a real annotation frame;
[0242] Input the real processed image into the target detection model to obtain the predicted annotation box;
[0243] Compare the real annotation box and the predicted annotation box, and calculate the total loss of the predicted annotation box;
[0244] The total loss is back-propagated to update the model parameters, and the target detection model is obtained through iterative training.
[0245] Optionally, the target detection model training module is further used to calculate the total loss of the predicted annotation box according to the following formula: :
[0246] ,
[0247] in, is the classification loss, is the confidence loss, For the positioning loss, , , are the weights of the three losses respectively;
[0248] The classification loss and classification loss The following formula is used for calculation:
[0249] ,
[0250] Where y=0 or 1 indicates whether the predicted annotation box is marked with a chicken, and p indicates the probability that the predicted annotation box is marked with a chicken;
[0251] ,
[0252] in To predict the consistency parameter representation of the aspect ratio of the annotation box, is a weight parameter, which indicates the proportion of the aspect ratio of the predicted annotation box in the loss; is the center point of the real rectangular frame, To predict the center point of the rectangular box, is the Euclidean distance between the center point of the real rectangular box and the predicted rectangular box, It is the diagonal distance between the minimum enclosed area of the real rectangular box and the predicted rectangular box;
[0253] ,
[0254] in, and Refers to the area of the real rectangular box and the predicted rectangular box. Represents the intersection area of the real rectangular box and the predicted rectangular box, Represents the union area of the real rectangular box and the predicted rectangular box;
[0255] ,
[0256] ,
[0257] in , is the width and height of the real rectangular box, , To predict the width and height of the rectangular box.
[0258] Optionally, the classification module is specifically used to:
[0259] Extract feature information based on residual blocks;
[0260] Concatenate feature information to form the overall input vector , get the overall input vector The self-attention mechanism output vector ;
[0261] Based on the output vector Calculate the class score for each class and convert the class scores into a probability distribution for each class.
[0262] Optionally, in the classification module, the probability distribution calculation formula for each category is
[0263]
[0264] in, Representative The category scores of the categories, represents the natural exponential operation on the category scores, Represents the output after normalization The probability distribution of the categories, This represents a total of K categories in this classification task. Represents the sum of the natural index results for the overall category scores.
[0265] Optionally, a classification model training module is also included, which is specifically used to:
[0266] Input the sample image into the classification model to obtain the model classification result;
[0267] Calculate the classification loss value between the model classification result and the actual classification based on the classification loss function;
[0268] The classification loss value is back-propagated to update the model parameters, and the classification model is obtained through iterative training.
[0269] Optionally, in the classification module, the classification loss function
[0270] ,
[0271] in, is the number of sample images, is the number of categories, Represents a sample image Belongs to category Tags, Represents a sample image Belongs to category probability.
[0272] Optionally, a data enhancement processing module is also included, which is specifically used to:
[0273] Rotation: According to random rotation angle Perform an affine transformation on the pixel position.
[0274]
[0275]
[0276] in and Respectively represent the pixel coordinates before and after the formula transformation, In the predetermined parameters within the scope;
[0277] Flip: According to the predetermined flip probability parameters , flip the image horizontally;
[0278] Color regularization: adjust the color channels of the target detection image;
[0279] Random cropping: according to the predetermined cropping image size And the area ratio of the cropping area , crop the target detection image and scale it to the specified size.
[0280] Optionally, the classification module is further configured to:
[0281] The target detection image is visualized to obtain a related heat map, which is used to determine the poultry characteristics associated with the classified species; the heat map is determined by gradient information.
[0282] Based on the same inventive concept as the above poultry chicken breed identification method, the embodiment of the present application also provides an electronic device 60, such as Fig.10 As shown, the electronic device 60 may include a processor 601 and a memory 602 .
[0283] The processor 601 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, and may implement or execute the methods, steps and logic block diagrams disclosed in the embodiments of the present invention. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present invention may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0284] The memory 602 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, etc. The memory is any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 602 in the embodiment of the present invention can also be a circuit or any other device that can realize a storage function, and is used to store program instructions and / or data.
[0285] An embodiment of the present invention provides a computer-readable storage medium for storing computer program instructions used by the above-mentioned electronic device, which includes a program for executing the above-mentioned page broadcast control method.
[0286] The above-mentioned computer storage media can be any available media or data storage devices that can be accessed by a computer, including but not limited to magnetic storage (such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), etc.), optical storage (such as CD, DVD, BD, HVD, etc.), and semiconductor storage (such as ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)), etc.
[0287] The above embodiments are only used to introduce the technical solutions of the present application in detail, but the description of the above embodiments is only used to help understand the methods of the embodiments of the present invention and should not be understood as limiting the embodiments of the present invention. Any changes or substitutions that can be easily thought of by technicians in this technical field should be included in the protection scope of the embodiments of the present invention.
Claims
1. A poultry chicken breed identification method, characterized in that: include: Get poultry chicken images; Based on the pre-trained target detection model, the position information of the chicken in the image is identified and annotated through the predicted annotation box to obtain the target detection image. The predicted annotation box is the output box of the target detection model. Based on a pre-trained classification model, the target detection image is classified into varieties; the classification model is based on a convolutional neural network and a residual network is added to extract feature information, and the feature information is used for variety classification after being adjusted by a self-attention mechanism; The classifying the target detection image based on the pre-trained classification model includes: Extract feature information based on residual blocks; The feature information is concatenated to form an overall input vector , get the overall input vector The self-attention mechanism output vector ; ,in That is the resulting output matrix, is a numerical matrix, are the parameters learned during training, is the attention score matrix, where each column vector is the same as the input vector One to one correspondence; Based on the output vector Calculate the category score of each category and convert the category score into the probability distribution of each category; add a fully connected layer after the output of the residual block, and get the category score after this layer. The probability distribution calculation formula for each category is: , in, Representative The category scores of the categories, represents the natural exponential operation on the category scores, Represents the output after normalization The probability distribution of the categories, This represents a total of K categories in this classification task. Represents the sum of the Nature Index results for the overall category score; also includes: The target detection image is visualized to obtain a related heat map, which is used to determine the poultry characteristics associated with the classified species; the heat map is determined by gradient information.
2. The method according to claim 1, characterized in that The training method of the target detection model includes: Acquire a real processed image; the real processed image is an image pre-processed to form a real annotation frame; Inputting the real processed image into the target detection model to obtain a predicted annotation box; Comparing the real annotation box with the predicted annotation box, and calculating the total loss of the predicted annotation box; The total loss is back-propagated to update the model parameters, and the target detection model is obtained by iterative training.
3. The method according to claim 2, characterized in that Also includes: The total loss of the predicted annotation box Calculated according to the following formula: , in, is the classification loss, is the confidence loss, is the positioning loss, , , are the weights of the three losses respectively; The classification loss and confidence loss The following formula is used for calculation: , Where y=0 or 1 indicates whether the predicted annotation box is marked with a chicken, and p indicates the probability that the predicted annotation box is marked with a chicken; , in To predict the consistency parameter representation of the aspect ratio of the annotation box, is a weight parameter, which indicates the proportion of the aspect ratio of the predicted annotation box in the loss; is the center point of the real rectangular frame, To predict the center point of the rectangular box, is the Euclidean distance between the center point of the real rectangular box and the predicted rectangular box, It is the diagonal distance between the minimum enclosed area of the real rectangular box and the predicted rectangular box; , in, and Refers to the area of the real rectangular box and the predicted rectangular box. Represents the intersection area of the real rectangular box and the predicted rectangular box, Represents the union area of the real rectangular box and the predicted rectangular box; , , in , is the width and height of the real rectangular box, , To predict the width and height of the rectangular box.
4. The method according to claim 1, characterized in that: The training method of the classification model comprises: Inputting the sample image into the classification model to obtain the model classification result; Calculate the classification loss value of the model classification result and the real classification based on the classification loss function; The classification model is obtained by back-propagating the classification loss value to update the model parameters and iteratively training.
5. The method according to claim 4, characterized in that The classification loss function , in, is the number of sample images, is the number of categories, Represents a sample image Belongs to category Tags, Represents a sample image Belongs to category probability.
6. The method according to claim 1, characterized in that Before the target detection image is input into the classification model, data enhancement processing is also performed, including: Rotation: According to random rotation angle Perform an affine transformation on the pixel position. , , in and Respectively represent the pixel coordinates before and after the formula transformation, In the predetermined parameters within the scope; Flip: According to the predetermined flip probability parameters , flip the image horizontally; Color regularization: adjusting the color channel of the target detection image; Random cropping: according to the predetermined cropping image size And the area ratio of the cropping area , crop the target detection image and scale it to a specified size.
7. A poultry chicken breed identification device, characterized in that: include: An image acquisition module, used for acquiring poultry chicken images; The target detection module is used to identify the location information of the chicken in the image based on the pre-trained target detection model and annotate it through the predicted annotation box to obtain the target detection image. The predicted annotation box is the output box of the target detection model; A classification module, for classifying the target detection image into species based on a pre-trained classification model; the classification model is based on a convolutional neural network and adds a residual network to extract feature information, and the feature information is used for species classification after being adjusted by a self-attention mechanism; The classification module is specifically used for: Extract feature information based on residual blocks; The feature information is concatenated to form an overall input vector , get the overall input vector The self-attention mechanism output vector ; ,in That is the resulting output matrix, is a numerical matrix, are the parameters learned during training, is the attention score matrix, where each column vector is the same as the input vector One to one correspondence; Based on the output vector Calculate the category score of each category and convert the category score into the probability distribution of each category; add a fully connected layer after the output of the residual block, and get the category score after this layer. The probability distribution calculation formula for each category is: , in, Representative The category scores of the categories, represents the natural exponential operation on the category scores, Represents the output after normalization The probability distribution of the categories, This represents a total of K categories in this classification task. represents the sum of the natural index results for the overall category scores; The classification module is further specifically used for: The target detection image is visualized to obtain a related heat map, which is used to determine the poultry characteristics associated with the classified species; the heat map is determined by gradient information.
Citation Information
Patent Citations
Image classification method and device, electronic equipment and storage medium
CN114120034A
Lightweight YOLO pet identification method based on GhostNet
CN115049966A
Embryo development stage prediction and quality evaluation system based on rotation equivariant network
CN116883996A
Stacked object recognition method and apparatus, electronic device and storage medium
WO2021061045A2