A method for group-rearing pig identity recognition and health monitoring based on computer vision
Through computer vision technology, the automation of pig identity identification and health monitoring is achieved, the shortcomings of RFID and traditional manual observation methods are solved, the breeding efficiency and abnormal detection capabilities are improved, and economic losses are reduced.
Patent Information
- Application Number
- CN202111588174.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-23
- Publication Date
- 2024-12-10
- Estimated Expiration
- 2041-12-23
AI Technical Summary
The prior art has problems of harm, high cost and easy shedding in pig identity identification and health monitoring. Traditional manual observation methods are difficult to detect abnormal situations in real time, resulting in low breeding efficiency and economic losses.
Using computer vision-based group health pig identity recognition and health monitoring methods, we realize automated pig face recognition and health status monitoring through image acquisition, preprocessing, convolutional neural network feature extraction and neural network classifier, combined with improved object detection algorithm Perform joint optimization.
Contactless and automated pig identity identification and health monitoring are achieved, labor costs are saved, breeding efficiency is improved, real-time detection of abnormal situations is enhanced, and the impact of environmental factors on pig houses is reduced.
Smart Images

Figure CN114255357B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of pig identity recognition and health monitoring, and relates to a method for group-reared pig identity recognition and health monitoring based on computer vision. Background Art
[0002] Pork is an indispensable consumer product in people's daily life, and its production and quality are closely related to people's healthy life. At present, more than half of the world's pigs are raised and consumed in my country. Although my country has formed a high-density, centralized pig farming system and the pig farming industry has made great progress, there are still many problems such as low pork quality, low market rate, low production efficiency, and high pig farming costs. The overall development of my country's pig farming industry is that the number of small-scale pig farmers is gradually decreasing, and the production scale of large-scale farms is expanding. However, compared with Western countries, my country's pig farming industry is inefficient. At present, my country mainly uses RFID technology to realize the identity identification of pigs and traditional manual observation methods to monitor the health status of pigs. RFID is harmful to pigs and has a relatively high cost. It is easy to fall off during use and easy to breed bacteria and cause complications. RFID is easy to be impersonated in management.
[0003] In addition, due to the high density of large-scale breeding technology, the environmental conditions in the house are often poor due to improper environmental control facilities in the house, which cannot meet the normal physiological functions of pigs. Too high or too low temperature, excessive humidity, and dampness in the house usually cause symptoms. Factors such as poor ventilation and accumulation of harmful gases make pigs feel uncomfortable or have a bad rest. The light is too strong, the pigs are in an excited state, and restlessness can easily cause abnormal behavior of pigs, thus affecting productivity. At the same time, due to the increase in breeding density, when a pig has an infectious disease such as plague, it may quickly spread to other pigs, so the real-time detection of abnormal conditions is increasingly required. If the abnormal situation is not discovered in time, it may cause serious economic losses. The traditional manual observation method is used to monitor the health status of pigs. Due to the limitations of the environment and the time and energy of the breeders, it is easy to ignore abnormal behaviors in the breeding process during the observation process. Summary of the invention
[0004] In order to solve the above technical problems, the purpose of the present invention is to provide a method for group-raising pig identity recognition and health monitoring based on computer vision, which monitors the health status of pigs' behavior through an automated method and promptly detects abnormal conditions of pigs.
[0005] The present invention provides a method for group-raising pig identity recognition and health monitoring based on computer vision, comprising the following steps:
[0006] Step 1: Collect pig image data for training pig face recognition and pig health monitoring models;
[0007] Step 2: Preprocess the images, remove abnormal images, use the structural similarity index to measure the similarity between images, remove images with high similarity, and make the image dataset into a pig face recognition dataset and a pig health monitoring dataset;
[0008] Step 3: Based on the convolutional neural network, the pig face recognition dataset is subjected to pig face feature extraction to obtain a pig face fusion feature map; the pig body detail feature is extracted from the pig health monitoring dataset to obtain a pig body fusion feature map;
[0009] Step 4: Construct a pig identification classifier based on a neural network to perform pig face recognition and determine the pig's identity information;
[0010] Step 5: Construct a pig health monitoring model based on the improved target detection algorithm to detect the health status of pigs and determine the health status of pigs;
[0011] Step 6: Jointly optimize the two tasks of pig face recognition and pig health monitoring;
[0012] Step 7: Combining the pig identity and health status identified in steps 4, 5, and 6, output the pig identity and health status.
[0013] In the method for group-raising pig identity recognition and health monitoring based on computer vision of the present invention, step 1 is specifically as follows:
[0014] Step 1.1: Use an anti-shake lens to record the videos required for the training data set. Select pigs of three sizes: large, medium, and small, and three states: healthy, sub-healthy, and sick. Record a video for each pig, focusing on the pig's face, body, and fur color. When moving the camera, the pig is 0.3 to 3 meters away from the lens.
[0015] Step 1.2: Cut the captured video into frames and extract one frame of image every 5 frames as training data;
[0016] Step 1.3: Add black pixel values to the edges of the acquired 1920×1080 resolution image to make its aspect ratio 2:1. After completion, the pixel value becomes 2048×1024.
[0017] In the method for group-raising pig identity recognition and health monitoring based on computer vision of the present invention, step 2 is specifically as follows:
[0018] Step 2.1: Manually filter out abnormal images that do not contain or only contain a small part of the pig face;
[0019] Step 2.2: After removing abnormal images, data cleaning is performed. For the case where the similarity between consecutive image frames is too high, the structural similarity index is used to measure the similarity between images. Each image is compared with the subsequent image until enough differences are found. Images with too high similarity are eliminated. Considering the variance, covariance and average intensity between two images, the calculation formula is as follows:
[0020]
[0021] Where S(x,y) represents the similarity between the two input images x and y; μ x and μ y are the average values of the pixels of the two input images, σ x and σ y is the variance of the pixels of the two input images, σ xy is the covariance of the pixels of the two images; c1 and c2 are constants, given by c z =(k z ×L) 2 , z=1,2, where k is a constant factor and L is the dynamic range of the image pixel value; k1 and k2 range from 0.01 to 0.05; S(x,y) ranges from 0 to 1. When S(x,y) is less than 0.75, the two images are considered different;
[0022] Step 2.3: After data cleaning, every two images are spliced to obtain a square image with a resolution of 2048×2048. The obtained image is scaled and the resolution is finally converted to 416×416.
[0023] Step 2.4: Use LabelImg software to label the pig face and pig body in the image respectively to obtain the pig face recognition dataset and pig health monitoring dataset.
[0024] In the method for group-raising pig identity recognition and health monitoring based on computer vision of the present invention, step 3 is specifically as follows:
[0025] Step 3.1, data set expansion:
[0026] The pig face recognition dataset and the pig health monitoring dataset are respectively expanded by adding illumination changes and salt and pepper noise to the images in the corresponding datasets, and then adding the newly formed images to the datasets;
[0027] Step 3.2, pig face feature extraction: Based on the pig face recognition dataset, the pig face features are extracted through the CSPDarknet53 network, and the last three layers of feature maps are fused using spatial attention and channel attention to obtain the pig face fused feature map;
[0028] Step 3.3, pig body detail feature extraction: Based on the pig health monitoring dataset, the pig body detail features are extracted through the CSPDarknet53 network, and the last three layers of feature maps are fused using spatial attention and channel attention to obtain the pig body fused feature map.
[0029] In the method for group-raising pig identification and health monitoring based on computer vision of the present invention, the step 4 sends the pig face fusion feature map to the classification network, and after confidence sorting, obtains the identity information of each pig, specifically:
[0030] Step 4.1: Pig face positioning, using the fused feature map output by CSPDarknet53, and quickly generating pig face candidate regions through the pig face detection algorithm;
[0031] Step 4.2: The detected pig face candidate area image is subjected to ROI pooling and deep convolutional neural network to obtain pig face features, and then the feature vector of the pig face is obtained through the fully connected layer;
[0032] Step 4.3: Perform L2 regularization on the feature vector of the pig face, filter out the feature vector of the effective feature pig face, calculate the Triplets Loss, and obtain the gradient to optimize the network parameters;
[0033] Step 4.4: By calculating the Euclidean distance between the feature vectors of the real-time collected pig face image and the pig face recognition data set, the difference between the two images is represented, and finally the pig face recognition is performed to determine the pig's identity information.
[0034] In the method for group-raising pigs identification and health monitoring based on computer vision of the present invention, step 5 is specifically as follows:
[0035] Step 5.1: Use the YOLOX backbone network as the feature extraction network, and extract features from the input image in the CSPDarknet53 network;
[0036] Step 5.2: Based on the original YOLOX network, the output of the lowest-dimensional feature scale in the three-scale output of the YOLOX network is removed and changed to a two-scale output; at the same time, the remaining two scale features are further integrated using the channel attention mechanism and the spatial attention mechanism to obtain a pig health monitoring model with an improved target detection algorithm;
[0037] Step 5.3: Use the pig health monitoring model with improved target detection algorithm to infer the current health status of the pigs, obtain the rectangular coordinates and health status confidence of the pigs, filter out the targets with confidence less than 0.5, and obtain the health status of the pigs.
[0038] In the method for group-raising pig identity recognition and health monitoring based on computer vision of the present invention, step 6 is specifically as follows:
[0039] The same feature extraction network is used for pig face feature extraction and pig body detail feature extraction. During optimization, the pig face recognition loss and health monitoring loss are added according to different weight coefficients for joint optimization, providing adaptive learning rates for different loss function items. The calculation formula is:
[0040]
[0041] Among them, θ i is the updated neural network parameter, F tt is a diagonal matrix, where the i-th matrix element corresponds to the gradient along the i-th direction from time 0 to time t The accumulation of squares, G tt is a diagonal matrix, where the i-th matrix element corresponds to the gradient along the i-th direction from time 0 to time t The accumulation of squares; lr is the learning rate, is the gradient of the loss function to the network parameters; divide the learning rate in the formula by a constant and where ∈ = 10 -8 Prevent division by zero divergence; f is the pig identity recognition loss function, g is the pig health monitoring loss function, and g is the loss function in YOLOX;
[0042] By minimizing the joint loss of f and g, the neural network parameters θ are i Updates have been made to achieve better pig face recognition and health monitoring results.
[0043] In the method for group-raising pigs identification and health monitoring based on computer vision of the present invention:
[0044] The pig identification process is divided into two parts: pig face detection and pig face recognition. The pig identification loss f consists of two parts:
[0045] f=L det +L rec
[0046] Among them, the pig face detection loss function L det The loss function g for pig health monitoring is the same as the loss function L for pig face recognition. rec To detect whether it is a pig face, the Triplet Loss in the face recognition model FaceNet is used as the pig face recognition loss function L rec .
[0047] In the computer vision-based group-raising pig identity recognition and health monitoring method of the present invention, the health status of the pigs includes three types: healthy, sub-healthy and sick. When the output result is sub-healthy or sick, a warning will be issued.
[0048] The computer vision-based group pig identification and health monitoring method of the present invention has at least the following beneficial effects:
[0049] 1) The non-contact intelligent video monitoring system will not have any impact on the pigs. At the same time, it can perform video monitoring, pig face recognition and health monitoring on the pigs, saving a lot of labor costs and improving breeding efficiency;
[0050] 2) Make full use of the extracted high-dimensional and low-dimensional features for pig face recognition, introduce an attention module between the low-dimensional and high-dimensional features, and finally splice them to form a new feature map to achieve accurate and efficient pig identity recognition;
[0051] 3) The attention mechanism is introduced into pig health monitoring to increase the extraction of detailed features, reduce the scale, and improve the detection speed and accuracy;
[0052] 4) Use multi-task learning to further reduce the overfitting degree of the model and improve the generalization ability of the model;
[0053] 5) The entire process is completed automatically and no human intervention is required. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 This is a flow chart of a method for group-raising pig identity recognition and health monitoring based on computer vision of the present invention;
[0055] Figure 2 It is a schematic diagram of the pig face recognition implementation method of the present invention;
[0056] Figure 3 This is a schematic diagram of the pig health monitoring method of the present invention. DETAILED DESCRIPTION
[0057] like Figure 1 As shown, a method for group-raising pig identity recognition and health monitoring based on computer vision of the present invention comprises the following steps:
[0058] Step 1: Collect pig image data for training pig face recognition and pig health monitoring models; Step 1 specifically includes:
[0059] Step 1.1: Use an anti-shake lens to record the videos required for the training data set. Select pigs of three sizes: large, medium, and small, and three states: healthy, sub-healthy, and sick. Record a video for each pig, focusing on the pig's face, body, and fur color. When moving the camera, the pig is 0.3 to 3 meters away from the lens.
[0060] Step 1.2: Cut the captured video into frames and extract one frame of image every 5 frames as training data;
[0061] Step 1.3: Add black pixel values to the edges of the acquired 1920×1080 resolution image to make its aspect ratio 2:1. After completion, the pixel value becomes 2048×1024.
[0062] In the specific implementation, the data set collected in this step is used for network training and verification, and the test set uses real group-raising pig monitoring videos. Use the Canon 700D anti-shake lens to select pigs of three sizes, large, medium and small, and three states of health, sub-health and illness. Record a video for each pig for about one minute, focusing on the pig's face, body and hair color. When moving the pig, the distance from the lens varies from 0.3 to 3m, and the face and body areas of pigs of different sizes are collected. A total of 30 pigs were collected for the first time. Considering the short growth cycle and large changes of pigs, the second batch of data sets were collected after the experiment. Cut the video frames of the collected videos, and take out one frame every 5 frames as training data. 700 pictures can be captured for each pig. Add black pixel values to the edges of the obtained 1920×1080 resolution pictures to make its aspect ratio 2:1. After completion, the pixel value becomes 2048×1024. The status of the collected pigs is shown in the following table:
[0063]
[0064]
[0065] Step 2: Preprocess the images, remove abnormal images, use the structural similarity index to measure the similarity between images, remove images with high similarity, and make the image data set into a pig face recognition data set and a pig health monitoring data set. Step 2 is specifically as follows:
[0066] Step 2.1: Manually filter out abnormal images that do not contain or only contain a small part of the pig face;
[0067] Step 2.2: After removing abnormal images, data cleaning is performed. For the case where the similarity between consecutive image frames is too high, the structural similarity index is used to measure the similarity between images. Each image is compared with the subsequent image until enough differences are found. Images with too high similarity are eliminated. Considering the variance, covariance and average intensity between two images, the calculation formula is as follows:
[0068]
[0069] Where S(x,y) represents the similarity between the two input images x and y; μ x and μ y are the average values of the pixels of the two input images, σ x and σ y is the variance of the pixels of the two input images, σ xyis the covariance of the pixels of the two images; c1 and c2 are constants, given by c z =(k z ×L) 2 , z=1,2, where k is a constant factor and L is the dynamic range of the image pixel value; k1 and k2 range from 0.01 to 0.05; S(x,y) ranges from 0 to 1. When S(x,y) is less than 0.75, the two images are considered different;
[0070] Step 2.3: After data cleaning, every two images are spliced to obtain a square image with a resolution of 2048×2048. The obtained image is scaled and the resolution is finally converted to 416×416.
[0071] After cleaning, each pig has 200 to 300 pictures. Preprocessing is performed, and every two images are spliced to obtain a square picture with a resolution of 2048×2048. The obtained pictures are scaled and the resolution is converted to 416×416 to reduce the amount of calculation and improve the speed of model training.
[0072] Step 2.4: Use LabelImg software as a labeling tool to label the pig face and pig body in the image respectively to obtain the pig face recognition dataset and pig health monitoring dataset.
[0073] The original images of the two datasets are the same. When annotating, the pig face recognition dataset uses a rectangular frame to mark the pig face, and the live pig health monitoring dataset uses a rectangular frame to mark the pig's entire body.
[0074] Step 3: Based on the convolutional neural network, the pig face recognition data set is subjected to pig face feature extraction to obtain a pig face fusion feature map; the pig body detail feature is extracted from the pig health monitoring data set to obtain a pig body fusion feature map. The specific step 3 is as follows:
[0075] Step 3.1, data set expansion: the pig face recognition data set and the pig health monitoring data set are expanded respectively by adding illumination changes and salt and pepper noise to the images in the corresponding data sets, and adding the new images to the data sets;
[0076] Step 3.2, pig face feature extraction: Based on the pig face recognition dataset, the pig face features are extracted through the CSPDarknet53 network, and the last three layers of feature maps are fused using spatial attention and channel attention to obtain the pig face fused feature map;
[0077] Step 3.3, pig body detail feature extraction: Based on the pig health monitoring dataset, the pig body detail features are extracted through the CSPDarknet53 network, and the last three layers of feature maps are fused using spatial attention and channel attention to obtain the pig body fused feature map.
[0078] In specific implementation, CSPDarknet53 outputs a total of 5 levels of feature maps, and only the last three layers of feature maps are used for pig face feature extraction and pig body detail feature extraction. The input image size is 416×416, and the sizes of the last three layers of feature maps are 52×52, 26×26, and 13×13 respectively. The 52×52 feature map is concatenated and fused with the 26×26 and 13×13 feature maps through spatial attention and channel attention to obtain a new feature map, and finally concatenated and fused with the 13×13 feature map to obtain the final fused feature map, which is used to extract more fine-grained features.
[0079] Step 4: Construct a pig identification classifier based on a neural network to perform pig face recognition, determine the pig's identity information, and send the pig face fusion feature map to the classification network. After confidence ranking, obtain the identity information of each pig, specifically:
[0080] Step 4.1: Pig face positioning, using the fused feature map output by CSPDarknet53, and quickly generating pig face candidate regions through the pig face detection algorithm;
[0081] Step 4.2: The detected pig face candidate area image is subjected to ROI pooling and deep convolutional neural network to obtain pig face features, and then the feature vector of the pig face is obtained through the fully connected layer;
[0082] Step 4.3: Perform L2 regularization on the feature vector of the pig face, filter out the feature vector of the effective feature pig face, calculate the Triplets Loss, and obtain the gradient to optimize the network parameters;
[0083] Step 4.4: By calculating the Euclidean distance between the feature vectors of the real-time collected pig face image and the pig face recognition data set, the difference between the two images is represented, and finally the pig face recognition is performed to determine the pig's identity information.
[0084] Pig identification includes two modules: pig face location and pig face recognition. Figure 2As shown in the figure, based on the MTCNN (Multi-task convolutional neural network) idea, the fusion feature map output by CSPDarknet53 and the pig face detection algorithm are used to quickly generate the pig face candidate area; then the pig face candidate area image is subjected to ROIpooling and deep convolutional neural network to obtain the pig face features, and then the pig face features are mapped to a 128-dimensional feature space (Euclidean space) through a fully connected layer, thereby obtaining a 128-dimensional feature vector of the pig face; finally, Triplet Loss is used as a supervision signal, the gradient is calculated and the parameters of the neural network model are optimized, so as to obtain a better feature vector of the pig face data; then the Euclidean distance of the feature vector between the real-time collected pig face picture and the pig face data set is calculated to indicate the difference between the two pig face pictures, and finally the pig face recognition is performed to determine the identity information of the pig.
[0085] Step 5: Figure 3 As shown, a pig health monitoring model based on an improved target detection algorithm is constructed to detect the health status of live pigs and determine the health status of pigs. The specific step 5 is as follows:
[0086] Step 5.1: Use the YOLOX backbone network as the feature extraction network, and extract features from the input image in the CSPDarknet53 network;
[0087] Step 5.2: Based on the original YOLOX network, the output of the lowest-dimensional feature scale in the three-scale output of the YOLOX network is removed and changed to a two-scale output; at the same time, the remaining two scale features are further integrated using the channel attention mechanism and the spatial attention mechanism to obtain a pig health monitoring model with an improved target detection algorithm;
[0088] Step 5.3: Use the pig health monitoring model with improved target detection algorithm to infer the current health status of the pigs, obtain the rectangular coordinates and health status confidence of the pigs, filter out the targets with confidence less than 0.5, and obtain the health status of the pigs.
[0089] The present invention changes the three-scale output of YOLOX into a two-scale output. The specific details are as follows: after obtaining 52×52, 26×26, and 13×13 features in step 3, the channel attention mechanism and the spatial attention mechanism are further integrated to obtain a two-scale feature output, which effectively combines feature information of different scales and reduces the computational complexity of the model, and obtains the final health status through the detection head.
[0090] Step 6: Jointly optimize the two tasks of pig face recognition and pig health status monitoring to improve the accuracy of pig identity recognition and health status recognition, specifically:
[0091] The same feature extraction network is used for pig face feature extraction and pig body detail feature extraction. During optimization, the pig face recognition loss and health monitoring loss are added according to different weight coefficients for joint optimization, providing adaptive learning rates for different loss function items. The calculation formula is:
[0092]
[0093] Among them, θ i is the updated neural network parameter, F tt is a diagonal matrix, the i-th matrix element corresponds to the gradient along the i-th direction from time 0 to time t Accumulation of squares, G tt is a diagonal matrix, the i-th matrix element corresponds to the gradient along the i-th direction from time 0 to time t The accumulation of squares; lr is the learning rate, is the gradient of the loss function to the network parameters; divide the learning rate in the formula by a constant and where ∈ = 10 -8 Prevent division by zero divergence; f is the pig identity recognition loss function, g is the pig health monitoring loss function, and g is the loss function in YOLOX;
[0094] By minimizing the joint loss of f and g, the neural network parameters θ are i Update to get better recognition effect.
[0095] The pig identification process is divided into two parts: pig face detection and pig face recognition. The pig identification loss f consists of two parts:
[0096] f=L det +L rec
[0097] Among them, the pig face detection loss function L det The loss function g for pig health monitoring is the same as the loss function L for pig face recognition. rec To detect whether it is a pig face, the Triplet Loss in the open source face recognition model FaceNet is used as the pig face recognition loss function L rec .
[0098] Step 7: Output the pig's identity and health status based on the pig's identity and health status identified in Steps 4, 5, and 6. The pig's health status includes three types: healthy, sub-healthy, and sick. When the output result is sub-healthy or sick, a warning will be issued.
[0099] In the specific implementation, the pig face and pig health monitoring data sets obtained by step 1 and step 2 are used for training. The data sets are composed of image data and manual labels. The training program is run by combining steps 4, 5, and 6. During training, the image data and the manual labels are matched. After the training is completed, the pig identity recognition and health monitoring model is obtained. The above model is used to infer the images collected by the real-time monitoring of the pig farm camera. According to the inference results, the identity information, health status information and confidence probability of all pigs are obtained; the targets with confidence less than 0.5 are filtered out, and the pig identity and health status are output. The health status of pigs includes healthy, sub-healthy and sick. When the output result is sub-healthy or sick, a warning will be issued.
[0100] The above description is only a preferred embodiment of the present invention and is not intended to limit the concept of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for group-raising pig identity recognition and health monitoring based on computer vision, characterized in that: The following steps are involved: Step 1: Collect pig image data for training pig face recognition and pig health monitoring models; Step 2: Preprocess the images, remove abnormal images, use the structural similarity index to measure the similarity between images, remove images with high similarity, and make the image dataset into a pig face recognition dataset and a pig health monitoring dataset; Step 3: Based on the convolutional neural network, the pig face recognition dataset is subjected to pig face feature extraction to obtain a pig face fusion feature map; the pig body detail feature is extracted from the pig health monitoring dataset to obtain a pig body fusion feature map; Step 4: Construct a pig identification classifier based on a neural network to perform pig face recognition and determine the pig's identity information; Step 5: Construct a pig health monitoring model based on the improved target detection algorithm to detect the health status of pigs and determine the health status of pigs; Step 6: Jointly optimize the two tasks of pig face recognition and pig health monitoring; Step 7: Combining the pig identity and health status identified in steps 4, 5, and 6, output the pig identity and health status; The step 2 is specifically as follows: Step 2.1: Manually filter out abnormal images that do not contain or only contain a small part of the pig face; Step 2.2: After removing abnormal images, data cleaning is performed. For the case where the similarity between consecutive image frames is too high, the structural similarity index is used to measure the similarity between images. Each image is compared with the subsequent image until enough differences are found. Images with too high similarity are eliminated. Considering the variance, covariance and average intensity between two images, the calculation formula is as follows: Where S(x,y) represents the similarity between the two input images x and y; μ x and μ y are the average values of the pixels of the two input images, σ x and σ y is the variance of the pixels of the two input images, σ xy is the covariance of the pixels of the two images; c1 and c2 are constants, given by c z =(k z ×L) 2 , z=1,2, where k is a constant factor and L is the dynamic range of the image pixel value; k1 and k2 range from 0.01 to 0.05; S(x,y) ranges from 0 to 1. When S(x,y) is less than 0.75, the two images are considered different; Step 2.3: After data cleaning, every two images are spliced to obtain a square image with a resolution of 2048×2048. The acquired image is scaled and the resolution is finally converted to 416×416; Step 2.4: Use LabelImg software to label the pig face and pig body in the image respectively to obtain the pig face recognition dataset and pig health monitoring dataset; The step 5 is specifically as follows: Step 5.1: Use the YOLOX backbone network as the feature extraction network, and extract features from the input image in the CSPDarknet53 network; Step 5.2: Based on the original YOLOX network, the output of the lowest-dimensional feature scale in the three-scale output of the YOLOX network is removed and changed to a two-scale output; at the same time, the remaining two scale features are further integrated using the channel attention mechanism and the spatial attention mechanism to obtain a pig health monitoring model based on the improved target detection algorithm; Step 5.3: Use the pig health monitoring model based on the improved target detection algorithm to predict and infer the current health status of the pigs, obtain the rectangular coordinates and health status confidence of the pigs, filter out the targets with confidence less than 0.5, and obtain the health status of the pigs.
2. The method for group-raising pig identity recognition and health monitoring based on computer vision according to claim 1, characterized in that: The step 1 is specifically as follows: Step 1.1: Use an anti-shake lens to record the videos required for the training data set. Select pigs of three sizes: large, medium, and small, and three states: healthy, sub-healthy, and sick. Record a video for each pig, focusing on the pig's face, body, and fur color. When moving the camera, the pig is 0.3 to 3 meters away from the lens. Step 1.2: Cut the captured video into frames and extract one frame of image every 5 frames as training data; Step 1.3: Add black pixel values to the edges of the acquired 1920×1080 resolution image to make its aspect ratio 2:
1. After completion, the pixel value becomes 2048×1024.
3. The method for group-raising pig identity recognition and health monitoring based on computer vision according to claim 1, characterized in that: The step 3 is specifically as follows: Step 3.1, data set expansion: The pig face recognition dataset and the pig health monitoring dataset are expanded respectively by adding illumination changes and salt and pepper noise to the images in the corresponding datasets and then adding them to the datasets; Step 3.2, pig face feature extraction: Based on the pig face recognition dataset, the pig face features are extracted through the CSPDarknet53 network, and the last three layers of feature maps are fused using spatial attention and channel attention to obtain the pig face fused feature map; Step 3.3, pig body detail feature extraction: Based on the pig health monitoring dataset, the pig body detail features are extracted through the CSPDarknet53 network, and the last three layers of feature maps are fused using spatial attention and channel attention to obtain the pig body fused feature map.
4. The method for group-raising pig identity recognition and health monitoring based on computer vision according to claim 1, characterized in that: In step 4, the pig face fusion feature map is sent to the classification network, and after confidence ranking, the identity information of each pig is obtained, which is specifically: Step 4.1: Pig face positioning, using the fused feature map output by CSPDarknet53, and quickly generating pig face candidate regions through the pig face detection algorithm; Step 4.2: The detected pig face candidate area image is subjected to ROI pooling and deep convolutional neural network to obtain pig face features, and then the feature vector of the pig face is obtained through the fully connected layer; Step 4.3: Perform L2 regularization on the feature vector of the pig face, filter out the feature vector of the effective feature pig face, calculate the Triplets Loss, and obtain the gradient to optimize the network parameters; Step 4.4: By calculating the Euclidean distance of the feature vector between the real-time collected pig face image and the pig face recognition data set, the difference between the two images is represented, and finally the pig face recognition is performed to determine the identity information of the pig.
5. The method for group-raising pig identity recognition and health monitoring based on computer vision as claimed in claim 1, characterized in that: The step 6 is specifically as follows: The same feature extraction network is used for pig face feature extraction and pig body detail feature extraction. During optimization, the pig face recognition loss and health monitoring loss are added according to different weight coefficients for joint optimization, providing adaptive learning rates for different loss function items. The calculation formula is: Among them, θ i is the updated neural network parameter, F tt is a diagonal matrix, where the i-th matrix element corresponds to the gradient along the i-th direction from time 0 to time t The accumulation of squares, G tt is a diagonal matrix, where the i-th matrix element corresponds to the gradient along the i-th direction from time 0 to time t The accumulation of squares; lr is the learning rate, is the gradient of the loss function to the network parameters; divide the learning rate in the formula by a constant and where ∈ = 10 -8 Prevent division by zero divergence; f is the pig identity recognition loss function, g is the pig health monitoring loss function, and g is the loss function in YOLOX; By minimizing the joint loss of f and g, the neural network parameters θ are i Updates have been made to achieve better pig face recognition and health monitoring results.
6. The method for group-raising pig identity recognition and health monitoring based on computer vision as claimed in claim 5, characterized in that: The pig identification process is divided into two parts: pig face detection and pig face recognition. The pig identification loss f consists of two parts: f=L det +L rec Among them, the pig face detection loss function L det The loss function g for pig health monitoring is the same as the loss function L for pig face recognition. rec To detect whether it is a pig face, the Triplet Loss in the face recognition model FaceNet is used as the pig face recognition loss function L rec .
7. The method for group-raising pig identity recognition and health monitoring based on computer vision as claimed in claim 1, characterized in that: The health status of live pigs includes three types: healthy, sub-healthy and sick. When the output result is sub-healthy or sick, a warning will be issued.
