Pig body posture recognition method based on deep learning, electronic equipment and readable storage medium

Through the deep learning-based pig body pose recognition method, the improved SegFormer model and correlation coefficient calculation technology are used to solve the problems of complex, time-consuming and low accuracy of existing pig body pose recognition algorithms, and high accuracy and low complexity are achieved pose recognition effect.

CN119418369APending Publication Date: 2025-02-11CHONGQING NORMAL UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411501444.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-25
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

The existing pig body posture recognition algorithm has problems such as complex and time-consuming detection of key points, high cost of 3D pose recognition, high data demand, and complex processing. The two-dimensional camera cannot give the distance of the pig or provide the three-dimensional structure of the object, resulting in accurate identification. The rate is reduced.

Method used

Using the pig body pose recognition method based on deep learning, the pig body image set is acquired and preprocessed, and an improved SegFormer model is constructed for image segmentation, the correlation coefficient between pixel data and pose label is calculated, and the pixel data with the highest correlation is selected as pose recognition. Data is input to the pose recognition model for training to achieve pose recognition.

Benefits of technology

It reduces the complexity of data, improves the accuracy of posture recognition, reduces labor costs, and provides auxiliary information for pig health judgment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119418369A_ABST
    Figure CN119418369A_ABST
Patent Text Reader

Abstract

The invention provides a pig body posture recognition method based on deep learning. The pig body posture recognition method comprises the following steps: S1, acquiring a sample data set; s2, determining a trained image segmentation model; s3, inputting the sample data set into the trained image segmentation model to obtain mask images of different parts of the pig body; s4, determining a pixel data set according to the mask graph; s5, determining n types of pixel data as posture recognition data; s6, determining a trained posture recognition model; s7, mask patterns of different parts of the pig body with the posture to be recognized are obtained; s8, determining the posture of the pig body according to the posture label; through the method, data parameters can be reduced, the attitude recognition cost is reduced, and the attitude recognition accuracy is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to image recognition, and in particular to a pig posture recognition method based on deep learning, an electronic device and a readable storage medium. Background Art

[0002] The changes in the posture of pigs during their growth process are one of the important factors in health diagnosis. Accurate identification of pig posture can diagnose health conditions in advance, prevent common diseases, and avoid economic losses caused by large-scale infections.

[0003] Traditional pig posture recognition mainly relies on manual observation and judgment by farmers, which is time-consuming and labor-intensive. In recent years, technology-driven production systems have developed rapidly. For example, micro-inertial sensors are used to monitor the posture of pigs. However, they rely on wearable hardware for detection, and the sensors are easily damaged or fall off. With the development of deep learning technology, image processing has been further enhanced in animal posture recognition in animal husbandry, but existing posture recognition algorithms have problems such as complex and time-consuming key point detection, high cost of 3D posture recognition, high data requirements, and complex processing; and two-dimensional cameras cannot give the distance of the pig, nor can they provide the three-dimensional structure of the object, which will lead to reduced recognition accuracy.

[0004] Therefore, in order to solve the above technical problems, it is urgent to propose a new technical means. Summary of the invention

[0005] In view of this, in order to improve the accuracy of posture recognition, reduce labor costs, and provide auxiliary information for pig health judgment, the present invention proposes a pig posture recognition method based on deep learning, an electronic device, and a readable storage medium.

[0006] The present invention provides a pig posture recognition method based on deep learning, comprising the following steps:

[0007] S1. Obtain a pig image set, and preprocess the pig image set to obtain a sample data set;

[0008] S2. Build an image segmentation model, input the sample data set into the image segmentation model for training, until the preset training target is reached, and obtain a trained image segmentation model;

[0009] S3. Input the sample data set into the trained image segmentation model to obtain mask images of different parts of the pig body;

[0010] S4. Determine a pixel data set according to the mask image;

[0011] The pixel data set includes pixel areas of mask images of different parts and ratios of pixel areas between mask images of different parts;

[0012] S5. Calculate the correlation coefficient between the data in the pixel data set and the posture label, and determine n types of pixel data as posture recognition data, n ≥ 3;

[0013] The posture recognition data meets the following requirements: the correlation coefficient between the posture recognition data and the posture label is greater than the correlation coefficient between the remaining data in the pixel data set except the posture recognition data and the posture label;

[0014] S6. Construct a posture recognition model, input the posture recognition data and the corresponding posture label into the posture recognition model for training, until the preset training goal is reached, and a posture recognition model with training is obtained;

[0015] S7. Inputting the image of the pig body in the posture to be identified into the trained image segmentation model to obtain mask images of different parts of the pig body in the posture to be identified;

[0016] S8. Determine the posture recognition data according to the mask image, and input the posture recognition data of the pig body to be recognized into the trained posture recognition model to obtain the posture label, and determine the pig body posture according to the posture label.

[0017] Furthermore, the image segmentation model is an improved SegFormer model;

[0018] The improved SegFormer model includes an improved hierarchical Transformer encoder and a decoder; the output end of the improved hierarchical Transformer encoder is connected to the input end of the decoder;

[0019] The improved encoder includes an overlapping pixel block embedding module, four Transformer modules, and four polarized self-attention modules;

[0020] The output end of the overlapping pixel block embedding module is connected to the input end of the first Transformer module, the output end of the first Transformer module is connected to the input end of the first polarization self-attention module, the output end of the first polarization self-attention module is connected to the input end of the second Transformer module and the input end of the decoder, the output end of the second Transformer module is connected to the input end of the second polarization self-attention module, the output end of the second polarization self-attention module is connected to the input end of the third Transformer module and the input end of the decoder, the output end of the third Transformer module is connected to the input end of the third polarization self-attention module, the output end of the third polarization self-attention module is connected to the input end of the fourth Transformer module and the input end of the decoder, the output end of the fourth Transformer module is connected to the input end of the fourth polarization self-attention module, and the output end of the fourth polarization self-attention module is connected to the input end of the decoder.

[0021] Furthermore, the decoder adopts an improved lightweight multi-layer perceptron decoder;

[0022] The improved lightweight multi-layer perceptron decoder includes two multi-layer perceptron layers, an upsampling module and a dilated spatial pyramid pooling module;

[0023] The output end of the hole space pyramid pooling module is connected to the input end of the first multi-layer perceptron layer, the output end of the first multi-layer perceptron layer is connected to the input end of the upsampling module, and the output end of the upsampling module is connected to the input end of the second multi-layer perceptron layer;

[0024] The input end of the atrous spatial pyramid pooling module is connected to the output ends of the first polarization self-attention module, the second polarization self-attention module, the third polarization self-attention module and the fourth polarization self-attention module.

[0025] Further, in step S5, the gesture recognition data is determined by the following method:

[0026] S51. Calculate the mean of the same data in the pixel data set represents the mean of the j-th data;

[0027] S52. Calculate the mean of the pose labels

[0028] S53. Based on the mean and mean Calculate the deviation between the pose label and the data in the pixel dataset. The calculation formula is as follows:

[0029]

[0030] in, represents the deviation of the jth data of the i-th sample, X ij represents the jth data of the i-th sample, represents the deviation of the pose label of the i-th sample, Y i Represents the posture label of the i-th sample;

[0031] S54. Calculate the covariance and standard deviation based on the deviation of the posture label and the deviation of the pixel data. The calculation formula is as follows:

[0032]

[0033] Where I represents the number of samples, Cov(X j ,Y) represents the covariance between the pose label and the j-th pixel data, SD(X j ) and SD(Y) represent the standard deviation of the j-th pixel data and the standard deviation of the posture label respectively;

[0034] S55. Calculate the Pearson correlation coefficient based on the covariance and standard deviation. The calculation formula is as follows:

[0035]

[0036] Among them, r j Represents the Pearson correlation coefficient between the j-th pixel data and the posture label;

[0037] S56. Select the first n types of pixel data with the largest Pearson correlation coefficient as gesture recognition data.

[0038] Further, in step S2, the image segmentation model is trained using the following loss function Loss:

[0039]

[0040] Among them, I represents the number of samples, C represents the number of categories, and y i,c represents the true label of the i-th sample for category c, represents the probability that the i-th sample predicted by the image segmentation model belongs to category c.

[0041] Further, in step S6, the posture recognition model is a supervised machine learning model.

[0042] Furthermore, the preset training target is a preset number of training times or a preset convergence degree.

[0043] Furthermore, the preprocessing includes at least: flipping, translating, adding noise and removing noise.

[0044] Accordingly, the present invention also provides an electronic device, comprising:

[0045] A memory and a processor, wherein the memory is used to store a computer program, and when the computer program is executed by the processor, the above-mentioned pig posture recognition method based on deep learning is implemented.

[0046] Correspondingly, the present invention also provides a readable storage medium, in which computer instructions are stored. When the computer instructions are executed by a processor, the above-mentioned pig posture recognition method based on deep learning is implemented.

[0047] Beneficial effects of the present invention: The present invention calculates the pixel areas of different parts, as well as the ratio of the pixel areas of different parts, and calculates the correlation between pixel data and posture, selects the pixel data with the highest correlation as posture recognition data, and inputs the posture recognition data into the posture recognition model for posture recognition, which can not only reduce the complexity of data but also improve the accuracy of posture recognition. BRIEF DESCRIPTION OF THE DRAWINGS

[0048] The present invention will be further described below in conjunction with the accompanying drawings and embodiments:

[0049] Figure 1 It is a flow chart of the present invention.

[0050] Figure 2 This is a schematic diagram of the improved SegFormer model structure of the present invention.

[0051] Figure 3 Schematic diagram of the polarized self-attention module structure.

[0052] Figure 4 Schematic diagram of the structure of the atrous space pyramid pooling module. DETAILED DESCRIPTION

[0053] The present invention is further described below in conjunction with the accompanying drawings:

[0054] The present invention provides a pig posture recognition method based on deep learning, comprising the following steps:

[0055] S1. Obtain a pig image set, and preprocess the pig image set to obtain a sample data set;

[0056] S2. Build an image segmentation model, input the sample data set into the image segmentation model for training, until the preset training target is reached, and obtain a trained image segmentation model;

[0057] S3. Input the sample data set into the trained image segmentation model to obtain mask images of different parts of the pig body;

[0058] S4. Determine a pixel data set according to the mask image;

[0059] The pixel data set includes pixel areas of mask images of different parts and ratios of pixel areas between mask images of different parts;

[0060] S5. Calculate the correlation coefficient between the data in the pixel data set and the posture label, and determine n types of pixel data as posture recognition data, n ≥ 3;

[0061] The posture recognition data meets the following requirements: the correlation coefficient between the posture recognition data and the posture label is greater than the correlation coefficient between the remaining data in the pixel data set except the posture recognition data and the posture label;

[0062] S6. Construct a posture recognition model, input the posture recognition data and the corresponding posture label into the posture recognition model for training, until the preset training goal is reached, and a posture recognition model with training is obtained;

[0063] S7. Inputting the image of the pig body in the posture to be identified into the trained image segmentation model to obtain mask images of different parts of the pig body in the posture to be identified;

[0064] S8. Determine the posture recognition data according to the mask image, and input the posture recognition data of the pig body to be recognized into the trained posture recognition model to obtain a posture label, and determine the pig body posture according to the posture label. Through the above method, the accuracy of posture recognition can be improved while reducing the complexity of calculation.

[0065] In this embodiment, in step S1, a pig body image set is obtained, and the pig body image set is preprocessed to obtain a sample data set;

[0066] The pig image set can be extracted from the surveillance video of the pig house, and the pig images can also be obtained from the Internet. The image set can be preprocessed by flipping, translating, adding noise and removing noise to expand the data set, and the pig image set can also be cropped; the aforementioned preprocessing steps are all existing technologies and will not be repeated here.

[0067] Before preprocessing the dataset, the image set should also be labeled. The labeled content includes: head, body, limbs and tail, etc., that is, the segmentation labels of various parts of the pig.

[0068] Through data enhancement techniques such as flipping, translating, and adding noise, the diversity of training data can be significantly increased, thereby avoiding the model's over-reliance on specific data samples and improving the model's generalization ability; adding noise can help the model learn more robust features, thereby improving its robustness to noise.

[0069] In this embodiment, in step S2, an image segmentation model is constructed, and a sample data set is input into the image segmentation model for training until a preset training target is reached, thereby obtaining a trained image segmentation model;

[0070] The image segmentation model is an improved SegFormer model. Due to the high efficiency, robustness and excellent robustness of the SegFormer model in the field of semantic segmentation, the present application further improves the model. The improved SegFormer model is as follows: Figure 2 As shown;

[0071] The improved SegFormer model includes an improved hierarchical Transformer encoder and an improved lightweight multi-layer perceptron decoder; the output end of the improved hierarchical Transformer encoder is connected to the input end of the improved lightweight multi-layer perceptron decoder;

[0072] The improved encoder includes an Overlap Patch Embedding module, four Transformer Block modules, and four Polarized Self-Attention (PSA) modules.

[0073] The output end of the overlapping pixel block embedding module is connected to the input end of the first Transformer module, the output end of the first Transformer module is connected to the input end of the first polarization self-attention module, the output end of the first polarization self-attention module is connected to the input end of the second Transformer module and the input end of the decoder, the output end of the second Transformer module is connected to the input end of the second polarization self-attention module, the output end of the second polarization self-attention module is connected to the input end of the third Transformer module and the input end of the decoder, the output end of the third Transformer module is connected to the input end of the third polarization self-attention module, the output end of the third polarization self-attention module is connected to the input end of the fourth Transformer module and the input end of the decoder, the output end of the fourth Transformer module is connected to the input end of the fourth polarization self-attention module, and the output end of the fourth polarization self-attention module is connected to the input end of the decoder;

[0074] The structure of the Transformer module is as follows Figure 2As shown, it includes an efficient self-attention module (ESA), a hybrid feedforward network (Mix-FFN) and an overlap patch merging module (Overlap Patch Merging). The output end of the efficient self-attention module is connected to the input end of the hybrid feedforward network, and the output end of the hybrid feedforward network is connected to the input end of the overlap patch merging module.

[0075] The polarized self-attention module, efficient self-attention module, hybrid feedforward network and overlapping block merging module are all existing modules, and their structures are not described here.

[0076] The main function of the overlapping pixel block embedding module is two-dimensional convolution, which scales the feature map by modifying the pixel block (patch) size and stride to form a feature hierarchy structure; the efficient self-attention module is similar to the standard self-attention structure, but it uses sequence reduction operations to reduce computational complexity; the hybrid feedforward network avoids the impact of position encoding during training and avoids leakage of missing positions caused by zero padding; the hybrid feedforward network transmits position information by directly using 3×3 convolution in the feedforward network (FFN); due to the use of deep convolution, the computational efficiency is greatly improved during the training of this model; the overlapping block merging module merges feature blocks through overlapping convolution operations, thereby reducing the dimension of the feature map and adjusting the number of channels while maintaining local continuity.

[0077] The structure of the polarized self-attention module is as follows Figure 3 As shown, it includes the channel attention module ( Figure 3 Left) and spatial attention module ( Figure 3 Right); The channel attention module first uses a 1×1 convolution to convert the input feature X into Q (1×H×W) and V (C / 2×H×W), where the channel dimension of Q is compressed and the channel dimension of V is C / 2; Since the channel dimension of Q is compressed, the Softmax function is used to enhance the information of Q; Then, the enhanced Q and K are matrix multiplied, and then a 1×1 convolution and Layernorm layer are added to restore the channel dimension to C; Finally, the Sigmoid function is used to limit all parameters between 0 and 1.

[0078] The spatial attention module first uses 1×1 convolution to convert the input features into Q and V; for the Q feature, global average pooling is used to compress its spatial dimension; and the spatial dimension of the V feature is H×W; since the spatial dimension of Q is compressed, the Softmax function is used to enhance the information of Q; then Q and V perform matrix multiplication, and then perform Reshap and Sigmoid functions to limit all parameters between 0 and 1.

[0079] In view of the complex image background, this application introduces a polarized self-attention module, which can make the model pay more attention to the features related to pigs, making the model more robust when processing complex background images, thereby improving the accuracy of model segmentation. The polarized self-attention module is an extension of the self-attention mechanism, which can further improve the model's perception of important features. Compared with other attention mechanisms, the polarized self-attention module maintains a higher resolution in the channel and spatial dimensions; the polarized self-attention module completely folds the features in the other direction while maintaining a small loss of information compression in the orthogonal direction, and then uses the Softmax function on the minimum tensor in the attention module to increase the attention range and perform dynamic mapping; while ensuring the amount of calculation, a very effective long-distance modeling method is implemented to achieve the purpose of improving segmentation performance.

[0080] The improved lightweight multi-layer perceptron decoder includes two multi-layer perceptron layers (MultilayerPerceptron, MLP), an upsampling module (UpSampling) and an atrous spatial pyramid pooling module (AtrousSpatialPyramidPooling,ASPP); the multi-layer perceptron layer is an existing structure and is not described here;

[0081] The output end of the hole space pyramid pooling module is connected to the input end of the first multi-layer perceptron layer, the output end of the first multi-layer perceptron layer is connected to the input end of the upsampling module, and the output end of the upsampling module is connected to the input end of the second multi-layer perceptron layer;

[0082] The input end of the hole space pyramid pooling module is connected to the output ends of the first polarization self-attention module, the second polarization self-attention module, the third polarization self-attention module and the fourth polarization self-attention module; that is, the improved lightweight multi-layer perceptron decoder in the present application adds a hole space pyramid pooling module before the encoder of the existing SegFormer model;

[0083] The void space pyramid pooling module is an existing structure, such as Figure 4As shown in the figure, the dilated spatial pyramid pooling module consists of five parallel branches, including a 1×1 dilated convolution branch with a dilation rate of 1, a 3×3 dilated convolution branch with a dilation rate of 6, a 3×3 dilated convolution branch with a dilation rate of 12, a 3×3 dilated convolution branch with a dilation rate of 18, and a pooling branch. The pooling branch includes an image-level global average pooling operation and an upsampling operation to restore the original feature map resolution. The dilated spatial pyramid pooling module allows the features extracted by each dilated convolution with different dilation rates to be processed in a separate branch. The dilated convolution can expand the receptive field of the network, and finally fuses the features on different branches to generate the final result; the parallel branches aggregate information of different scales. In addition, it uses dilated convolutions with different dilation rates to avoid information loss and retain high-resolution features. This module helps to extract detailed information from pig images.

[0084] The improved SegFormer model not only strengthens the focus on important features, but also integrates global information, so that the output of each pixel is not only dependent on the local neighborhood, thereby enhancing the context perception ability of the model; it also integrates low-level features and high-level features, so that the model can perform semantic segmentation more finely.

[0085] Use the AdamW optimizer, set the initial learning rate to 0.00005, use the poly strategy to dynamically adjust the learning rate, set the weight decay to 0.01, and use the loss function Loss for training. The loss function Loss is as follows:

[0086]

[0087] Among them, I represents the number of samples, C represents the number of categories, and y i,c represents the true label of the i-th sample for category c, represents the probability that the i-th sample predicted by the image segmentation model belongs to category c;

[0088] The preset training target is a preset number of training times or a preset convergence degree, which is determined according to demand.

[0089] Through the above settings, the difference between the model's predicted distribution and the true distribution can be effectively measured. By minimizing the cross entropy loss function, the model's predicted probability distribution can be made as close as possible to the probability distribution of the true label.

[0090] In this embodiment, in step S3, the sample data set is input into the trained image segmentation model to obtain mask images of different parts of the pig body; the mask images of different parts are mask images corresponding to the aforementioned labels, specifically including the head, body, limbs and tail, etc. The aforementioned information is obtained to provide a data basis for subsequent classification.

[0091] In this embodiment, in step S4, a pixel data set is determined according to the mask image;

[0092] The pixel data set includes pixel areas of mask images of different parts and ratios of pixel areas between mask images of different parts; the process of calculating the pixel area according to the mask image is a prior art, and the specific calculation process will not be described in detail here;

[0093] Specifically, it includes the pixel areas of the head, body, limbs and tail of different pigs, which are represented by S1, S2, S3 and S4 respectively; the ratio of the pixel areas between the mask images of different parts of different pigs, including: the pixel ratio of the head to the body S1 / S2, the pixel ratio of the limbs to the body S3 / S2, the pixel ratio of the limbs to the head S3 / S1, the pixel ratio of the tail to the head S4 / S1 and the pixel ratio of the tail to the body S4 / S2, etc.;

[0094] Since a two-dimensional camera cannot give the distance of the pigs or provide the three-dimensional structure of the object, in order to distinguish between lying and standing pigs, this application calculates the pixel area size of each part. This is because when pigs lie on their sides, they stretch their limbs, and the pixel area of ​​their limbs is larger than when they are standing. By calculating the size of the pixel area of ​​each part, the posture of the pig can be identified more accurately. Furthermore, in order to reduce the impact of the size differences of the pigs in the image, the ratio of the pixel area of ​​each part is calculated.

[0095] In this embodiment, in step S5, the correlation coefficient between the data in the pixel data set and the posture label is calculated, and n types of pixel data are determined as posture recognition data, where n≥3;

[0096] The posture recognition data meets the following requirements: the correlation coefficient between the posture recognition data and the posture label is greater than the correlation coefficient between the remaining data in the pixel data set except the posture recognition data and the posture label;

[0097] The gesture recognition data is determined by the following method:

[0098] S51. Calculate the mean of the same data in the pixel data set represents the mean of the j-th data;

[0099] S52. Calculate the mean of the posture label (the value corresponding to the label)

[0100] S53. Based on the mean and mean Calculate the deviation between the pose label and the data in the pixel dataset. The calculation formula is as follows:

[0101]

[0102] in, represents the deviation of the jth data of the i-th sample, X ij represents the jth data of the i-th sample, represents the deviation of the pose label of the i-th sample, Y i Represents the posture label of the i-th sample;

[0103] S54. Calculate the covariance and standard deviation based on the deviation of the posture label and the deviation of the pixel data. The calculation formula is as follows:

[0104]

[0105] Where I represents the number of samples, Cov(X j ,Y) represents the covariance between the pose label and the j-th pixel data, SD(X j ) and SD(Y) represent the standard deviation of the j-th pixel data and the standard deviation of the posture label respectively;

[0106] S55. Calculate the Pearson correlation coefficient based on the covariance and standard deviation. The calculation formula is as follows:

[0107]

[0108] Among them, r j Represents the Pearson correlation coefficient between the j-th pixel data and the posture label;

[0109] S56. Select the first n pixel data with the largest Pearson correlation coefficient as gesture recognition data, where n≥3;

[0110] The posture recognition data determined by calculation using the sample data set of the present application are the pixel area of ​​the limbs S3, the pixel area ratio of the limbs to the body S3 / S2, and the pixel area ratio of the limbs to the head S3 / S1.

[0111] Through the above method, several types of data with the highest correlation with the posture can be selected to provide a basis for subsequent posture recognition.

[0112] In this embodiment, in step S6, a posture recognition model is constructed, and the posture recognition data and the corresponding posture label are input into the posture recognition model for training until a preset training target is reached, thereby obtaining a trained posture recognition model;

[0113] The posture recognition model is a supervised machine learning model, and the support vector machine SVM is preferred. The basic idea of ​​SVM is to find a hyperplane that can separate data of different categories and maximize the intervals on both sides of the hyperplane. When the data is linearly inseparable, SVM can map the data to a higher-dimensional space through the kernel technique to make it linearly separable. The SVM classifier finds the best dividing plane based on three features (limb pixel area, limb / body pixel area ratio, limb / head pixel area ratio) to distinguish different postures.

[0114] The preset training target is a preset number of training times or a preset convergence degree, which is determined according to demand and will not be elaborated here.

[0115] Using supervised machine learning models for data classification can bring significant advantages in processing complex data sets, improving classification accuracy, and optimizing model generalization capabilities. In particular, the core idea of ​​SVM is to find a maximum margin hyperplane to separate data points of different categories. This method not only improves classification accuracy, but also reduces the complexity of the model, making the model easier to explain and understand.

[0116] In this embodiment, in step S7, the image of the pig body in the posture to be identified is input into the trained image segmentation model to obtain mask images of different parts of the pig body in the posture to be identified, specifically including mask images of the head, body, limbs and tail.

[0117] In this embodiment, in step S8, the posture recognition data is determined according to the mask image, and the posture recognition data of the pig body to be recognized is input into the trained posture recognition model to obtain a posture label, and the pig body posture is determined according to the posture label;

[0118] Determining the posture recognition data according to the mask image includes: calculating the limb pixel areas, the limb / body pixel area ratios, and the limb / head pixel area ratios according to the mask image;

[0119] The pixel areas of the limbs, the pixel area ratios of the limbs / body, and the pixel area ratios of the limbs / head are input into the trained support vector machine, and the posture labels are output. The pig posture is determined based on the posture labels.

[0120] In order to verify the effectiveness of adding the polarized self-attention module and the dilated spatial pyramid pooling module to the segmentation model proposed in this application, an ablation comparison experiment was conducted; mean F1-score (mF1) and mean Intersection over Union (mIoU) were used as evaluation indicators;

[0121]

[0122] Among them, k represents the pixel category, TP represents the number of true positive examples, FP represents the number of false positive examples, FN represents the number of false negative examples, Precision represents the precision, and Recall represents the recall rate.

[0123] Experiment 1 is the SegFormer model, Experiment 2 is the SegFormer model with the polarized self-attention module PSA added, Experiment 3 is the SegFormer model with the dilated spatial pyramid pooling module added, and Experiment 4 is the SegFormer model with the polarized self-attention module PSA and the dilated spatial pyramid pooling module added. The ablation experiment results are shown in Table 1:

[0124]

[0125] Table 1 Ablation experiment results

[0126] By comparing Experiment 1 and Experiment 2, it can be found that compared with the baseline model, the addition of the PSA module has improved all evaluation indicators, among which mIoU has increased by 1.23 percentage points and mF1 has increased by 0.73 percentage points. In general, the posture of pigs is most correlated with their limbs, so we can focus on the data related to the limbs. The IoU of the limbs has increased by 0.65 percentage points. The experimental results show that the introduction of the PSA module can enhance the self-attention at the pixel level of the image, which can effectively improve the segmentation effect, proving the effectiveness of adding the PSA polarization self-attention mechanism module to SegFormer.

[0127] By comparing Experiment 1 and Experiment 3, we can find that after the introduction of the ASPP module, the mIoU of SegFormer increased by 0.79 percentage points, the mF1 increased by 0.24 percentage points, and the IoU of the limbs category increased by 1.41 percentage points compared with the original model. The experimental results show that the introduction of the ASPP module integrates multi-scale context information to obtain denser data, which enables the model to have a better extraction effect, proving the effectiveness of adding the ASPP module to SegFormer.

[0128] The results of Experiment 4 show that the introduction of the ASPP module and the PSA polarized self-attention mechanism module can effectively improve the model, with mIoU increased by 3.41 percentage points, mF1 increased by 2.32 percentage points, and the IoU of the limbs category increased by 2.37 percentage points. The effectiveness of the ASPP module and the PSA module in the semantic segmentation task of pig images was verified.

[0129] At the same time, the model of this application is compared with other segmentation models (ensuring that the segmentation samples and training processes are the same, only the models are different), and the segmentation results are shown in Table 2:

[0130]

[0131] Table 2 Comparison results of different segmentation models

[0132] It can be concluded from Table 2 that the segmentation accuracy of the improved SegFormer model is better than that of Unet, K-Net, DeeplabV3+, DeeplabV3, Mask2Former and SegFormer models. The average intersection-over-union ratio and average F1 score of the improved SegFormer model are 81.59% and 88.55%, respectively, which are 3.51 percentage points and 2.32 percentage points higher than the experimental results of the SegFormer model; in terms of mIoU indicators, it exceeds K-Net, Deeplabv3+, and Mask2Former. +, DeeplabV3, and Mask2Former models by 17.87 percentage points, 6.67 percentage points, 10.21 percentage points, 10.23 percentage points and 7.12 percentage points; in terms of mF1 indicators, it exceeds K-Net, DeeplabV3+, DeeplabV3, and Mask2Former models by 17.78 percentage points, 3.74 percentage points, 7.29 percentage points, 7.74 percentage points and 4.31 percentage points respectively. The improved SegFormer model is the model with the best overall performance in Table 2.

[0133] To further verify the accuracy of the posture recognition results, taking the support vector machine as an example, part of the data in the sample data set was selected as the prediction set. According to the method recorded in this application, the mask map of the pig was obtained, and the limb pixel area, limb / body pixel area ratio, and limb / head pixel area ratio were calculated according to the mask map; the limb pixel area, limb / body pixel area ratio, and limb / head pixel area ratio were input into the trained support vector machine for classification, and the recognition accuracy rate for standing posture reached 92%, and the recognition accuracy rate for lying posture was 90%. The accuracy of posture recognition in this application is relatively high.

[0134] At the same time, the same test data was input into the SegFormer model to obtain a mask map, and the limb pixel area, limb / body pixel area ratio, and limb / head pixel area ratio were further calculated based on the mask map segmented by the SegFormer model; the limb pixel area, limb / body pixel area ratio, and limb / head pixel area ratio were input into the trained support vector machine for classification, and the standing posture recognition accuracy was 82%, and the lying posture recognition accuracy was 85%. The experimental results show that the improved SegFormer model is significantly more effective than the SegFormer model in pig posture recognition.

[0135] Accordingly, the present invention also provides an electronic device, comprising:

[0136] A memory and a processor, wherein the memory is used to store a computer program, and when the computer program is executed by the processor, the above-mentioned pig posture recognition method based on deep learning is implemented.

[0137] Correspondingly, the present invention also provides a readable storage medium, in which computer instructions are stored. When the computer instructions are executed by a processor, the above-mentioned pig posture recognition method based on deep learning is implemented.

[0138] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solution of the present invention, which should be included in the scope of the claims of the present invention.

Claims

1. A pig posture recognition method based on deep learning, characterized by: The following steps are involved: S1. Obtain a pig image set, and preprocess the pig image set to obtain a sample data set; S2. Build an image segmentation model, input the sample data set into the image segmentation model for training, until the preset training target is reached, and obtain a trained image segmentation model; S3. Input the sample data set into the trained image segmentation model to obtain mask images of different parts of the pig body; S4. Determine a pixel data set according to the mask image; The pixel data set includes pixel areas of mask images of different parts and ratios of pixel areas between mask images of different parts; S5. Calculate the correlation coefficient between the data in the pixel data set and the posture label, and determine n types of pixel data as posture recognition data, n ≥ 3; The posture recognition data meets the following requirements: the correlation coefficient between the posture recognition data and the posture label is greater than the correlation coefficient between the remaining data in the pixel data set except the posture recognition data and the posture label; S6. Construct a posture recognition model, input the posture recognition data and the corresponding posture label into the posture recognition model for training, until the preset training goal is reached, and a posture recognition model with training is obtained; S7. Inputting the image of the pig body in the posture to be identified into the trained image segmentation model to obtain mask images of different parts of the pig body in the posture to be identified; S8. Determine the posture recognition data according to the mask image, and input the posture recognition data of the pig body to be recognized into the trained posture recognition model to obtain the posture label, and determine the pig body posture according to the posture label.

2. The pig posture recognition method based on deep learning according to claim 1 is characterized by: The image segmentation model is an improved SegFormer model; The improved SegFormer model includes an improved hierarchical Transformer encoder and a decoder; the output end of the improved hierarchical Transformer encoder is connected to the input end of the decoder; The improved encoder includes an overlapping pixel block embedding module, four Transformer modules, and four polarized self-attention modules; The output end of the overlapping pixel block embedding module is connected to the input end of the first Transformer module, the output end of the first Transformer module is connected to the input end of the first polarization self-attention module, the output end of the first polarization self-attention module is connected to the input end of the second Transformer module and the input end of the decoder, the output end of the second Transformer module is connected to the input end of the second polarization self-attention module, the output end of the second polarization self-attention module is connected to the input end of the third Transformer module and the input end of the decoder, the output end of the third Transformer module is connected to the input end of the third polarization self-attention module, the output end of the third polarization self-attention module is connected to the input end of the fourth Transformer module and the input end of the decoder, the output end of the fourth Transformer module is connected to the input end of the fourth polarization self-attention module, and the output end of the fourth polarization self-attention module is connected to the input end of the decoder.

3. The pig posture recognition method based on deep learning according to claim 2 is characterized in that: The decoder adopts an improved lightweight multi-layer perceptron decoder; The improved lightweight multi-layer perceptron decoder includes two multi-layer perceptron layers, an upsampling module and a dilated spatial pyramid pooling module; The output end of the hole space pyramid pooling module is connected to the input end of the first multi-layer perceptron layer, the output end of the first multi-layer perceptron layer is connected to the input end of the upsampling module, and the output end of the upsampling module is connected to the input end of the second multi-layer perceptron layer; The input end of the atrous spatial pyramid pooling module is connected to the output ends of the first polarization self-attention module, the second polarization self-attention module, the third polarization self-attention module and the fourth polarization self-attention module.

4. The pig posture recognition method based on deep learning according to claim 1 is characterized in that: In step S5, the gesture recognition data is determined by the following method: S51. Calculate the mean of the same data in the pixel data set represents the mean of the j-th data; S52. Calculate the mean of the pose labels S53. Based on the mean and mean Calculate the deviation between the pose label and the data in the pixel dataset. The calculation formula is as follows: in, represents the deviation of the jth data of the i-th sample, X ij represents the jth data of the i-th sample, represents the deviation of the pose label of the i-th sample, Y i Represents the posture label of the i-th sample; S54. Calculate the covariance and standard deviation based on the deviation of the posture label and the deviation of the pixel data. The calculation formula is as follows: Where I represents the number of samples, Cov(X j ,Y) represents the covariance between the pose label and the j-th pixel data, SD(X j ) and SD(Y) represent the standard deviation of the j-th pixel data and the standard deviation of the posture label respectively; S55. Calculate the Pearson correlation coefficient based on the covariance and standard deviation. The calculation formula is as follows: Among them, r j Represents the Pearson correlation coefficient between the j-th pixel data and the posture label; S56. Select the first n types of pixel data with the largest Pearson correlation coefficient as gesture recognition data.

5. The pig posture recognition method based on deep learning according to claim 1 is characterized in that: In step S2, the image segmentation model is trained using the following loss function Loss: Among them, I represents the number of samples, C represents the number of categories, and y i,c represents the true label of the i-th sample for category c, represents the probability that the i-th sample predicted by the image segmentation model belongs to category c.

6. The pig posture recognition method based on deep learning according to claim 1 is characterized by: In step S6, the posture recognition model is a supervised machine learning model.

7. The pig posture recognition method based on deep learning according to claim 1 is characterized by: The preset training target is a preset number of training times or a preset convergence degree.

8. The pig posture recognition method based on deep learning according to claim 1 is characterized by: The preprocessing at least includes: flipping, translating, adding noise and removing noise.

9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory is used to store a computer program, and when the computer program is executed by the processor, the method for pig posture recognition based on deep learning according to any one of claims 1 to 8 is implemented.

10. A readable storage medium, characterized in that: The readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the pig posture recognition method based on deep learning described in any one of claims 1 to 8 is implemented.