A method for multi-posture recognition and scoring of pig groups using depth images and CNN-SVM
Through deep image processing and CNN-SVM model, the multi-pose of pigs is identified and scored, which solves the problem of multi-pose recognition of pigs and achieves high-accuracy gesture recognition, which is suitable for automatic detection of large-scale farms.
Patent Information
- Application Number
- CN202210081496.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-24
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-01-24
AI Technical Summary
It is difficult for existing technology to effectively identify and score multiple postures of pigs, especially in large-scale breeding farms. Traditional methods are inefficient and difficult to adapt to environmental changes.
Depth image processing and the CNN-SVM model are used to collect data through the Azure Kinect DK depth camera to extract features such as the pig's shoulder and hip depth distance, convex hull area and boundary ratio, and build a CNN-SVM detector for posture detection and classification. , to achieve multi-posture recognition of pigs.
The accuracy of group pig posture recognition is improved. Compared with the traditional method, the recognition accuracy is increased by 94.6368%, 92.2175% and 90.5396%, significantly improving the recognition accuracy.
Smart Images

Figure CN114419675B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of multi-posture recognition of a group of pigs, and in particular to a multi-posture recognition and scoring method of a group of pigs using a depth image and a CNN-SVM. Background Art
[0002] Judging whether pigs are healthy and comfortable in the environment is an important aspect of pig behavior detection. The posture of pigs can be used as an indicator to reflect whether pigs are healthy and comfortable. Generally speaking, pigs prefer to lie down rather than stand. When the ambient temperature is high, pigs generally lie completely flat with their limbs stretched out, or lie on their side. When the ambient temperature is low, pigs lie with their limbs folded under their bodies, lying on their sternum, or lying on their abdomens with their sternums on the ground, their front legs folded under their bodies, and their hind legs visible. At the same time, when the temperature is high, pigs will become more agitated and their activity will increase. The standing posture of pigs will increase compared to when the temperature is low. The above shows the importance of the posture of pigs in behavioral detection to determine whether they are healthy and comfortable in the environment.
[0003] As the scale of pig farming grows, people's demand for pig behavior detection is not just for a single pig. Breeders hope to detect the behavior of a group of pigs. The integration of machine vision and machine learning technologies increases the possibility of detecting the behavior, health and growth status of large-scale farm animals, which helps further welfare farming. At the same time, managers can make timely adjustments based on their current conditions such as health status and social activities. Video behavior detection of pigs is a typical way to apply machine vision technology and deep learning technology. This is an accurate, low-cost, non-stressful and non-invasive method that is stress-free for both animals and breeders, and is adaptable to indoor and outdoor production conditions, avoiding the cumbersome and inefficient process of traditional manual recording. Summary of the invention
[0004] The purpose of this section is to summarize some aspects of embodiments of the present invention and briefly introduce some preferred embodiments. Some simplifications or omissions may be made in this section and the specification abstract and the invention title of this application to avoid blurring the purpose of this section, the specification abstract and the invention title, and such simplifications or omissions cannot be used to limit the scope of the present invention.
[0005] In view of the above existing problems, the present invention is proposed.
[0006] Therefore, the technical problem solved by the present invention is: to realize multi-posture recognition of pig groups based on deep video by using machine vision and deep learning technology.
[0007] To solve the above technical problems, the present invention provides the following technical solutions: a method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM, comprising the following steps: collecting an initial data set; defining and describing each posture of a pig; performing depth image processing on the initial data set to obtain the shoulder-hip depth distance, shoulder-hip depth distance ratio, ratio of the area of the convex hull to the boundary, and ratio of the perimeter of the convex hull to the boundary of the target pig in each posture as input data; constructing a CNN-SVM detector for pig posture detection and classification, using the input data as training data for the detector, obtaining weight parameters between each layer of the model after training, and saving the model; obtaining feature vectors of the image data of the target group of pigs to be identified by the first fully connected layer of the CNN model, and sending them to the SVM classification for data classification to complete posture recognition.
[0008] Preferably, the depth image processing includes the following steps: extracting the target object through Grabcut image segmentation, first calibrating the target object for watershed segmentation; based on the segmented pig image, adjusting the pig to a horizontal position through a minimum circumscribed rectangle to obtain depth information of the shoulder and buttocks; and binarizing the segmented pig image to find and calculate the perimeter and area of the convex hull of each pig in each posture and the pig boundary.
[0009] Preferably, the extraction of the depth distance of the shoulder and hip includes the following steps: cropping the image after watershed segmentation based on the regional attributes; finding the convex polygon of the cropped single pig image, and then finding the minimum circumscribed rectangle; obtaining the horizontal angle in the top view image, if the horizontal angle is greater than 1, then rotating each pig image accordingly to adjust it to the horizontal, and the rotation angle formula is as follows:
[0010]
[0011] Among them, T0(x1,y1) and T1(x2,y2) are the two vertices of an edge of the convex envelope, respectively. i (x t ,y t ) are vertices of the convex envelope, (t=1,2,...,n), (x' t ,y' t ) is T i (x t ,y t ) is the coordinate after rotation θ; the average value of the depth distance from 1 / 5 to 2 / 5 of the pig's body is taken as its depth value. The depth information of the hip is collected in the same way as above, from about 6 / 10 to 8 / 10, and the average value is taken as its depth distance. The shoulder depth distance calculation formula is as follows:
[0012]
[0013] Among them, D s-final The depth distance after taking the average of the shoulder, (D s-(i) ) body(1 / 5~2 / 5 ) is the depth distance from the pig's head to the shoulder at 2 / 5 of the whole body, n is the number of shoulder depth distance value points, thrshold is the set threshold, and the hip acquisition principle is the same as the shoulder.
[0014] Preferably, the method includes extracting the area, perimeter and boundary of the convex hull of each pig based on image binarization, including the following steps, and the convex hull definition formula is as follows:
[0015] p=[p1,p2,...,pn]λ=λ1p1+λ2p2+...+λnpn (λ1+λ2+...+λn=1,min{λ1,λ2,...,λn}≥0)where λ is a vector consisting of n components, i.e., the coefficients of each point, S={p1,p2,...,pn} is the point set in 2D space, P is the convex hull, and the boundary of the target in image processing is the set of pixel coordinates of the boundary; based on the definition, the boundary, perimeter and area of the convex hull of the pig are calculated respectively, and the calculation formula is as follows:
[0016]
[0017] Among them, S area Expressed as the convex hull area, s0,s1,...,s n represents the vertex of the convex envelope, Ls1-s0 represents the length of the corresponding edge between the two vertices of the convex envelope, θs2-s1 represents the angle corresponding to the edge s2-s1 of the convex envelope in the triangle s0s1s2, L C-girth represents the perimeter of the convex hull, L border represents the boundary length, (x b-0 ,y b-0 ),(x b-1 ,y b-1 ),...,(x b-m ,y b-m ) represents the pixel coordinates of points on the boundary.
[0018] Preferably, the CNN in the CNN-SVM detector has two convolutional layers, two pooling layers, a fully connected layer and a softmax regression layer, and an SVM classifier is connected after the first fully connected layer to realize object classification and recognition.
[0019] Preferably, the CNN-SVM detector includes the following recognition steps: the text data first enters the first convolution layer C1 to extract the feature vector; then enters the first pooling layer S1 for data dimensionality reduction processing; next, the data enters the second convolution layer C2 for data feature extraction, and then enters the second pooling layer S2 for dimensionality reduction processing; finally, the feature vector is output through the first fully connected layer FC1.
[0020] Preferably, the CNN-SVM detector includes the following training steps: the detector model sets the convolution kernel size of the convolution layer to 5*5, the step size to 1, the convolution kernel size of the pooling layer to 2*2, sets dropout so that it is not easy to overfit, and uses the softmax regression layer to reversely train the CNN when training the CNN model, sets the error cost in the form of cross entropy, and uses the AdamOptimizer algorithm to optimize the objective function; finally, after the model is trained, the experimental text data is input to obtain the feature vector from the first fully connected layer of the CNN, and the feature vector is sent to the SVM classification for data classification.
[0021] Preferably, the definition and description of each posture of the pig includes defining 5 lying postures of the pig, namely A is standing posture (STD), B is sitting posture (SIT), C is sternal recumbent posture (STR), D is abdominal recumbent posture (VTR), and E is lying flat on the back posture (LTR).
[0022] Preferably, the acquisition of the initial data set includes using Microsoft's Azure Kinect DK depth camera to continuously collect data for 8 days, with an average indoor temperature of 22°C and a humidity range of 55%-70%. The camera is installed for top view and includes a depth camera, an RGB camera IMU and a multi-array microphone.
[0023] Beneficial effects of the present invention: The model (CNN-SVM) in this paper combines the advantages of the SVM and CNN models, uses CNN to extract feature vectors that are not easy to fit and are more scientific, and the powerful classification and generalization capabilities of SVM. The difference between the model (CNN-SVM) in this paper and the traditional SVM and CNN in posture recognition is that under the same training data and test data, the accuracy of posture recognition is 94.6368%, 92.2175% and 90.5396% respectively, which obviously has a significant improvement in recognition accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for describing the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative labor. Among them:
[0025] Figure 1 This is a schematic diagram of the light source of the experimental site of the present invention;
[0026] Figure 2 This is a schematic diagram of the installation position of the Azure Kinect DK camera device in the experimental site of the present invention;
[0027] Figure 3 A schematic diagram for describing the details of the experimental site of the present invention;
[0028] Figure 4 These are five exemplary diagrams of lying postures for pigs according to the present invention;
[0029] Figure 5 A schematic diagram of the process of removing the background by using the Grabcut algorithm of the present invention, and a schematic diagram of the watershed segmentation after marking the segmented area and the watershed segmentation without marking;
[0030] Figure 6 It is a schematic diagram of obtaining pig shoulder and hip depth information and pig envelope and boundary information according to the present invention;
[0031] Figure 7 This is a schematic diagram of the pig group posture detection process and the internal structure of the CNN-SVM detector described in the present invention;
[0032] Figure 8 A schematic diagram of the training model process and the testing model process of the present invention;
[0033] Fig. 9 The multi-classification confusion matrix of the five postures of the group of pigs described in the present invention;
[0034] Fig.10 This is the ROC curve for the group pig posture detection described in the present invention. DETAILED DESCRIPTION
[0035] In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are described in detail below in conjunction with the drawings of the specification. Obviously, the described embodiments are part of the embodiments of the present invention, but not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary persons in the art without creative work should fall within the scope of protection of the present invention.
[0036] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0037] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The term "in one embodiment" that appears in different places in this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive with other embodiments.
[0038] The present invention is described in detail with reference to schematic diagrams. When describing the embodiments of the present invention, for the sake of convenience, the cross-sectional diagrams showing the device structure will not be partially enlarged according to the general scale, and the schematic diagrams are only examples, which should not limit the scope of protection of the present invention. In addition, in actual production, the three-dimensional dimensions of length, width and depth should be included.
[0039] At the same time, in the description of the present invention, it should be noted that the directions or positional relationships indicated by the terms "upper, lower, inner and outer" are based on the directions or positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore cannot be understood as limiting the present invention. In addition, the terms "first, second or third" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0040] In the present invention, unless otherwise clearly specified and limited, the terms "install, connect, connect" should be understood in a broad sense, for example: it can be a fixed connection, a detachable connection or an integral connection; it can also be a mechanical connection, an electrical connection or a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0041] Example 1
[0042] Animal behavior provides information about their health, welfare, living environment, etc. They will show different postures under different ambient temperature conditions. When the ambient temperature is high, they will lie on their side with their limbs stretched out, and will appear more anxious. At the same time, they will stand more often than usual. When the temperature is low, they will lie on their side with their abdomen or sternum, and lie more often than usual. In recent years, machine vision and machine learning technologies have been widely used for behavioral detection of individual and group pigs.
[0043] Therefore, this embodiment proposes a method for realizing multi-posture recognition of pig groups based on deep video using machine vision and deep learning technology. The method adopts image processing algorithms of convolutional neural network (CNN) and support vector machine (SVM), uses the Azure Kinect DK depth camera with top view to obtain the depth information of pigs, extracts the target object through Grabcut image segmentation, and then first performs watershed segmentation through target calibration. On the one hand, based on the segmented pig image, the pig is adjusted to a horizontal position through the minimum circumscribed rectangle to obtain the depth information of the shoulder and buttocks. On the other hand, the segmented image is binarized to find and calculate the perimeter and area of the convex hull of each pig in each posture and the pig boundary. The ratio of the corresponding convex hull area and perimeter to the target pig boundary, the shoulder and buttocks depth information and the ratio are used as the input of the CNN-SVM classification model, the model is trained and tested, and the trained and tested model is applied to the actual pig posture recognition.
[0044] More specifically, a method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM includes the following steps:
[0045] S1: Collect the initial data set;
[0046] S2: Define and describe the various postures of pigs;
[0047] S3: performing depth image processing on the initial data set to obtain the shoulder-hip depth distance, shoulder-hip depth distance ratio, ratio of the convex hull area to the boundary, and ratio of the convex hull perimeter to the boundary of the target pig in each posture as input data;
[0048] S4: construct a CNN-SVM detector for pig posture detection and classification, use the input data as training data of the detector, obtain weight parameters between each layer of the model after training, and save the model;
[0049] S5: The image data of the target group of pigs to be identified obtains feature vectors through the first fully connected layer of the CNN model, and sends them to the SVM classification for data classification to complete posture recognition.
[0050] Furthermore, in step S1, it should be noted that:
[0051] Since various environmental factors in the real scene affect the results of the experiment to a certain extent, the analysis of the posture of the live pigs is inaccurate. The main reasons that affect the experimental results include: (1) the live pigs are crowded together, resulting in inaccurate image segmentation; (2) the lighting in the experimental site and the change of day and night cause the light in the site to change. This embodiment combines the actual production situation to identify the posture of the group of pigs. The difficulty of automatic detection in this way is much greater than that of single pig posture recognition.
[0052] In order to reduce the impact of changes in lighting in the experimental site on image acquisition, changes in light caused by lighting and day-night cycles in the acquisition site must be considered. In order to ensure the accuracy of the experiment, a stable, clear and reliable data set must be constructed.
[0053] The data in this example were collected in May 2021 at the local pig farm "Taihuyuan Feeding Station" in Hangzhou, Zhejiang. In order to ensure the reliability of the experimental data, the data was collected continuously for 8 days, using Microsoft's Azure KinectDK depth camera. The average indoor temperature was 22°C and the humidity range was 55%-70%. In this experimental study, the Azure KinectDK depth camera was used as a tool for collecting RGB and depth images, installed as a top view (refer to Figure 2 ), it consists of a depth camera, an RGB camera, an IMU, and a multi-array microphone.
[0054] There are 24 pig pens in the breeding ground, with an area of 5.30m×3.8m and a height of 2.3m~3m. The fences in the breeding ground are made of galvanized steel pipes, which not only ensure the stability of the pig pens, but also ensure the air circulation of the pig pens. The light in the pig pens uses a unified flat-top LED energy-saving lamp and a natural light source to complement each other. The ventilation in the pig pens uses a unified exhaust fan for air circulation. The Landrace pigs observed in the experiment are about 60 to 70 days old. There are 10-15 pigs in each pig pen. The Kinect camera is installed parallel to the ground. For specific conditions, please refer to Figures 1 to 3 As shown, Figure 3 The experimental site is described in detail in the figure, where h1 and h2 = height of the pig house, L = length of the pig house, and W = width of the pig house.
[0055] Furthermore, in step S2, it should be noted that:
[0056] The combination of the position, orientation and connection relationship of the various parts of the pig's body is called the pig's posture. The definitions of the five pig postures identified in this study are shown in Table 1 below. Figure 4 Examples of depth images in different postures are shown. The "lying posture" is further subdivided into "sternum", "abdomen" and "lying flat" postures, which can further reflect the behavior habits of pigs.
[0057] Table 1: Definitions and descriptions of pig posture.
[0058]
[0059] Reference Figure 4The diagram shows 5 examples of lying positions for pigs. A is standing position (STD), B is sitting position (SIT), C is sternal recumbent position (STR), D is abdominal recumbent position (VTR), and E is lying flat (LTR).
[0060] Furthermore, regarding the depth image processing in step S3, it should be noted that:
[0061] To analyze the standing, sitting and lying postures of live pigs, we first need to obtain the specific information of the specific target pigs (i.e., the depth distance of the shoulder and hips, the boundary, the perimeter and area of the convex hull). First, the image is pixel-cropped, and the image is uniformly cropped to a resolution of 512*424 pixels. Traditional background subtraction of live pigs is to eliminate the background through the shadow difference method, and the pig body is extracted by subtracting the target image and the background image. However, in actual production practice, it is difficult to take a single background image.
[0062] This embodiment uses a Grabcut image segmentation method to extract the target object. It is based on an energy optimization algorithm to convert the image segmentation problem into a minimum cut problem of the graph. By inputting the foreground and background, a weighted graph of the similarity between the background and the foreground is completed, and the image segmentation is achieved through optimal cutting, so that the foreground can be extracted without the background image. The extraction effect is as follows: Figure 5 's hint.
[0063] Then, it is converted into a binary image through dynamic threshold segmentation, and the median fuzzy filter algorithm is used for multiple iterations to eliminate the interference of image noise. Watershed transform is a commonly used segmentation method. This experiment uses this method to segment overlapping (touching) pigs. The traditional watershed segmentation method often has the phenomenon of over-segmentation. In order to solve this phenomenon of over-segmentation, this experiment first marks the segmentation area and then performs watershed segmentation. In this way, by specifying the segmentation "valley" in advance, the image segmentation can be more effective. The segmentation results are compared. Figure 5 Secondly, in order to obtain better posture classification performance, this experiment classifies standing postures into one category for unified recognition. Figure 5 The Grabcut algorithm removes the background. The figure includes the foreground, background, watershed segmentation after marking the segmented area, and watershed segmentation without marking. Figure 5 It can be seen that the real effect of the actual segmentation target.
[0064] Using the depth image data of the pigs in the image to identify their posture can obtain more information about the target than traditional RGB images, which makes it possible to detect more postures. In order to initialize the model for pig posture scoring, it is necessary to obtain the shoulder and hip depth distance, convex envelope and boundary of the target pig. The details are as follows:
[0065] First, extract the depth distance of the pig's shoulder and hip. The image after the watershed segmentation is cropped based on regional attributes (size and area) to remove any body parts of other pigs in close proximity. According to the actual depth distance of pigs in different postures, the depth distance of the pig's shoulder and hip is different in different postures, and there is a significant difference. At the same time, due to the different tilt postures of the pigs in the image, in order to make the depth data of the shoulder and hip more accurate, the convex polygon (defined in formula 3) of the cropped single pig image is calculated to obtain the minimum circumscribed rectangle, and the horizontal angle in the top view image is obtained. If the horizontal angle is greater than 1. Each pig is rotated accordingly to adjust it to the horizontal. The rotation angle formula is as follows:
[0066]
[0067] Among them, T0(x1,y1) and T1(x2,y2) are the two vertices of an edge of the convex envelope, respectively. i (x t ,y t ), t=1,2,...,n, are the vertices of the convex envelope. (x' t ,y' t ) is T i (x t ,y t ) is the coordinate after rotation θ. By collecting 9000 frames of images on site, it can be seen that the shoulder position of the pig is approximately from 1 / 5 to 2 / 5 of the whole body from the head. The average value of the depth distance of the pig in this section is taken as its depth value. The depth information of the hip is collected in the same way as above, from about 6 / 10 to 8 / 10, and the average value is taken as its depth distance. The shoulder depth distance calculation formula is as follows:
[0068]
[0069] Where D s-final The depth distance after taking the average of the shoulder, (D s-(i) ) body(1 / 5~2 / 5 ) is the depth distance from the pig's head to the shoulder at 2 / 5 of the entire body, n is the number of points for obtaining the shoulder depth distance value, thrshold is the set threshold, the purpose of setting the threshold is to prevent the extraction point depth distance from being inconsistent with the actual situation. The hip acquisition is similar to the shoulder. The extraction process is as follows: Figure 6 . Figure 6 The left part (a) shows the acquisition of pig shoulder and hip depth information, and the right part (b) shows the acquisition of pig envelope and boundary information.
[0070] The next step is to extract the 2D features (convex envelope and boundary) of the pig image, that is, to extract the area, perimeter and boundary of the convex hull of each pig based on the above binary image. The convex hull is an important geometric structure in computer image processing and is called the minimum convex polygon set of all given points (Jayaram and Fleyeh., 2016; Behera et al., 2018). It is a famous feature for object shape recognition in 2D images (Liu-Yu and Thonnat., 1993). The principle is that the envelope and convex hull of the boundary of pigs in different postures are different. The convex hull definition formula is as follows:
[0071] p=[p1,p2,...,pn]λ=λ1p1+λ2p2+...+λnpn (λ1+λ2+...+λn=1,min{λ1,λ2,...,λn}≥0) (3)
[0072] Among them, λ is a vector composed of n components, that is, the coefficients of each point. S = {p1, p2, ..., pn} is the point set in the 2D space, and P is the convex hull. The boundary of the target in image processing is the set of pixel coordinates of the boundary. Next, based on the above definition, the boundary, perimeter and area of the convex hull of the pig are calculated respectively. The calculation formula is as follows:
[0073]
[0074] Where S area Expressed as the convex hull area, s0,s1,...,s n L represents the vertex of the convex envelope, Ls1-s0 represents the length of the corresponding edge between the two vertices of the convex envelope, and θs2-s1 represents the angle corresponding to the edge s2-s1 of the convex envelope in the triangle s0s1s2. C-girth represents the perimeter of the convex hull, L border represents the boundary length, (x b-0 ,y b-0 ),(x b-1 ,y b-1 ),...,(x b-m ,y b-m ) represents the pixel coordinates of points on the boundary.
[0075] Finally, in order to enhance the stability of the model, the depth distance between the pig shoulder and hip, the ratio of the depth distance between the shoulder and hip, the ratio of the area of the convex hull to the boundary, and the ratio of the perimeter of the convex hull to the boundary are taken as the input of the CNN-SVM. The extraction process is as follows: Figure 6 .
[0076] Furthermore, in step S4, it should be noted that:
[0077] Reference Figure 7The figure shows the process of posture recognition in the video. The detector outputs the classification of the target object and the accuracy of posture recognition. Combined with the time series information of the image, the posture information of the pig group is counted. This experiment recognizes and counts the posture of the pigs in the entire pen, and does not involve the recognition and statistics of a specific pig.
[0078] The structure of the pig posture detector in this step is as follows:
[0079] The recognition model is based on the CNN architecture, which is built on a 6-layer CNN (5 layers for extracting feature vectors and 1 layer for softmax regression) and SVM classifier structure. The process basically consists of two parts (refer to Figure 7 Schematic diagram): a 5-layer CNN network structure for generating feature vectors and a layer of SVM classifier for result prediction. CNN can process high-dimensional data and extract features at the same time. There are various fields of image detection applications of improved CNN models, but traditional CNN model training requires a lot of time and samples, which has certain limitations on experimental conditions. The CNN-SVM model in this paper combines the advantages of two models:
[0080] (1) Due to the properties of CNN pooling and convolution, the extracted feature vectors are not easy to fit;
[0081] (2) The feature vector extracted by CNN is more scientific than simple projection, direction and center of gravity;
[0082] (3) The fitting ability of the actual overall model can be controlled by using different convolutions, pooling, and the size of the final output feature vector;
[0083] (4) The powerful classification and generalization capabilities of the SVM classifier were utilized to achieve a more accurate assessment of the multi-postures of live pigs with a small sample size.
[0084] In the model of this paper, CNN consists of two convolutional layers, two pooling layers, a fully connected layer and a softmax regression layer. A SVM classifier is connected after the first fully connected layer to realize the classification and recognition of objects. First, the text data enters the first convolutional layer C1 to extract the feature vector, and then enters the first pooling layer S1 for data dimensionality reduction processing; the next step is that the data enters the second convolutional layer C2 for data feature extraction, and then enters the second pooling layer S2 for dimensionality reduction processing; finally, the feature vector is output through the first fully connected layer FC1; the model sets the convolution kernel size of the convolution layer to 5*5, the step size is 1, and the convolution kernel size of the pooling layer is 2*2. Dropout is set to prevent overfitting. When training the CNN model, the softmax regression layer is used to reversely train the CNN, and the error cost is set in the form of cross entropy. The AdamOptimizer algorithm is used to optimize the objective function to make the network more efficient. Finally, after the model is trained, the experimental text data is input to obtain the feature vector from the first fully connected layer of CNN, and it is sent to the SVM classification for data classification. The network structure is shown in Figure 7.
[0085] In this embodiment, the above-mentioned CNN-SVM model is trained and tested. This experiment has two steps. In order to initialize the weight parameters between each layer in the detection network, 9000 depth images collected on-site are randomly selected and extracted to accurately locate and extract 85500 experimental data. In the first step, 85425 sets of experimental data are used for training to train the CNN model. During the training, not only forward training is performed, but also reverse training is performed using the softmax regression layer. SVM classification is not used at this time. Finally, the weight parameters between each layer of the trained model are obtained, and the model is saved.
[0086] In the second step, the trained model is used to estimate the posture score and 69194 sets of experimental data in the extracted data set are used for testing. First, the experimental data is input into the final trained model. At the same time, the feature vector extracted by the first fully connected layer is input into the SVM classifier for posture recognition. The flow chart of the training mode and the scoring test mode is shown in Figure 8.
[0087] Example 2
[0088] In order to train and test the posture detection model in this article, this study selected 9,000 images collected on-site and used the above-mentioned image processing technology to extract experimental data. A total of 95% of the experimental data of live pigs were correctly located and extracted, with a total of 85,540. However, other objects in the fence (pig troughs and noise shadows in the image) were mistakenly identified as pigs and information was extracted, and experimental information of the pigs in the image could not be extracted. These were all considered erroneous information extraction, with an error rate of 5% and a total of 4,500.
[0089] In order to compare the differences between the posture detection model in this paper and the SVM and CNN posture models in pig posture recognition, this experiment used the same training and test data for the three models. This experiment used 85425 sets of experimental data for training and 69194 sets of experimental data for testing. The test amount of the model was 90% of the training amount. The penalty coefficient C of CNN_SVM and SVM was set to 0.9, and kernel = 'Linear'.
[0090] The size of the CNN convolutional layer and pooling layer in the posture detection model in this paper is the same as that of CNN. Dropout is set to prevent overfitting. At the same time, the softmax regression layer is used to reversely train the CNN, and the error cost is set in the form of cross entropy. The AdamOptimizer algorithm is used to optimize the objective function. CNN, SVM and the posture detection model (CNN-SVM) in this paper are tested respectively. In order to ensure the accuracy of the experimental results, the experimental results are obtained through reverse experiments as shown in Table 2:
[0091] Table 2: Different models recognize multiple poses.
[0092]
[0093]
[0094] This embodiment uses different methods and the same amount of experimental data to detect the posture of live pigs. The accuracy of the model (CNN-SVM), SVM and CNN in recognizing posture is 94.6368%, 92.2175% and 90.5396% respectively. It can be seen that the method of this paper has a significant improvement in the accuracy of model posture recognition compared with traditional SVM and CNN, and the accuracy of posture recognition is 2.4193% and 4.0972% higher than the two models (SVM and CNN) respectively. The reason for this may be that the model (CNN-SVM) of this experiment combines the advantages of both SVM and CNN models, using CNN to extract feature vectors that are not easy to fit and more scientific, and SVM's powerful ability to classify and generalize, so that the accuracy of pig posture recognition in a certain amount of sample model posture has been improved to a certain extent. In order to further verify the reliability of the model of this paper, different data amounts and data of different breeds of pigs are used to train three models and verify them in subsequent studies.
[0095] Example 3
[0096] In order to improve the performance of the CNN-SVM detector in recognizing the multi-classification of pig postures in the above embodiment, that is, to score the postures after recognition, this embodiment adopts standard precision (P), recall rate (R), and F1 value, and the calculation formula is as follows:
[0097]
[0098] Where TP represents the number of positive examples predicted by the detector and are actually positive; FP represents the number of negative examples predicted by the detector; FN represents the number of positive examples predicted by the detector and are actually positive; TN represents the number of negative examples predicted by the detector and are actually negative. In multi-classification, the classification accuracy (P) of each category is the vector of the fraction of all frames that correctly define the category.
[0099] Similarly, recall is defined for each class as the fraction of events where all frames are of that class and the correct detection is declared as that class. Accuracy (ACC) represents the ratio of the number of accurately recognized poses to the total number of poses. Although accuracy is an intuitive measure of the performance of a detection, it cannot specifically reflect the classification of a specific class, and it is not applicable to cases where the classification data is asymmetric. F1 is an indicator that takes both precision and recall into account. It can more comprehensively evaluate the indicators of a classifier, and its range of adaptability is also wider than ACC.
[0100] At the same time, in the case of multi-classification, it is generally expressed based on the confusion matrix (error matrix), the diagonal of which indicates the number of consistent model predictions and data labels, and the sum of the diagonal divided by the total number of test sets is the accuracy rate. The larger the diagonal number, the better. The deeper it is in the visualization result, the more accurate the result. In general, it is hoped that the diagonal data is as large as possible, and the non-diagonal numbers are as low as possible. The confusion matrix data of this embodiment are shown in Table 3 and Fig. 9 As shown in the table, the overall posture recognition accuracy of the model is 94.63%.
[0101] In the model of this experiment, the correct recognition rate for the "STD" and "SIT" posture detection is relatively high, and the correct recognition rate for "STR" is relatively low. The specific five postures have different recognition accuracy.
[0102] Table 3: Multi-classification confusion matrix of five postures of pigs.
[0103]
[0104] ROC and AUC are also often used in image classification in machine learning. The ROC curve is a curve with false positive rate as the horizontal axis and true positive rate as the vertical axis. Generally speaking, the closer the ROC curve is to the upper left corner (0, 1), the better the classification performance of the classifier. However, the ROC curve often cannot indicate which classifier is more effective. AUC, as a numerical value, represents the area under the ROC curve. Its value range is (0.5~1). The larger the AUC value, the better the classifier. The above Macro is a macro calculation method that calculates the final value by averaging. Micro is a micro calculation method that needs to consider the values of each dimension when calculating. These two calculation methods can reflect the performance of the classifier from different aspects. Fig.10 The AUC value is equal to the area. Class0 to Class4 represent "STD", "SIT", "STR", "VTR" and "LTR" respectively. It shows that the "STD" and "LTR" classifiers of the pig posture classifier have better performance, and their AUC values are 0.9969 and 0.9967 respectively, but the performance of the "SIT", "STR" and "VTR" classifiers is slightly worse, and their AUC values are 0.9790, 0.9355 and 0.9795 respectively.
[0105] This experiment not only further refined the traditional automatic scoring of lying posture (lying flat and lying on the side), but also added the automatic scoring of "standing posture" and "sitting posture" to further improve the automatic scoring. The overall posture detection accuracy of the model is about 94.6%, showing acceptable high performance. However, in posture detection, about 1% of the postures of "STD" and "SIT" are misclassified as other postures, and the correct detection rates of the other three postures "STR", "VTR" and "LTR" are about 12%, 11% and 7% respectively. It is because the two postures of "STD" and "SIT" have a greater degree of distinction from other postures than the other three postures, resulting in a large difference in the accuracy of posture recognition classification. The AUC values of the "STD" and "LTR" classifiers of the pig posture classifier are 0.9969 and 0.9967 respectively, and the performance of these two classifiers is good. The performance of the “SIT”, “STR”, and “VTR” classifiers is slightly worse, with AUC values of 0.9790, 0.9355, and 0.9795, respectively. This is because the inter-class gap between the “STD” and “LTR” postures is larger than the inter-class gap between the “SIT”, “STR”, and “VTR” postures.
[0106] The deep image processing and deep learning technology used in this embodiment further subdivides the lying posture into three postures: sternum flat, abdomen flat and side-lying. At the same time, two postures "STD" and "SIT" are added, further increasing the classification types. The Taihuyuan Inspection Station in Lin'an, Hangzhou, Zhejiang was selected. The number of pigs in each pigpen is (10 to 15), the pig breed is Landrace pigs, and the pig age is 70 days (fattening). Using image processing technology from the depth map, the depth distance of the pig's shoulder and hip, the ratio of the shoulder and hip depth distance, the ratio of the area of the convex hull to the pig's boundary, and the ratio of the perimeter of the convex hull to the pig's boundary are calculated as training data from the posture detection model (CNN-SVM) of this article for posture detection and classification. The trained model is then used to predict the posture of pigs in the new depth image, and the posture classification of pigs has good accuracy, precision and recall.
[0107] It should be appreciated that embodiments of the present invention may be implemented or enforced by computer hardware, a combination of hardware and software, or by computer instructions stored in a non-transitory computer-readable memory. The method may be implemented in a computer program using standard programming techniques - including a non-transitory computer-readable storage medium configured with a computer program, wherein the storage medium so configured causes the computer to operate in a specific and predefined manner - according to the methods and drawings described in the specific embodiments. Each program may be implemented in a high-level procedural or object-oriented programming language to communicate with a computer system. However, if desired, the program may be implemented in an assembly or machine language. In any case, the language may be a compiled or interpreted language. In addition, the program may be run on a programmed ASIC for this purpose.
[0108] Furthermore, the operations of the processes described herein may be performed in any suitable order unless otherwise indicated herein or otherwise clearly contradicted by context. The processes described herein (or variations and / or combinations thereof) may be performed under the control of one or more computer systems configured with executable instructions, and may be implemented as code (e.g., executable instructions, one or more computer programs, or one or more applications) that is executed collectively on one or more processors, by hardware, or a combination thereof. The computer program includes a plurality of instructions that may be executed by one or more processors.
[0109] Further, the method can be implemented in any type of computing platform that is operably connected to a suitable computer, including but not limited to a personal computer, a minicomputer, a mainframe, a workstation, a network or distributed computing environment, a separate or integrated computer platform, or in communication with a charged particle tool or other imaging device, etc. Aspects of the present invention can be implemented in machine-readable code stored on a non-transitory storage medium or device, whether removable or integrated into a computing platform, such as a hard disk, an optical read and / or write storage medium, a RAM, a ROM, etc., so that it can be read by a programmable computer, and when the storage medium or device is read by the computer, it can be used to configure and operate the computer to perform the process described herein. In addition, the machine-readable code, or part thereof, can be transmitted via a wired or wireless network. When such media includes instructions or programs that implement the steps described above in conjunction with a microprocessor or other data processor, the invention described herein includes these and other different types of non-transitory computer-readable storage media. When programmed according to the methods and techniques described in the present invention, the present invention also includes the computer itself. The computer program can be applied to input data to perform the functions described herein, thereby converting the input data to generate output data stored in a non-volatile memory. The output information can also be applied to one or more output devices such as a display. In a preferred embodiment of the present invention, the converted data represents a physical and tangible object, including a specific visual depiction of the physical and tangible object produced on a display.
[0110] As used in this application, the terms "component", "module", "system", etc. are intended to refer to a computer-related entity, which can be hardware, firmware, a combination of hardware and software, software, or software in operation. For example, a component can be, but is not limited to: a process running on a processor, a processor, an object, an executable file, a thread in execution, a program, and / or a computer. As an example, an application running on a computing device and the computing device can both be components. One or more components can exist in a process and / or thread in execution, and a component can be located in a computer and / or distributed between two or more computers. In addition, these components can be executed from various computer-readable media having various data structures thereon. These components can communicate in a local and / or remote process manner, such as according to a signal having one or more data packets (e.g., data from a component that interacts with another component in a local system, a distributed system, and / or interacts with other systems in a signal manner through a network such as the Internet).
[0111] It should also be understood that the present invention is described through implementation methods, and the embodiments are only clear and complete descriptions of the technical solutions proposed in the claims of the present invention, that is, explanations of the claims. Therefore, when judging whether the technical solutions recorded in the specification of the present invention are sufficiently disclosed, full consideration should be given to the core essence of the solutions defined by the claims. In the specification, there must be other technical problems that are not related to the core technical problems proposed in this embodiment. The corresponding technical features and technical solutions do not belong to the essence of this embodiment and are non-essential technical features. Therefore, they can be referred to as implicit disclosures. Those skilled in the art can fully implement them in combination with existing technologies and common knowledge. Therefore, there is no need to describe them in detail.
[0112] It should be noted that the above embodiments are only used to illustrate the technical solutions 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 solutions of the present invention can be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should be included in the scope of the claims of the present invention.
Claims
1. A method for multi-posture recognition and scoring of pig groups using depth images and CNN-SVM, characterized by: The following steps are included: Collect the initial data set; Define and describe the various postures of pigs; Performing depth image processing on the initial data set, obtaining the shoulder-hip depth distance, shoulder-hip depth distance ratio, ratio of the area of the convex hull to the boundary, and ratio of the perimeter of the convex hull to the boundary of the target pig in each posture as input data; Construct a CNN-SVM detector for pig posture detection and classification, use the input data as training data for the detector, obtain weight parameters between each layer of the model after training, and save the model; The image data of the target group of pigs to be identified is used to obtain feature vectors from the first fully connected layer of the CNN model, which are then sent to the SVM classification for data classification to complete posture recognition. The posture recognized by the CNN-SVM detector is scored using a multi-classification evaluation index; the multi-classification evaluation index includes standard precision P, recall rate R and F1 value, and the formula is as follows: Where TP represents the number of positive examples predicted by the detector and actually positive examples; FP represents the number of negative examples predicted by the detector; FN represents the number of positive examples predicted by the detector as negative examples; TN represents the number of negative examples predicted by the detector as negative examples. The multi-classification evaluation index also includes ROC curve and AUC value. The AUC value is the area under the ROC curve, ranging from 0.5 to 1. The larger the value, the higher the classification recognition score. The extraction of the depth distance of the shoulder and hip includes the following steps: The image after watershed segmentation is cropped based on the regional attributes; Find the convex polygon of the cropped single pig image, and then find the minimum circumscribed rectangle; Get the horizontal angle in the top view image. If the horizontal angle is greater than 1, rotate each pig image accordingly to adjust it to the horizontal. The rotation angle formula is as follows: Among them, T0(x1,y1) and T1(x2,y2) are the two vertices of an edge of the convex envelope, respectively. i (x t ,y t ) are vertices of the convex envelope, (t=1,2,...,n), (x' t ,y' t ) is T i (x t ,y t ) is the coordinate after rotation by θ; The average value of the depth distance from 1 / 5 to 2 / 5 of the pig's body is taken as its depth value. The depth information of the hip is collected in the same way as above, from about 6 / 10 to 8 / 10, and the average value is taken as its depth distance. The shoulder depth distance calculation formula is as follows: Among them, D s-final The depth distance after taking the average of the shoulder, (D s-(i) ) body(1 / 5~2 / 5 ) is the depth distance from the pig's head to the shoulder at 2 / 5 of the whole body, n is the number of shoulder depth distance value points, thrshold is the set threshold, and the hip acquisition principle is the same as the shoulder.
2. The method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM as claimed in claim 1, characterized in that: The depth image processing comprises the following steps: Extract the target object through Grabcut image segmentation, first mark the target object and perform watershed segmentation; Based on the segmented pig image, the pig is adjusted to a horizontal position through the minimum circumscribed rectangle to obtain the depth information of the shoulder and hip; The segmented pig images are binarized, and the perimeter and area of the convex hull of each pig in each posture and the pig boundary are found and calculated.
3. The method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM as claimed in claim 1, characterized in that: The method includes extracting the area, perimeter and boundary of the convex hull of each pig based on image binarization, and includes the following steps: The convex hull definition formula is as follows: p=[p1,p2,...,pn]λ=λ1p1+λ2p2+...+λnpn(λ1+λ2+...+λn=1,min{λ1,λ2,...,λn}≥0) Among them, λ is a vector composed of n components, that is, as the coefficients of each point, S = {p1, p2, ..., pn} is the point set in the 2D space, P is the convex hull, and the boundary of the target in image processing is the set of pixel coordinates of the boundary; Based on the definition, the boundary, perimeter and area of the convex hull of the pig are calculated respectively. The calculation formula is as follows: Among them, S area Expressed as the convex hull area, s 0, s 1,..., s n represents the vertex of the convex envelope, Ls1-s0 represents the length of the corresponding edge between the two vertices of the convex envelope, θs2-s1 represents the angle corresponding to the edge s2-s1 of the convex envelope in the triangle s0s1s2, L C-girth represents the perimeter of the convex hull, L border represents the boundary length, (x b-0 ,y b-0 ),(x b-1 ,y b-1 ),...,(x b-m ,y b-m ) represents the pixel coordinates of points on the boundary.
4. The method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM as claimed in claim 1, characterized in that: In the CNN-SVM detector, the CNN has two convolutional layers, two pooling layers, a fully connected layer, and a softmax regression layer. An SVM classifier is connected after the first fully connected layer to realize object classification and recognition.
5. The method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM as claimed in claim 1, characterized in that: The CNN-SVM detector includes the following recognition steps, The text data first enters the first convolutional layer C1 to extract feature vectors; Then enter the first pooling layer S1 for data dimensionality reduction processing; Next, the data enters the second convolutional layer C2 for data feature extraction, and then enters the second pooling layer S2 for dimensionality reduction; Finally, the feature vector is output through the first fully connected layer FC1.
6. The method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM as claimed in claim 1, characterized in that: The CNN-SVM detector includes the following training steps, The detector model sets the convolution kernel size of the convolution layer to 5*5 and the step size to 1, and the convolution kernel size of the pooling layer to 2*2. Dropout is set to prevent overfitting. When training the CNN model, the softmax regression layer is used to reversely train the CNN. The error cost is set in the form of cross entropy, and the AdamOptimizer algorithm is used to optimize the objective function. Finally, after the model is trained, the experimental text data is input to obtain the feature vector from the first fully connected layer of CNN, and it is sent to the SVM classification for data classification.
7. The method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM as claimed in claim 1, characterized in that: The definition and description of various postures of live pigs include the definition of 5 lying postures of live pigs, namely A for standing posture STD, B for sitting posture SIT, C for sternal recumbent posture STR, D for abdominal recumbent posture VTR, and E for lying flat posture LTR.
8. The method for multi-posture recognition and scoring of a group of pigs using depth images and CNN-SVM as claimed in claim 1, characterized in that: The collecting of the initial data set comprises: Microsoft's Azure Kinect DK depth camera was used to collect data continuously for 8 days. The average indoor temperature was 22°C and the humidity range was 55%-70%. The camera was installed in a top-view mode and included a depth camera, RGB camera IMU, and a multi-array microphone.
