A sow body condition automatic scoring method based on dual-view point cloud
By combining SAM2 segmentation of point clouds from two perspectives with the DGCNN model and pregnancy status modulation, an efficient and stable assessment of sow body condition was achieved, solving the problems of unstable perspective and confusion of physiological stages in existing technologies, and improving the scoring accuracy and robustness.
Patent Information
- Application Number
- CN202611617908.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-19
- Publication Date
- 2026-11-27
AI Technical Summary
Existing technologies lack methods for simultaneously acquiring point clouds from both the back and rump, completing geometric fusion of the two perspectives in three-dimensional space, and combining prior knowledge of the sow's pregnancy status for body condition assessment, resulting in unstable scoring results and confusion of physiological stages.
A dual-view point cloud automated scoring method was adopted. Point clouds were constructed by SAM2 segmentation mask and cluster statistical filtering. A DGCNN model with shared weights was used for feature extraction and fusion. Pregnancy status modulation was combined for body condition assessment.
It achieves high-precision and stable sow body condition assessment, reduces data construction costs, and improves the robustness of the assessment and its adaptability to physiological stages.
Smart Images

Figure CN123182271A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of pig measurement technology, specifically to an automated scoring method for sow body condition based on dual-view point clouds. Background Technology
[0002] Body condition scoring in sows is a crucial tool for assessing their condition, guiding precise feeding, and ensuring reproductive performance. Traditional methods rely on manual visual inspection by pressing or ultrasonic measurement of backfat thickness, which is inefficient, prone to causing stress, and inconsistent. In recent years, non-contact body condition scoring methods based on machine vision have received considerable attention, primarily including methods based on two-dimensional images and methods based on three-dimensional point clouds.
[0003] CN 120726672A discloses a method for body condition scoring of sows based on two-dimensional images. This method uses a gestation bar and a smart camera to capture images of the sow's rump and back at a specific time period. The body condition score is divided into 5 levels according to the thickness of backfat. A SAM-ResNet50 model is constructed by combining SAM and ResNet50. After training and optimization, the body condition score of the sow to be evaluated is predicted. However, this scheme has the following problems: ① In terms of data dimensions, it scores based on two-dimensional image features, while the key criterion for body condition scoring is essentially three-dimensional geometric shape. Two-dimensional projection loses depth information, and changes in shooting angle will cause contour deformation, resulting in fluctuations in the scoring results of the same sow under different postures; ② In terms of perspective fusion, the images of the buttocks and back are independently input into the two-dimensional network for processing, without fusion of dual-perspective geometric information in three-dimensional space. The two complementary types of information, namely the overall shape of the trunk and the key areas of fat deposition in the buttocks, are not used together; ③ In terms of physiological priors, the sow's pregnancy status is not used as prior information in modeling. The body shape of sows varies significantly at different stages of pregnancy, and the morphological distribution of the same score is different at different physiological stages. Mixed modeling is prone to category confusion and a high rate of misjudgment of boundary body condition.
[0004] CN 110612921A discloses a monitoring system and method for sows in positioning pens. This method uses a guide rail and data acquisition device mounted directly above the sow's positioning pen to acquire color images, depth images, and thermal distribution images of the sow. Based on the color and depth images, three-dimensional point cloud data is obtained, leading to growth and health status scores such as body size, weight, and body temperature. The data acquisition device moves along the guide rail to achieve single-view time-sharing acquisition. However, this scheme has the following problems: ① In terms of acquisition method, single-view time-sharing acquisition along the guide rail cannot guarantee synchronous registration of the back and rump perspectives at the same time. Changes in sow posture during the acquisition interval make the geometric correspondence between the two perspectives unstable, affecting the consistent utilization of multi-view information; ② In terms of evaluation method, body condition acquisition relies on traditional measurement methods such as body size parameters, feature point and contour line extraction. Feature design relies on manual priors and does not use deep learning models to perform end-to-end body condition feature learning on the point cloud. Generalization ability is limited in complex breeding environments, and physiological prior information such as pregnancy status is also not introduced.
[0005] In summary, current technologies lack a method that can simultaneously acquire point clouds from both the back and rump, perform geometric fusion of the two perspectives in three-dimensional space, and combine this with prior knowledge of the sow's pregnancy status for body condition assessment. Summary of the Invention
[0006] To address the shortcomings of existing technologies, the purpose of this invention is to provide an automated sow body condition scoring method based on dual-view point clouds. This method integrates complementary information from dual-view point clouds, automatically constructs and purifies sow body point clouds using SAM2 segmentation masking and clustering statistical filtering, and builds an improved DGCNN model with shared weight dual-view fusion to achieve higher accuracy in sow body condition scoring.
[0007] To achieve the above objectives, the technical solution of the present invention is: an automated sow body condition scoring method based on dual-view point clouds, comprising the following steps: S1. Using depth cameras positioned directly above and diagonally behind the restraint bar, color and depth images of the sow's back and rump views are simultaneously acquired. A set of dual-view frame pairs is obtained through equally spaced frame extraction and posture filtering. S2. Perform pig body segmentation on each color image in the frame pair set to obtain a two-dimensional segmentation mask, map it to a depth map aligned with the color image after calibration, and back-project the pixels in the two-dimensional segmentation mask pixel by pixel according to the camera intrinsic parameters to obtain three-dimensional coordinates. After removing invalid depth and out-of-bounds points, obtain the preliminary point cloud of the back and the preliminary point cloud of the buttocks of each frame respectively. S3. Perform multi-level statistical filtering denoising on the preliminary point cloud of the back and the preliminary point cloud of the buttocks respectively, estimate the surface normal vector of each point in the denoised point cloud, perform centroid alignment and maximum norm normalization on the three-dimensional coordinates of each point, concatenate the normalized three-dimensional coordinates with the corresponding surface normal vectors, and sample to a fixed number of points to obtain a six-channel input point cloud of the back and buttocks; the three channels of the six-channel input point cloud are three-dimensional coordinates and the three channels are surface normal vectors; S4. Input the back six-channel input point cloud, the buttock six-channel input point cloud, and the pregnancy condition vector generated according to the gestation days of the sow at the time of collection into the trained body condition assessment model to obtain the frame-level continuous ordinal score corresponding to the frame pair. S5. According to the sow ear tag number and the assessment period, the frame-level continuous ordinal scores of multiple frames of the same sow in the same assessment period are aggregated by mean. The aggregated mean is rounded to obtain the sow body condition category number, and the body condition assessment result is output according to the sow body condition category number. The physical condition assessment model includes two shared network parameters: a dynamic graph convolutional neural network (DGCNN) feature extraction branch, a feature fusion module, an SE channel attention module, a pregnancy condition modulation module, and an ordinal classification head. The two DGCNN feature extraction branches independently construct adjacency graphs and extract viewpoint features from the six-channel input point cloud of the back and the six-channel input point cloud of the buttocks, respectively; the feature fusion module concatenates the two viewpoint features along the channel dimension and maps them into fused features; the SE channel attention module performs channel weighting on the fused features; the pregnancy condition modulation module generates scaling increment vectors and translation coefficient vectors based on the pregnancy condition vectors, and performs channel-wise residual affine modulation on the channel-weighted fused features; the ordinal classification head outputs the predicted probability of whether the corresponding body condition exceeds the upper limit of each body condition category based on the modulated features, sums the predicted probabilities, and obtains the frame-level continuous ordinal score.
[0008] Preferably, the multi-level statistical filtering denoising method in step S3 includes the following steps: S31. Global outlier removal based on centroid distance: Read preliminary pig body point cloud data, extract three-dimensional coordinate information, calculate the centroid of the preliminary point cloud and the Euclidean distance from each point to the centroid, calculate the mean and standard deviation of the Euclidean distance, and remove points whose Euclidean distance is greater than the sum of the mean and 2.5 times the standard deviation. S32. Calculate the mean and standard deviation of the Z-axis coordinates of each point in the point cloud after global outlier removal, and remove points whose absolute value of the difference between the Z-axis coordinate and the mean is greater than 3 times the standard deviation; S33. In the normalized space, voxels with preset side lengths are downsampled to sample the point cloud. The average distance between each voxel's center and its k nearest neighbor voxels is calculated. The mean and standard deviation of the average distances for each voxel are calculated. Voxels whose average distances are greater than the sum of the mean and twice the standard deviation are removed. The corresponding points in the original point cloud are retained according to the correspondence between the retained voxels and the original points.
[0009] Step S3, which involves obtaining the six-channel input point cloud for the back and buttocks, includes: For each point in the denoised point cloud, search for 20 nearest neighbor points, construct a local covariance matrix based on the nearest neighbor points, and use the eigenvector corresponding to the smallest eigenvalue of the local covariance matrix as the surface normal vector of the corresponding point. The three-dimensional coordinates of each point are concatenated with the corresponding normal vectors to form six-channel point cloud data. Subtract the centroid of the point cloud from all points to move the center of the pig's body point cloud to the origin; Calculate the maximum Euclidean distance r from all points to the centroid, then divide the distance from all points to the centroid by r, and scale the point cloud to a uniform scale to obtain a six-channel input point cloud.
[0010] Furthermore, each of the DGCNN feature extraction branches sequentially includes a four-layer dynamic edge convolution module, a multi-layer feature concatenation module, a global max pooling module, and a fully connected mapping module; The first-layer dynamic edge convolution module performs K-nearest neighbor search based on the 3D coordinates of the input point cloud and constructs a local adjacency graph. Subsequent dynamic edge convolution modules perform K-nearest neighbor search again based on the point-by-point features output by the previous layer dynamic edge convolution module and construct a local adjacency graph, with the number of nearest neighbors being 20 each time. Each dynamic edge convolution module constructs edge features based on the center point features and the difference between the features of neighboring points and the center point features, and extracts local features; The output channels of the four-layer dynamic edge convolution module are 64, 64, 128 and 256 respectively. The outputs of each layer are concatenated along the channel dimension to form 512-channel point-by-point features. Global max pooling is used to obtain 512-dimensional global features, and then a fully connected mapping module is used to obtain 128-dimensional view features. The feature fusion module concatenates the 128-dimensional view features from the back view and the 128-dimensional view features from the hip view along the channel dimension, and then processes them sequentially through fully connected mapping, batch normalization, ReLU activation and Dropout to obtain 128-dimensional fused features. The SE channel attention module compresses the channel dimension of the 128-dimensional fusion feature from 128 to 32 and then restores it to 128 through two fully connected layers. It also generates 128-dimensional channel weights through the sigmoid function and multiplies the channel weights element-wise with the 128-dimensional fusion feature to obtain the channel-weighted fusion feature. The pregnancy condition modulation module includes a condition parameter generation network and a channel-by-channel affine modulation unit; The condition parameter generation network receives a three-dimensional pregnancy condition vector and sequentially passes it through a first fully connected layer, a nonlinear activation layer, and a second fully connected layer. The three-dimensional pregnancy condition vector is mapped to a 256-dimensional condition parameter vector through a 64-dimensional intermediate representation, and the 256-dimensional condition parameter vector is then split into a 128-dimensional scaling increment vector γ and a 128-dimensional translation coefficient vector β. The channel-by-channel affine modulation unit obtains the modulated features according to the following formula: f' = f + γ⊙f + β Where f is the fusion feature before modulation, f' is the feature after modulation, and ⊙ represents element-wise multiplication; The output layer of the conditional parameter generation network is initialized so that the initial outputs of the scaling increment vector and translation coefficient vector are both zero.
[0011] Furthermore, the three-dimensional pregnancy condition vector is a three-bit binary vector generated based on the pregnancy stage status number to which the sow belongs in the number of days of pregnancy. The first bit indicates whether the sow is in the late stage of pregnancy (1 if yes, 0 otherwise), the second bit indicates whether the sow is in the early or middle stage of pregnancy (1 if yes, 0 otherwise), and the third bit indicates the parity of the pregnancy stage status number corresponding to the pregnancy stage status (1 for odd, 0 for even). The ordinal classification head transforms the five-category body condition classification task into a four-level threshold binary classification task, determining whether the sow's body condition is higher than category I, II, III, and IV, and outputting four logical values accordingly. Four logical values The predicted probability of body condition exceeding the k-th class threshold is obtained by applying temperature scaling and the sigmoid function. , ,in, , ; The predicted probabilities of the four level thresholds are summed to obtain the continuous ordinal score of the paired point cloud of the i-th frame. ; in, For the first i Each frame corresponds to a logical value. σ For the sigmoid function, T A positive temperature scaling factor. ; The sow body condition category number is obtained according to the following formula: That is, take the average of all frame scores under the same ear mark and round it to get the final prediction value.
[0012] Furthermore, the physical condition assessment model is obtained through the following steps: During the body condition assessment period corresponding to the dual-view point cloud acquisition period, body condition measurement calipers were used to measure the subcutaneous fat thickness at the location of the last rib of the sow, obtaining body condition scores in 0.2-point increments. Based on these scores, the sows were divided into five ordered body condition categories from low to high: Category I corresponds to a score no greater than 3.0, Category II to 3.2–3.6, Category III to 3.8–4.0, Category IV to 4.2–4.4, and Category V to a score no less than 4.6. Categories I through V were sequentially coded as actual body condition category numbers. As a label for physical condition; The paired back six-channel input point cloud and the rump six-channel input point cloud were associated with the corresponding sow's ear tag number, gestation days at the time of collection, and body condition label to form a sample; among them, each set of paired point clouds from the same sow in the same body condition assessment period were associated with the corresponding body condition label for that period. The samples are divided into training set, validation set and test set according to the individual sows, so that all frame pairs of the same sow belong to only one of the datasets; The back six-channel input point cloud, buttock six-channel input point cloud, and pregnancy condition vector of each training sample are input into the body condition assessment model, and four cumulative binary classification targets are constructed based on the actual body condition category numbers. ,in, For the level threshold, y represents the actual physical condition category number; The ordinal focus loss is calculated based on the four level threshold prediction logic values output by the physical condition assessment model and the corresponding cumulative binary classification target, and the model parameters are updated through backpropagation. The model parameters are saved using the validation set evaluation metrics. After training, the model parameters with the best validation set evaluation metrics are loaded to obtain the trained body condition assessment model.
[0013] Furthermore, the ordinal focus loss function is: Where r k ∈{0,1} represents the k-th ordinal binary classification target (takes 1 when the true class is greater than k), p t,k To correspond to the predicted probability, γ is the focusing parameter (set to 2.0), and a 0.05 label smoothing is introduced to prevent overconfidence. The model is for the first Predicted probability of each level threshold .
[0014] Beneficial effects: (1) Stable data acquisition and deployment, and efficient data construction. The dual-view depth camera is fixedly installed on the limit bar, and the data is acquired without contact and is not affected by collisions or pollution; the back and buttock views complement each other, making up for the lack of geometric information in a single view. Based on SAM2, a mask is generated on the RGB image and back-projected to construct a point cloud, which does not require three-dimensional point-by-point annotation, significantly reducing the cost of data construction. Moreover, SAM2 only runs offline, which meets the real-time deployment requirements on site; (2) The model is lightweight and fully expresses features. The dual-view DGCNN shares weights, reducing the number of parameters by nearly half; through dual-view feature fusion and SE channel attention, it adaptively emphasizes the discriminative channel and makes full use of complementary geometric information; (3) High assessment accuracy and strong decision robustness. Pregnancy condition modulation is introduced to alleviate stage confusion by incorporating physiological priors; the ordinal classification and focus loss are combined to maintain the ordinal relationship between categories and alleviate sample imbalance; the soft fraction mean aggregation of multiple frames based on ear tags reduces single-frame jitter, and the standard deviation is used as confidence to trigger the review, thereby improving the stability of individual assessment. Attached Figure Description
[0015] Figure 1 This is a flowchart of the present invention. Detailed Implementation
[0016] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the described embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.
[0017] Example 1 like Figure 1 As shown, an automated sow body condition scoring method based on dual-view point clouds includes the following steps: S1. Image Acquisition: Simultaneously acquire images of the sow directly above and diagonally behind in the restraint bar using a camera. Obtain color and depth images of the back and rump of the standing sow. Obtain a set of dual-view frame pairs through equally spaced frame extraction and posture filtering.
[0018] The specific steps S1 include: using a data acquisition cart, two Kinect depth cameras (Azure KinectDK) are positioned directly above the gestation bar (back view) and diagonally behind the gestation bar (rump view), respectively, to simultaneously acquire color and depth videos of the sows in their normal standing posture within the gestation bar. Each sow is filmed for approximately 3 minutes per view, and the videos are named after the sow's ear tag and saved in a folder named after the current date. After filming, the same person uses body condition calipers to measure the subcutaneous fat thickness at the location of the sow's last rib. The caliper readings are directly read out in 0.2-point increments, and information such as gestational age and parity is recorded.
[0019] The video files from both perspectives were subjected to fixed-interval frame extraction, with the frame extraction interval set to 15 frames. Frames of the sow in a normal standing posture were selected, while frames of abnormal postures such as lying down or vigorous exercise were removed.
[0020] All data were collected from the Xinzhou pig farm of Wuhan Fengmeihe Livestock Co., Ltd., from August 13, 2025 to November 5, 2025. After filtering out pigs with incomplete data, there were data on 580 sows, including replacement gilts, multiparous sows and weaned sows. The gestation days of multiparous sows included more than 30 days, more than 50 days, more than 70 days and more than 90 days.
[0021] S2. Perform pig body segmentation on each color image in the frame pair set to obtain a two-dimensional segmentation mask, map it to a calibrated and aligned depth map, and back-project the pixels in the mask pixel by pixel into three-dimensional coordinates according to the camera intrinsic parameters. After removing invalid depth and out-of-bounds points, obtain the back and rump point cloud of the frame.
[0022] The specific steps include: S21.RGB image pig annotation To achieve point cloud extraction of pig bodies without 3D annotation, this solution transforms the 3D extraction task into a mature 2D segmentation task: the AnyLabeling interactive annotation tool (configured with SAM2 segmentation large model) is used on the color image to outline the main outline of the pig, automatically generating a pig body segmentation mask to mark the main pig body region.
[0023] S22. Mask mapping and pixel-wise backprojection The segmentation mask was mapped onto a calibrated and aligned depth map. Pixel-by-pixel backprojection was performed only on pixels within the mask's coverage area: first, invalid depth pixels with a depth value of 0 were removed; then, the depth values of the remaining pixels were converted from millimeters to meters; finally, the 2D pixel coordinates were converted to 3D spatial coordinates using camera intrinsics. If the number of valid points obtained from a frame's backprojection was less than 100, the frame was considered an extraction failure and discarded, generating and saving a preliminary pig body point cloud in Ply format. The above annotation and backprojection were performed on the back and rump views of each sow, resulting in 34,800 back point clouds and 34,800 rump point clouds, providing basic data for subsequent purification and pairing.
[0024] S3. Perform multi-level statistical filtering denoising, surface normal vector estimation and normalization on the preliminary pig body point cloud in sequence, and sample to a fixed number of points to obtain a six-channel input point cloud.
[0025] The initial point cloud obtained solely through mask back projection still contains outliers and a small number of background noise points. To obtain a clean pig body point cloud, this invention proposes a point cloud denoising method combining multi-level statistical filtering, which performs the following processing steps sequentially: S31. Radius filtering, global outlier removal based on centroid distance. Read the preliminary pig body point cloud data, extract the three-dimensional coordinate information, average the three-dimensional coordinates of all points in the point cloud to obtain the centroid position, calculate the distance of each point based on the centroid of the point cloud, and remove outliers whose distance exceeds the mean plus 2.5 times the standard deviation.
[0026] S32. Z-axis cutoff For the point cloud after radius filtering, calculate the deviation of each point's Z-axis coordinate from the mean, and remove points whose absolute deviation exceeds 3 times the standard deviation, thus eliminating discrete noise points along the Z-axis. This is used to remove fence points and ground reflection points above the pig's body, as these points may still be near the pig's body in the X and Y directions, but have deviated significantly from the main body in the Z direction.
[0027] S33. Voxel downsampling statistical outlier filtering Voxel downsampling is performed on the point cloud in normalized space with a voxel side length of 0.02. The average distance between the center of each voxel and its 30 nearest neighbors is calculated. Voxels whose average distance exceeds the mean plus twice the standard deviation are removed. The retained voxels are then mapped back to the original point cloud, achieving efficient removal of local sparse outliers.
[0028] S34. Normal Vector Estimation and Normalization For the point cloud after S33 denoising, its k nearest neighbors are searched point by point (k=20 in this embodiment). A local covariance matrix is constructed based on the k nearest neighbors, and the direction of the eigenvector corresponding to the smallest eigenvalue of the covariance matrix is taken as the surface normal vector of that point. The three-dimensional coordinates of each point are concatenated with the corresponding normal vector to form a six-channel point cloud data. Centroid alignment and maximum norm normalization are performed on the six-channel point cloud in sequence to translate the point cloud to the origin and scale the coordinate range to a preset interval to eliminate the influence of differences in individual pig size and position on the network input. Then, the normalized point cloud is uniformly sampled to a fixed number of points (2048 points in this embodiment) to form a six-channel input point cloud for network input.
[0029] After the above steps, a total of 34,800 pairs of clean and pose-complete pig body point clouds were obtained, providing reliable input for subsequent body condition assessment.
[0030] Centroid alignment is performed on the six-channel point cloud, which involves subtracting the centroid of the point cloud from all points, thus moving the center of the pig's point cloud back to the origin. Since the position of the point cloud in the camera coordinate system can change depending on the pig's position, centroid alignment eliminates the overall positional offset, and the network does not need to additionally learn the differences in the same shape appearing in different locations.
[0031] Maximum norm normalization is performed on the six-channel point cloud, which includes calculating the maximum Euclidean distance *r* from all points to the centroid, and then dividing the distances from all points to the centroid by *r* to scale the point cloud to a uniform scale. Since the three coordinate axes use the same scaling factor, the geometric relationships such as the length-to-width ratio and relative concavity / convexity of the pig remain unchanged; at the same time, the input numerical scale is more consistent, which is beneficial to the stability of network training.
[0032] S4 Sow Body Condition Assessment Based on Shared Weight Dual-View DGCNN The six-channel input point cloud, paired for each time period, is input into the trained shared-weight body condition assessment model to obtain the sow body condition assessment results for each time period: ; Finally, a soft-score aggregation strategy based on ear tags was used to group the same sow within the same evaluation period according to the ear tag number. The body condition assessment results of the sows corresponding to the point clouds were grouped into one group. That is, the mean statistical method was used to aggregate the scores from multiple frames to obtain the final body condition category of the pig. That is, take the average of all frame scores under the same ear mark and round it to get the final prediction value.
[0033] Each soft fraction corresponds to a set of paired point clouds for the back and buttocks.
[0034] Mean aggregation preserves continuous information of ordinal decision boundaries, reducing the randomness of decision-making in pigs with boundary conditions. At the same time, the standard deviation of inter-frame scores is used as the decision confidence level. The larger the standard deviation, the more inconsistent the judgments in each frame and the less reliable the decision. This can trigger manual review, thereby improving the stability and reliability of individual pig condition assessment results.
[0035] The training process of the physical condition assessment model includes: The six-channel input point clouds of the back and rump output from step S3 are associated with the corresponding sow's ear tag number, gestation days at the time of collection, and body condition label to form samples. Each pair of dual-view paired point clouds serves as the point cloud input for one sample, the gestation days as a conditional input, the body condition label as the supervisory target, and the ear tag number for identifying individual sows, dividing the dataset, and aggregating multi-frame prediction results for the same sow. The body condition label serves as the supervisory target for model training.
[0036] Body condition is tagged as the subcutaneous fat thickness at the last rib location of the sow, measured with body condition calipers. The measurement period corresponds to the point cloud acquisition period. The obtained fat thickness is used as the body condition score, with values in 0.2-point increments. Sows are classified into five ordered body condition categories according to their scores, from lowest to highest: Category I: Body condition score not greater than 3.0; Category II: 3.2–3.6; Category III: 3.8–4.0; Category IV: 4.2–4.4; Category V: Body condition score not less than 4.6. Categories I to V are coded as follows: in, This assigns a true body condition category number to the sample. Paired point clouds from two perspectives, collected from the same sow within the same body condition assessment period, are associated with the corresponding body condition label for that period.
[0037] Using ear tag numbers as the unit of division, 580 sows were randomly partitioned stratified according to body condition category, resulting in a training set of 435 sows, a validation set of 87 sows, and a test set of 58 sows. All paired point cloud samples from the same sow belonged to only one dataset to avoid data leakage caused by different frames of the same sow appearing in the training, validation, or test sets simultaneously. The training set was used to optimize model parameters, the validation set was used for model selection and early stopping, and the test set was used for independent performance evaluation of the trained and selected model.
[0038] During training, the back point cloud, buttock point cloud, and pregnancy condition vector of each training sample are input into the body condition assessment model. The ordinal focus loss is calculated, and the parameters of the feature extraction, feature fusion, attention, condition modulation, and classification modules are updated through backpropagation.
[0039] The network parameters were set as follows: EdgeConv layers: 4; number of channels: 64, 64, 128, 256; nearest neighbor count: k=20; feature dimension: 128; SE compression ratio: 4; pregnancy coding dimension: 3; inference phase temperature scaling factor: 0.9; focus parameter: γ=2.0. The model was trained using the AdamW optimizer with an initial learning rate of 0.001 and a weight decay factor of 0.0001. The learning rate adjustment strategy used cosine annealing and restart. During training, a pre-selected evaluation metric was calculated using the validation set, and the model parameters with the best performance on the validation set were saved. Training stopped when the metric did not improve for 30 consecutive rounds; otherwise, training continued until the maximum number of rounds. After training, the saved optimal parameters were loaded to obtain the trained sow body condition assessment model. The training epoch was set to 100 rounds with early stopping (30 rounds of patience), the batch size was set to 8, the gradient clipping threshold was set to 2.0, and mixed precision training was used to accelerate the training. To address class imbalance, an inverse frequency-weighted random sampler was used to balance the sampling probabilities of each class.
[0040] Body condition assessment model prediction results The body condition assessment model has a total of 324,649 parameters. The final body condition assessment model achieved a pig-level accuracy of 73.6% (soft score aggregation) to 75.9% (hard vote) on a test set of 58 sows, with a macro-average F1 of 70.5% to 72.2%, indicating that the method can achieve accurate and automatic body condition assessment using dual-view 3D point cloud information of sows.
[0041] The body condition assessment model includes two DGCNN feature extraction branches that process back and buttock point clouds respectively. The two branches share network parameters and independently construct and extract features from their respective viewpoints. The features extracted by the two DGCNN feature extraction branches are concatenated along the channel dimension. The concatenated features are then processed sequentially through fully connected mapping, batch normalization, ReLU activation, and Dropout to obtain a 128-dimensional fused feature. This fused feature is input into the SE channel attention module to obtain a channel-weighted fused feature. The pregnancy condition modulation module FiLM's channel-wise affine modulation unit uses the scaling increment vector γ and the translation coefficient vector β to perform residual affine modulation on the 128-dimensional fused feature f output by the SE channel attention module, obtaining a modulation feature f' containing pregnancy condition information. This modulated feature f' is then input into the ordinal classification head for body condition prediction. The ordinal classification head outputs logical values corresponding to the boundaries of the four body condition categories. During training, the five body condition labels are converted into four cumulative binary classification targets, which indicate whether the true body condition category is higher than the corresponding category boundary. The ordinal focus loss is calculated based on each logical value and the corresponding target. During inference, each logical value is converted into a probability, and the probabilities are summed to obtain the frame-level continuous ordinal score, which is used for subsequent pig-level multi-frame aggregation. Alternatively, each probability can be thresholded and accumulated to obtain the frame-level body condition category number.
[0042] The Pregnancy Condition Modulation (FiLM) module dynamically adjusts the scale and bias of each feature channel, enabling the network to adopt different feature representation strategies at different physiological stages, thus mitigating class confusion caused by "same physical condition, different body type" at different pregnancy stages. The channel-wise affine modulation unit is initialized with zero initialization, degenerating to a modulated baseline in the early stages of training, and gradually learning to utilize physiological priors as training progresses, ensuring training stability.
[0043] f' = f + γ⊙f + β Where f is the pre-modulation fusion feature, f' is the post-modulation feature, and ⊙ represents element-wise multiplication.
[0044] The Condition Parameter Generation Network (FiLM) of the Pregnancy Condition Modulation Module receives a three-dimensional pregnancy condition vector, maps it to a 256-dimensional condition parameter vector, and then decomposes it into a 128-dimensional scaling increment vector γ and a 128-dimensional translation coefficient vector β. The condition parameter generation network includes a first fully connected layer, a nonlinear activation layer, and a second fully connected layer, with dimensions of 3→64→256 respectively. The three-dimensional pregnancy condition vector is a 3-bit binary vector encoding the number of days of gestation in the sow. The first digit indicates whether the pregnancy is in the late stage (1 if yes, 0 otherwise); the second digit indicates whether the pregnancy is in the early or mid-stage (1 if yes, 0 otherwise); the third digit indicates whether the pregnancy stage status number is odd (1 for odd, 0 for even). The gestational days in the sample are categorized into pregnancy stages in ascending order, then encoded as pregnancy stage status numbers, and finally converted into a three-dimensional pregnancy condition vector. Pregnancy stages include: weaning state, unmated reserve state, early pregnancy, mid-pregnancy, and late pregnancy, with status numbers 0, 1, 2, 3, and 4 respectively. These correspond to the following three-dimensional pregnancy condition vectors. , , , and .
[0045] The SE channel attention module has a compression ratio of 4. It compresses the channel dimension from 128 to 32 through two fully connected layers, and then restores it to 128. The channel weights are generated by the sigmoid function. The channel weights are weighted with the fused features channel by channel to enhance the feature responses related to body condition discrimination (such as the channel corresponding to the fat deposition pattern in the buttocks) and weaken the feature responses that contribute less. This achieves adaptive fusion of complementary information from two perspectives and generates a 128-dimensional feature after dual-view fusion.
[0046] Each DGCNN branch consists of four layers of dynamic edge convolution module EdgeConv, multi-layer feature concatenation module, global max pooling module, and fully connected mapping module.
[0047] Each dynamic edge convolutional module (EdgeConv) constructs a local adjacency graph through K-nearest neighbor search, with 20 nearest neighbors. The first-layer dynamic edge convolutional module (EdgeConv) constructs the graph in 3D coordinate space, while subsequent dynamic edge convolutional modules (EdgeConv) reconstruct the graph in the feature space output by the previous layer's EdgeConv. The four layers of dynamic edge convolutional modules (EdgeConv) have output channels of 64, 64, 128, and 256 respectively. Their outputs are concatenated along the channel dimension to form 512-channel pointwise features, which are then subjected to global max pooling to obtain 512-dimensional global features. Finally, a fully connected mapping module generates 128-dimensional viewpoint features. Each dynamic edge convolutional module (EdgeConv) constructs edge features based on the center point features and the feature differences between neighboring points and the center point. Shared parameters enable consistent feature extraction mapping for both viewpoints and reduce the number of parameters relative to the two independent parameter backbones, which is beneficial for subsequent dual-viewpoint feature fusion. The ordinal classification head transforms the five-category body condition classification task into a four-level threshold binary classification task, determining whether the sow's body condition is higher than category I, II, III, and IV, and outputting four logical values accordingly. Four logical values The predicted probability of body condition exceeding the k-th class threshold is obtained by applying temperature scaling and the sigmoid function. , ,in, , For the actual physical condition category number , No. The true label for a binary classification task with a threshold level is defined as follows: .
[0048] The predicted probabilities of the four level thresholds are summed to obtain the continuous ordinal score of the paired point cloud of the i-th frame. , This can be used for multi-frame soft-score aggregation of the same sow; or the predicted probability of each level threshold can be compared with 0.5, and the number of values exceeding 0.5 can be counted to obtain the predicted category number of the paired point cloud of the i-th frame. The predicted category numbers 0 to 4 correspond to body condition categories I to V, respectively. This classification method utilizes the ordered relationship between body condition categories to determine the classification based on multiple level thresholds.
[0049] Where σ is the sigmoid function, l k The k-th logical value is denoted by T, which is a temperature scaling factor (set to 0.9) used to sharpen the decision boundary. This structure naturally maintains ordinal consistency between categories, avoiding the unreasonable assumption in ordinary multi-classifiers that "neighboring categories are equidistant from distant categories".
[0050] Ordinal focus loss function: In the pig body condition dataset, the number of samples in different body condition categories is unevenly distributed, and samples of extreme body conditions (≤3.0 and ≥4.6) are scarce. When training with the traditional cross-entropy loss function, the model is easily affected by a large number of intermediate category samples, while paying insufficient attention to extreme body condition samples, thus reducing the classification accuracy of extreme samples.
[0051] To address the aforementioned problems, this invention designs an ordinal focus loss function. Within the ordinal framework, K-1 binary classification tasks inherently suffer from sample imbalance. Focus loss modulation is applied to each ordinal binary classification task, and the total loss is defined as: Where r k ∈{0,1} represents the k-th ordinal binary classification target (takes 1 when the true class is greater than k), p t,k To correspond to the predicted probability, γ is the focusing parameter (taken as 2.0), and a 0.05 label smoothing is introduced to prevent overconfidence. The model is for the first Predicted probability of each level threshold .
[0052] Through this weighting mechanism, hard-to-distinguish samples will receive a higher loss contribution, making the model pay more attention to extreme conditions and boundary samples during parameter optimization, thereby alleviating the problem of imbalanced sample distribution and improving the model's ability to classify the full range of condition categories.
[0053] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions described in the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. An automated body condition scoring method for sows based on dual-view point clouds, characterized in that, Includes the following steps: S1. Using depth cameras positioned directly above and diagonally behind the restraint bar, color and depth images of the sow's back and rump views are simultaneously acquired. A set of dual-view frame pairs is obtained through equally spaced frame extraction and posture filtering. S2. Perform pig body segmentation on each color image in the frame pair set to obtain a two-dimensional segmentation mask, map it to a depth map aligned with the color image after calibration, and back-project the pixels in the two-dimensional segmentation mask pixel by pixel according to the camera intrinsic parameters to obtain three-dimensional coordinates. After removing invalid depth and out-of-bounds points, obtain the preliminary point cloud of the back and the preliminary point cloud of the buttocks of each frame respectively. S3. Perform multi-level statistical filtering denoising on the preliminary point cloud of the back and the preliminary point cloud of the buttocks respectively, estimate the surface normal vector of each point in the denoised point cloud, perform centroid alignment and maximum norm normalization on the three-dimensional coordinates of each point, concatenate the normalized three-dimensional coordinates with the corresponding surface normal vectors, and sample to a fixed number of points to obtain a six-channel input point cloud of the back and buttocks; the three channels of the six-channel input point cloud are three-dimensional coordinates and the three channels are surface normal vectors; S4. Input the back six-channel input point cloud, the buttock six-channel input point cloud, and the pregnancy condition vector generated according to the gestation days of the sow at the time of collection into the trained body condition assessment model to obtain the frame-level continuous ordinal score corresponding to the frame pair. S5. According to the sow ear tag number and the assessment period, the frame-level continuous ordinal scores of multiple frames of the same sow in the same assessment period are aggregated by mean. The aggregated mean is rounded to obtain the sow body condition category number, and the body condition assessment result is output according to the sow body condition category number. The physical condition assessment model includes two shared network parameters: a dynamic graph convolutional neural network (DGCNN) feature extraction branch, a feature fusion module, an SE channel attention module, a pregnancy condition modulation module, and an ordinal classification head. The two DGCNN feature extraction branches independently construct adjacency graphs and extract viewpoint features from the back six-channel input point cloud and the buttock six-channel input point cloud, respectively; the feature fusion module concatenates the two viewpoint features along the channel dimension and maps them into a fused feature. The SE channel attention module performs channel weighting on the fused features; the pregnancy condition modulation module generates a scaling increment vector and a translation coefficient vector based on the pregnancy condition vector, and performs channel-by-channel residual affine modulation on the channel-weighted fused features; the ordinal classification head outputs the predicted probability of whether the corresponding physical condition exceeds the upper limit of each physical condition category based on the modulated features, and sums the predicted probabilities to obtain the frame-level continuous ordinal score.
2. The automated sow body condition scoring method based on dual-view point clouds according to claim 1, characterized in that, The multi-level statistical filtering denoising method in step S3 includes the following steps: S31. Global outlier removal based on centroid distance: Read preliminary pig body point cloud data, extract three-dimensional coordinate information, calculate the centroid of the preliminary point cloud and the Euclidean distance from each point to the centroid, calculate the mean and standard deviation of the Euclidean distance, and remove points whose Euclidean distance is greater than the sum of the mean and 2.5 times the standard deviation. S32. Calculate the mean and standard deviation of the Z-axis coordinates of each point in the point cloud after global outlier removal, and remove points whose absolute value of the difference between the Z-axis coordinate and the mean is greater than 3 times the standard deviation; S33. In the normalized space, voxels with preset side lengths are downsampled to sample the point cloud. The average distance between each voxel's center and its k nearest neighbor voxels is calculated. The mean and standard deviation of the average distances for each voxel are calculated. Voxels whose average distances are greater than the sum of the mean and twice the standard deviation are removed. The corresponding points in the original point cloud are retained according to the correspondence between the retained voxels and the original points.
3. The automated sow body condition scoring method based on dual-view point clouds according to claim 1, characterized in that, Step S3, which involves obtaining the six-channel input point cloud for the back and buttocks, includes: For each point in the denoised point cloud, search for 20 nearest neighbor points, construct a local covariance matrix based on the nearest neighbor points, and use the eigenvector corresponding to the smallest eigenvalue of the local covariance matrix as the surface normal vector of the corresponding point. The three-dimensional coordinates of each point are concatenated with the corresponding normal vectors to form six-channel point cloud data. Subtract the centroid of the point cloud from all points to move the center of the pig's body point cloud to the origin; Calculate the maximum Euclidean distance r from all points to the centroid, then divide the distance from all points to the centroid by r, and scale the point cloud to a uniform scale to obtain a six-channel input point cloud.
4. The automated sow body condition scoring method based on dual-view point clouds according to claim 1, characterized in that, Each of the DGCNN feature extraction branches includes, in sequence, a four-layer dynamic edge convolution module, a multi-layer feature concatenation module, a global max pooling module, and a fully connected mapping module; The first-layer dynamic edge convolution module performs K-nearest neighbor search based on the 3D coordinates of the input point cloud and constructs a local adjacency graph. Subsequent dynamic edge convolution modules perform K-nearest neighbor search again based on the point-by-point features output by the previous layer dynamic edge convolution module and construct a local adjacency graph, with the number of nearest neighbors being 20 each time. Each dynamic edge convolution module constructs edge features based on the center point features and the difference between the features of neighboring points and the center point features, and extracts local features; The output channels of the four-layer dynamic edge convolution module are 64, 64, 128 and 256 respectively. The outputs of each layer are concatenated along the channel dimension to form 512-channel point-by-point features. Global max pooling is used to obtain 512-dimensional global features, and then a fully connected mapping module is used to obtain 128-dimensional view features. The feature fusion module concatenates the 128-dimensional view features from the back view and the 128-dimensional view features from the hip view along the channel dimension, and then processes them sequentially through fully connected mapping, batch normalization, ReLU activation and Dropout to obtain 128-dimensional fused features. The SE channel attention module compresses the channel dimension of the 128-dimensional fusion feature from 128 to 32 and then restores it to 128 through two fully connected layers. It also generates 128-dimensional channel weights through the sigmoid function and multiplies the channel weights element-wise with the 128-dimensional fusion feature to obtain the channel-weighted fusion feature. The pregnancy condition modulation module includes a condition parameter generation network and a channel-by-channel affine modulation unit; The condition parameter generation network receives a three-dimensional pregnancy condition vector and sequentially passes it through a first fully connected layer, a nonlinear activation layer, and a second fully connected layer. The three-dimensional pregnancy condition vector is mapped to a 256-dimensional condition parameter vector through a 64-dimensional intermediate representation, and the 256-dimensional condition parameter vector is then split into a 128-dimensional scaling increment vector γ and a 128-dimensional translation coefficient vector β. The channel-by-channel affine modulation unit obtains the modulated features according to the following formula: f' = f + γ⊙f + β Where f is the fusion feature before modulation, f' is the feature after modulation, and ⊙ represents element-wise multiplication; The output layer of the conditional parameter generation network is initialized so that the initial outputs of the scaling increment vector and translation coefficient vector are both zero.
5. The automated sow body condition scoring method based on dual-view point clouds according to claim 4, characterized in that, The three-dimensional pregnancy condition vector is a three-bit binary vector generated according to the pregnancy stage status number to which the sow belongs based on the number of days of pregnancy. The first bit indicates whether the sow is in late pregnancy (1 if yes, 0 otherwise), the second bit indicates whether the sow is in early or mid pregnancy (1 if yes, 0 otherwise), and the third bit indicates the parity of the pregnancy stage status number corresponding to the pregnancy stage status (1 for odd, 0 for even). The ordinal classification head transforms the five-category body condition classification task into a four-level threshold binary classification task, determining whether the sow's body condition is higher than category I, II, III, and IV, and outputting four logical values accordingly. The four logical values are scaled by temperature and processed by the sigmoid function to obtain the predicted probability that the body condition will exceed the k-th level threshold. ,in For the k-th logical value, T is the temperature scaling factor. ; The predicted probabilities of the four level thresholds are summed to obtain the continuous ordinal score of the paired point cloud of the i-th frame. ; in, For the first i Each frame corresponds to a logical value. σ For the sigmoid function, A positive temperature scaling factor. ; The sow body condition category number is obtained according to the following formula: That is, take the average of all frame scores under the same ear mark and round it to get the final prediction value.
6. The automated sow body condition scoring method based on dual-view point clouds according to claim 4, characterized in that, The physical condition assessment model is trained through the following steps: During the body condition assessment period corresponding to the dual-view point cloud acquisition period, body condition measurement calipers were used to measure the subcutaneous fat thickness at the location of the last rib of the sow, obtaining body condition scores in 0.2-point increments. Based on these scores, the sows were divided into five ordered body condition categories from low to high: Category I corresponds to a score no greater than 3.0, Category II to 3.2–3.6, Category III to 3.8–4.0, Category IV to 4.2–4.4, and Category V to a score no less than 4.
6. Categories I through V were sequentially coded as actual body condition category numbers. As a label for physical condition; The paired back six-channel input point cloud and the rump six-channel input point cloud were associated with the corresponding sow's ear tag number, gestation days at the time of collection, and body condition label to form a sample; among them, each set of paired point clouds from the same sow in the same body condition assessment period were associated with the corresponding body condition label for that period. The samples are divided into training set, validation set and test set according to the individual sows, so that all frame pairs of the same sow belong to only one of the datasets; The back six-channel input point cloud, buttock six-channel input point cloud, and pregnancy condition vector of each training sample are input into the body condition assessment model, and four cumulative binary classification targets are constructed based on the actual body condition category numbers. ,in, For the level threshold, y represents the actual physical condition category number; The ordinal focus loss is calculated based on the four level threshold prediction logic values output by the physical condition assessment model and the corresponding cumulative binary classification target, and the model parameters are updated through backpropagation. The model parameters are saved using the validation set evaluation metrics. After training, the model parameters with the best validation set evaluation metrics are loaded to obtain the trained body condition assessment model.
7. The automated sow body condition scoring method based on dual-view point clouds according to claim 4, characterized in that, The ordinal focus loss function is: Where r k ∈{0,1} represents the k-th ordinal binary classification target (takes 1 when the true class > k), p t,k To correspond to the predicted probability, γ is the focusing parameter, which is set to 2.0, and a 0.05 label smoothing is introduced to prevent overconfidence. Is the physical condition beyond the first Predicted probability of each level threshold
Citation Information
Patent Citations
Positioning column sow monitoring system and method
CN110612921A
Sow body condition scoring method based on two-dimensional image
CN120726672A
