Deep learning-based sheep face recognition and weight prediction method and system
By using deep learning technology, the organic synergy between sheep identification and weight prediction has been achieved, solving the problem of the separation between sheep identification and weight monitoring, improving the accuracy of identification and the precision of weight prediction, and meeting the needs of efficient management in large-scale farming.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-22
- Publication Date
- 2026-04-17
AI Technical Summary
The existing sheep identification and weight monitoring technologies are disconnected, resulting in low identification accuracy and low retrieval efficiency. Furthermore, the weight monitoring process is cumbersome and easily affected by light and posture, making it difficult to meet the efficient management needs of large-scale farming.
A deep learning-based sheep face recognition and weight prediction method is adopted. The sheep face region is located by target detection network, individual recognition is achieved by feature vector similarity comparison, and key point estimation of sheep body region is assisted by instance mask. Body size parameters are calculated by combining camera calibration parameters and depth map recovery scale. Finally, the predicted value is output by weight regression network.
It improves the accuracy and robustness of individual sheep identification, achieves precise estimation of body size parameters and accurate weight prediction, supports non-contact, real-time monitoring, and enhances the efficiency and precision of breeding management.
Smart Images

Figure CN121884388A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the fields of computer vision, animal recognition and intelligent breeding management technology, and relates to a method and system for sheep face recognition and weight prediction based on deep learning. Background Technology
[0002] In the process of refined management in animal husbandry, sheep identification and weight monitoring are key links that affect the scientific and rational nature of feed input. They also serve as an important reference for slaughter decisions, helping farmers accurately grasp the optimal slaughter time and maximize economic benefits. In terms of disease early warning, continuous monitoring of sheep weight and identification information can promptly detect abnormal changes, providing strong support for early disease detection and prevention. Furthermore, for production statistics, accurate identification and weight data are an important foundation for measuring breeding efficiency and planning subsequent production.
[0003] However, traditional sheep identification methods often rely on ear tags or microchips. While these methods achieve identification to some extent, ear tags are prone to detachment and microchips are susceptible to misreading, leading to decreased accuracy in sheep identification. Weighbridges, a common method for weight monitoring, are cumbersome and require significant manpower and resources for herding, weighing, and recording sheep. Furthermore, weighing can cause stress in sheep, affecting their health and growth and potentially leading to inaccurate weight data. With rapid technological advancements, breakthroughs in target detection, pose estimation, and metric learning are unlocking immense application potential for image-based non-contact identification and weight estimation technologies.
[0004] However, existing image-based sheep identification and weight estimation schemes are fragmented and fail to form an organic whole. At the same time, in complex breeding scenarios, they are easily affected by various factors such as lighting, occlusion, and sheep posture, which affect the accuracy of identification and weight estimation. When faced with large-scale sheep data, the retrieval efficiency is low, making it difficult to meet the needs of fast and efficient management in actual breeding production. The weight estimation process lacks interpretable intermediate quantities, making it difficult to effectively evaluate and verify the accuracy and reliability of the weight estimation results. Summary of the Invention
[0005] The purpose of this invention is to solve the technical problems in the existing sheep identification and weight monitoring, such as the separation of sheep face recognition and weight estimation, low efficiency of large-scale retrieval, and lack of interpretable intermediate quantities for weight estimation, and to provide a sheep face recognition and weight prediction method and system based on deep learning.
[0006] To achieve the above objectives, the present invention employs the following technical solution: The first aspect of this invention provides a deep learning-based method for sheep face recognition and weight prediction, comprising the following steps: Acquire images or video streams of sheep and their corresponding depth maps, and perform normalization and pixel standardization processing on the images or video streams of sheep to obtain the image to be processed; An object detection network is used to identify the image to be processed, and the sheep face region, sheep body region and instance mask are obtained; Feature extraction is performed on the sheep face region to obtain a feature vector; the feature vector is compared with the individual vectors in the feature library. If the maximum similarity is greater than or equal to the first threshold, the corresponding identity is output; otherwise, it is marked as a new individual candidate. Based on the example mask, key points are estimated for the sheep body region; based on the key point estimation results of the sheep body region, combined with camera calibration parameters and depth map recovery scale, body size is estimated; the body size parameters include at least one of body length, chest circumference, body height and body width. The body size parameters, along with the shape and texture features extracted from the sheep's body region, are input into a weight regression network, which outputs a predicted weight value and an optional confidence level or confidence interval.
[0007] In one alternative embodiment, the object detection network employs the YOLO object detection model. In an optional embodiment, the feature extraction of the sheep face region employs a ResNet50 network including a BNNeck structure. In an alternative embodiment, the similarity comparison is performed using cosine similarity or Euclidean distance. In one alternative embodiment, the ViTPose network is used to estimate key points in the sheep's body region; the key points include the neck base, tail root, left acromion, right acromion, left knee, right knee, fore hooves, hind hooves, and back and loin. In one optional embodiment, body length is calculated by fitting a curve of the line connecting the base of the neck and the base of the tail and the back and loins; chest circumference is calculated by the equivalent ellipse circumference of the chest cross-sectional profile; body height is calculated by the vertical distance from the ground to the left and right acromions; and body width is calculated by the three-dimensional distance between the left and right acromions. The body size estimation adopts a multi-frame fusion method. In one alternative embodiment, the weight regression network includes an attention fusion layer and a regression head; the regression head is an attention-enabled multilayer perceptron or a lightweight Transformer, trained using a Gaussian negative log-likelihood loss function or Huber loss, and outputs a confidence interval through uncertainty estimation. A second aspect of the present invention provides an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the aforementioned deep learning-based sheep face recognition and weight prediction method. A third aspect of the present invention provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the aforementioned deep learning-based sheep face recognition and weight prediction method. A fourth aspect of the present invention provides a deep learning-based sheep face recognition and weight prediction system, comprising: The image acquisition module acquires images or video streams of sheep, and performs normalization and pixel value standardization processing on the images or video streams of sheep to obtain the image to be processed. The target detection and segmentation module uses a target detection network to identify the image to be processed, and obtains the sheep face region, sheep body region and instance mask; The sheep face recognition module extracts features from the sheep face region to obtain a feature vector; it then compares the feature vector with the individual vectors in the feature library. If the maximum similarity is greater than or equal to a first threshold, the corresponding identity is output; otherwise, it is marked as a new individual candidate. The body size parameter estimation module estimates key points of the sheep body region based on the instance mask; and estimates body size parameters based on the key point estimation results of the sheep body region, combined with camera calibration parameters and depth map recovery scale; the body size parameters include at least one of body length, chest circumference, body height and body width. The weight prediction module inputs the body size parameters and shape and texture features extracted from the sheep's body region into the weight regression network, and outputs the predicted weight value and an optional confidence level or confidence interval.
[0008] Compared with the prior art, the present invention has the following beneficial effects: This invention discloses a deep learning-based method for sheep face recognition and weight prediction. It accurately locates the sheep's face region through a target detection network and uses feature vector similarity comparison to identify individual sheep. Compared to traditional manual labeling or simple visual recognition methods, this method effectively improves the accuracy and robustness of sheep identification. The intelligent labeling of new individual candidates facilitates rapid record-keeping by farmers, significantly improving the efficiency of sheep identification management in large-scale farming and reducing the error rate of manual identification.
[0009] Furthermore, this invention utilizes instance masks to assist in estimating key points in the sheep's body region and combines camera calibration parameters with the recovery scale of the depth map to calculate body size parameters, achieving automation and intelligence in body size estimation. This method overcomes the subjectivity, error, and high labor costs associated with manual body size measurement. Simultaneously, the integration of depth information effectively compensates for the limitations of two-dimensional images in scale perception, significantly improving the accuracy and reliability of body size parameter estimation, such as body length, chest circumference, body height, and body width.
[0010] Furthermore, by combining body size parameters with the shape and texture features of the sheep's body region into the weight regression network, the multidimensional features of the sheep's appearance are fully utilized. This makes the input dimensions of the weight prediction model richer and the feature representation more comprehensive, significantly improving the accuracy of weight predictions compared to regression models that rely solely on body size parameters. Simultaneously, the entire weight prediction process is based on real-time image or video stream processing, enabling rapid output of prediction results and selectable confidence levels or confidence intervals. This achieves non-contact, real-time monitoring of sheep weight, solving the problems of traditional weighing methods being time-consuming, labor-intensive, prone to causing stress to sheep, and unable to be monitored frequently.
[0011] In summary, this invention comprehensively applies deep learning technology to sheep identification and weight prediction, achieving automated collection and analysis of livestock data. This provides crucial technical support for the digital management of large-scale, intensive sheep farming. Through precise correlation between individual sheep identification and weight data, farmers can efficiently grasp information such as flock growth status and individual developmental differences. This provides data support for farming decisions such as precise feeding, disease early warning, and breeding selection, promoting the transformation of the sheep farming industry from traditional experience-based management to data-driven intelligent management, and improving overall farming efficiency and industry competitiveness. Attached Figure Description
[0012] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 This is a flowchart of the sheep face recognition and weight prediction method based on deep learning according to the present invention. Figure 2 A schematic diagram illustrating the acquisition of color and depth images of sheep using an RGB-D camera; Figure 3 This diagram illustrates the segmentation of the sheep's face and body regions and the detection of key points. Detailed Implementation
[0014] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations.
[0015] Therefore, the following detailed description of the embodiments of the invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the invention without inventive effort are within the scope of protection of the invention.
[0016] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0017] The present invention will now be described in further detail with reference to the accompanying drawings: See Figure 1 This invention discloses a deep learning-based method for sheep face recognition and weight prediction. In specific implementation, RGB-D depth cameras are deployed at the sheepfold entrances and exits, feeding passages, and activity areas. The camera frame rate is set to 15fps, and the resolution is [missing information]. To meet the requirements of high-definition image acquisition, adjustable spectral and brightness LED supplementary lights are used to simulate the impact of different lighting conditions on the acquisition effect of sheep face images, thereby evaluating the robustness of the model in multi-light environments. All cameras are connected to the local area network via an industrial switch, supporting hardware timestamp synchronization with a synchronization error ≤1ms. A two-tier "edge + cloud" architecture is adopted. The edge side uses embedded computing modules supporting TensorRT inference (such as the Jetson series) to handle real-time preprocessing, object detection, keypoint estimation, and rough body size calculation. The cloud deploys a GPU server with a high-performance graphics card (such as an NVIDIA RTX 3070 or equivalent) with at least 8GB of GPU memory and at least 16GB of system memory for feature library management, high-precision weight regression, cluster reconstruction, and data storage. The edge and cloud communicate via a reliable network to ensure low latency data transmission. Configure a database server (supporting MySQL clusters) with sufficient storage capacity to meet the long-term retention requirements of millions of sheep identification information, weight data, body size parameters, image data, and system logs. Simultaneously, configure industrial switches and network security equipment to ensure system network stability and data security. The cloud-based system includes a clustering center table (cluster_id, size, center_vec, mem_pos), an access count statistics table (cluster_id, in_mem, visits), and an in-memory feature vector table (contiguous storage blocks, maximum length max_len). Query vectors... First, calculate the similarity with the center table, then select Top- Clustering; load clusters not in memory in descending order of visits; if memory is insufficient, evict them block by block from the end and update mem_pos; perform vector-level comparisons only within loaded blocks, reducing the amortized complexity from... Down to .
[0018] Specifically, the following steps are included: Step 1: Acquire images or video streams of sheep, and perform size normalization and pixel standardization on the images or video streams of sheep to obtain the image to be processed; The images or video streams originate from industrial-grade RGB or RGB-D cameras deployed above sheepfold passages, weighing areas, or grazing fences. The acquisition frame rate is no less than 15 fps, the spatial resolution is 1280×720 to 1920×1080, and the cameras have automatic exposure and wide dynamic range (WDR) capabilities. When a depth camera is connected, color images and corresponding depth maps are acquired simultaneously, and the deviation between RGB and depth frames is ensured to be less than 50 ms through hardware triggering or software timestamp alignment mechanisms. Normalization processing includes four sub-processes: (1) Optical distortion correction, using the camera intrinsic parameter matrix and distortion coefficients obtained based on the checkerboard calibration board to perform reverse mapping interpolation on the image; (2) Color and brightness normalization, using white balance algorithms (such as gray-world method or perfect reflection method) to unify the color temperature, and then using histogram equalization or CLAHE (contrast-limited adaptive histogram equalization) to enhance details in low-light areas; (3) Noise suppression, applying non-local mean (NL-Means) filtering or lightweight CNN denoising models (such as DnCNN lightweight version) to high ISO or low-light images; (4) Scale unification, scaling all inputs to a fixed short side (such as 640 pixels), maintaining the original aspect ratio and filling the edges to adapt to the input size of the subsequent detection network. To evaluate the robustness of the model under different lighting conditions, the system is equipped with LED fill lights with adjustable spectrum and brightness. By adjusting the lighting angle and intensity, various ambient light conditions (such as daytime, dusk and nighttime scenes) are simulated, and the impact of lighting changes on the quality of sheep face images and feature extraction effects is analyzed. The normalization process can be configured as offline preprocessing or online real-time pipeline, and can also be dynamically adjusted—for example, enabling infrared illumination and switching to the green channel enhancement strategy in night mode, enabling a defogging network (such as AOD-Net) as a front-end module in rainy and foggy weather, and automatically enabling the defogging network when the image contrast is lower than a threshold (such as 0.3) or the visibility is lower than a preset value.
[0019] Step 2: Use an object detection network to identify the image to be processed, and obtain the sheep face region, sheep body region and instance mask; The target detection network is an end-to-end trainable single-stage detector used to simultaneously locate the faces and bodies of multiple sheep in a single forward propagation. The sheep face region refers to a compact bounding box that includes the sheep's facial contours, eyes, nose, and part of the forehead, with an aspect ratio typically between 0.8:1 and 1.2:1. The sheep body region refers to a looser bounding box that covers the main body of the sheep's torso (including shoulders, back, waist, and buttocks), with an aspect ratio of approximately 1.5:1 to 2.5:1. The instance mask refers to a binary pixel-level mask added to the output of a detection model that supports instance segmentation (such as YOLOv8-Seg and YOLOv11-Seg), used to accurately define the sheep's body contours and exclude interference from limbs, head, and background. The mask resolution is consistent with the input image (e.g., 640×640). This step supports two deployment modes: one is dual-head detection, where the same network backbone outputs bounding boxes and corresponding masks for sheep faces and sheep bodies respectively; the other is single-head multi-class detection, where "sheep face" and "sheep body" are defined as two independent categories, sharing classification and regression branches. After non-maximum suppression (NMS), candidate boxes with a confidence score ≥0.4 are retained, and soft NMS is performed on adjacent boxes to mitigate occlusion-related missed detections. As an optional embodiment, this detection network can also be replaced with Faster R-CNN (ResNet50-FPN backbone), DETR (with deformable attention), or RT-DETR (real-time Transformer), as long as it can stably output the above three types of structured outputs. The total loss of the object detection network can be:
[0020] in, The term represents the cross-entropy of the side length distribution; where, Let be the total loss function of the object detection network. Represents classification loss, P t This represents the model's predicted probability for the correct category. This is a balancing factor used to control the weights of positive and negative samples. As an adjustment factor, the weight of easily classified samples is reduced; L1 loss for the bounding box; For generalized IoU loss, among which B For the true frame, For prediction boxes; This is the boundary distribution loss. For classification loss weights, The bounding box coordinates are used as the regression loss weights. Weighting for IoU loss. The weights are the weights for the distributed regression loss.
[0021] Step 3: Extract features from the sheep face region to obtain feature vectors; compare the similarity of the feature vectors with the individual vectors in the feature library. If the maximum similarity is greater than or equal to the first threshold, output the corresponding identity; otherwise, mark it as a new individual candidate. In this process, feature extraction employs a deep convolutional neural network to encode the cropped sheep face image. The input image undergoes context expansion (expanding the original detection box by 10%–15% pixels to preserve the neck transition region), is then scaled to 224×224, and after standardization, is fed into the backbone network. The backbone network uses a ResNet50 architecture, with its last layer being a global average pooling layer followed by a BNNeck layer (Batch Normalization + Linear Projection), outputting 512-dimensional or 2048-dimensional L2-normalized feature vectors. This ensures that the vector distribution is concentrated on a unit hypersphere, which is beneficial for cosine similarity calculation. The feature library is a memory-resident vector database that stores feature vectors of historically registered individuals indexed by sheep ID, supporting incremental writing and batch updates. Similarity comparison uses either cosine similarity or Euclidean distance; cosine similarity is preferred due to its greater robustness to changes in lighting and posture. The first threshold is a dynamically adjustable parameter, initially set to 0.65 (corresponding to cosine similarity), and temperature scaling calibration is performed in the production environment using ground truth labels within a scrolling window (i.e.,...). This helps avoid an increase in the false recognition rate due to model drift or sudden environmental changes.
[0022] ResNet50 refers to a deep residual network (50 layers). Its backbone structure consists of four residual block groups (Stage 1–Stage 4), each containing multiple residual units with skip connections. This effectively alleviates the gradient vanishing problem during deep network training and provides powerful multi-scale local texture and global structure representation capabilities. The network input is a normalized preprocessed sheep face image region (224×224 pixels), and the output is a feature vector after global average pooling (GAP). Its convolutional kernel size is 3×3, stride is 1, padding is "same", and the number of channels in each stage is 64, 128, 256, and 512 respectively. The final feature dimension before the fully connected layer is 2048 dimensions. In actual deployment, the last two residual blocks can be replaced with lightweight modules (such as the Inverted Residual in MobileNetV3) depending on the computing power constraints of edge devices. Alternatively, the number of channels can be uniformly reduced to 0.5 times the original ratio (i.e., 32 / 64 / 128 / 256) while still maintaining the integrity of the ResNet topology and feature discriminativeness. The BNNeck (Batch Normalization Neck) structure refers to a batch normalization layer inserted after the global average pooling layer and before the fully connected classification head. Its function is not merely numerical stabilization, but rather feature decoupling. This separates the classification task (performed by the fully connected layer + Softmax) used for supervised training from the embedding task (i.e., the feature vectors themselves) used for retrieval and matching in terms of optimization objectives. The BN layer forces the output features to satisfy a zero-mean, unit-variance distribution, ensuring that subsequent similarity calculations (such as cosine similarity) are no longer affected by feature amplitude scales, significantly improving vector comparability across samples, lighting conditions, and poses. The parameters of this BN layer ( , It participates in end-to-end training without freezing; it can be followed by an optional L2 normalization layer (or executed uniformly by the inference engine on the output side) to form a fixed-length and orientation-sensitive embedding vector; when the output dimension is set to 512 dimensions, it is achieved by adding a 1×1 convolutional dimensionality reduction module (input 2048 dimensions, output 512 dimensions, no bias, activation function is linear) after the BN layer; when the output dimension is set to 2048 dimensions, the GAP output is directly taken and processed by the BN layer without dimensionality reduction; both configurations are compatible with the ArcFace loss function's optimization requirements for angular boundaries. Step 4: Based on the instance mask, estimate the key points of the sheep body region; In this step, the instance mask serves as a Region of Interest (ROI) mask, constraining the search range of the keypoint estimation network. It generates heatmap responses only within the masked area, significantly suppressing background false responses. The keypoint estimation network is the ViTPose model, which takes the masked sheep image as input and outputs two-dimensional coordinate heatmaps of at least eight anatomical keypoints, including the cervical base, tail root, left / right acromion, left / right knee, left / right front paw, and left / right hind paw. Each keypoint heatmap uses a Gaussian kernel (GK). The system generates a supervisory signal (pixel-level) and uses the point-by-point L2 norm mean as the loss function. ViTPose employs the Swin Transformer as its backbone, possessing strong long-range modeling capabilities and natural robustness to limb occlusion and perspective distortion. Its output keypoint coordinates are upsampled to the original image resolution via bilinear interpolation and achieve sub-pixel accuracy through heatmap peak localization. As an optional embodiment, this keypoint estimation module can also be replaced with HRNet-W32 (high-resolution network), PoseFormer (spatiotemporal Transformer), or LightweightOpenPose (lightweight OpenPose), as long as it can stably output the aforementioned set of anatomical keypoints. The mask can also be generated independently by a semantic segmentation network (such as SegFormer), without relying on the output of the detection network.
[0023] The key point heatmap loss can be selected as follows:
[0024] in, Losses due to key point thermal calculations, The total number of key points. For the first Key point index, For the first The true features of a key point, For the first Predictive heatmaps of key points.
[0025] Step 5: Based on the key point estimation results of the sheep's body area, combined with the camera calibration parameters and the depth map recovery scale, perform body size estimation; body size includes at least one of the following body size parameters: body length, chest circumference, body height, and body width. The camera calibration parameters include the intrinsic parameter matrix as follows:
[0026] The intrinsic parameter matrix and extrinsic parameter R / t (rotation R and translation t) are determined before deployment using the Zhang Zhengyou calibration method. The depth map is a pixel-by-pixel depth value matrix strictly aligned with the color image, in millimeters. Scale restoration employs a dual-path fusion strategy: when a depth map exists, effective depth pixels within the mask are selected first, and then filtered by median filtering and spatial consistency (outliers with a depth difference > 50 mm from their neighbors are removed). The vertical distance from each key point to the ground is obtained by combining ground plane fitting (RANSAC algorithm fitting z = ax + by + c). When no depth map exists, the pixel-to-meter scaling factor ρ (unit: m / pixel) is calculated based on the measured dimensions of the calibration board and applied to the calculation of the two-dimensional coordinate difference of the key points. The body size parameters are specifically defined as follows: (1) Body length: the three-dimensional Euclidean distance along the line connecting the base of the neck to the base of the tail, or the arc length calculated after fitting a B-spline curve based on the key points of the back and waist (base of the neck, 1st / 3rd / 5th lumbar vertebrae, and base of the tail); (2) Chest circumference: the chest cross-sectional profile is cut at the level of the 5th to 6th thoracic vertebrae, the minimum circumscribed ellipse is fitted, and its circumference is taken; (3) Body height: the average z-coordinate of the left and right acromion points minus the z-coordinate of the ground, i.e., the vertical height; (4) Body width: the Euclidean distance between the projections of the left and right acromion points onto the xy plane, reflecting the degree of transverse development of the trunk. This step supports multi-frame fusion: the estimated values of each body size parameter are obtained within the time window W = 3 to 5 frames. Empowerment The weighted fusion yields the final estimate, and outlier frames are removed using the MAD (Median Absolute Deviation) threshold. Specifically, the fusion expression is: ;in, These are weighting coefficients. The standard deviation of the current frame, For stability, For the final estimate after fusion, This is an estimate for each frame. This represents the overall variance of the estimated results after fusion.
[0027] Step 6: Input the body size parameters and the shape and texture features extracted from the sheep body region into the weight regression network, and output the predicted weight value and the optional confidence level or confidence interval.
[0028] Input multimodal features Among them, the body size parameter is a 4-dimensional scalar vector [x_length, x_girth, x_height, x_width], which is concatenated with other modal features after Z-score standardization; "shape features" are extracted from the sheep body mask contour using Fourier descriptors (first 20 harmonic coefficients) or Hu moments (7 invariant moments) to characterize the overall contour geometry; "texture features" are extracted using the gray-level co-occurrence matrix (GLCM) to extract 16-dimensional statistics of contrast, correlation, energy and homogeneity, or the global texture embedding (512-dimensional) of the mask ROI is extracted using a pre-trained EfficientNet-B0 backbone network. The weight regression network employs a multimodal fusion architecture. The front end consists of an attention fusion layer (such as Cross-Attention or MLP-Mixer) that weights and aligns three types of heterogeneous features. The back end is the regression head, which can be either a multilayer perceptron with channel attention (MLP, containing 3 fully connected layers, 512 units per layer, GELU activation) or a lightweight Transformer (2 encoder layers, 8-head attention, 512 hidden dimensions), outputting the predicted weight value. Together with the logarithm and variance log σ², they form a Gaussian distribution. Training primarily employs Gaussian negative log-likelihood loss (Gaussian NLL), supplemented by Huber loss (δ = 1.0) to enhance robustness to abnormal weight samples; after deployment, predicted weight values are output. and 95% confidence interval As an alternative embodiment, the regression network can also be replaced with a Bayesian neural network (BNN) or Monte Carlo Dropout to achieve uncertainty estimation, or a small-sample linear calibration layer can be introduced (such as...). ), and quickly adapt to the physiological characteristics of local sheep flocks by using the true values of 3 to 5 sets of weighbridges on site.
[0029] Through the above steps, this invention achieves the organic synergy of non-contact sheep individual identification and weight prediction: the normalization process in step one provides a stable and consistent input basis for subsequent modules, eliminating environmental interference; the target detection in step two accurately separates the semantic regions of the sheep's face and body, providing a structured premise for parallel processing of the two branches; the sheep face feature extraction and comparison in step three constructs a high-confidence identity anchor point, ensuring the reliability of the ID link; steps four and five together constitute a closed loop for body size estimation, using anatomical key points as geometric constraints and combining depth / calibration information to map the two-dimensional image coordinates into a physically meaningful three-dimensional body size, enabling the weight estimation process to have measurable, verifiable, and calibrable intermediate variables to support it; the multimodal regression in step six deeply integrates the interpretable body size with the invisible but information-rich shape / texture features, outputting uncertainty quantification while ensuring accuracy, supporting risk decision-making. Because steps one through six form a complete causal chain of "perception-segmentation-recognition-geometric modeling-regression reasoning," this application effectively overcomes the technical problems of traditional contact recognition being prone to failure, the difficulty in popularizing weighbridges, and the inability to interpret end-to-end weight estimation. Ultimately, it achieves the core capabilities of intelligent aquaculture with high precision (MAE weight ≤2.6 kg), high throughput (≥15 fps), scalability (supporting a million-level ID library), and deployability (edge-side TensorRT optimization).
[0030] In one embodiment of the present invention, feature vectors are obtained by extracting features from the sheep face region; the feature vectors are then compared with the individual vectors in the feature library for similarity; the similarity comparison refers to comparing the feature vectors extracted from the current sheep face region with the feature vector set of registered individuals in the feature library one by one to determine whether the sheep is a known individual or a new individual candidate.
[0031] Cosine similarity is defined as the cosine of the angle between two vectors, and its calculation formula is as follows:
[0032] in, To query the feature vector (i.e., the one extracted from the current sheep face). For the first feature in the feature library The feature vectors of each registered individual; after L2 normalization, the cosine similarity is equivalent to the vector dot product, and its value range is... A value closer to 1 indicates stronger directional consistency and higher semantic similarity. This metric is insensitive to vector magnitude and is suitable for deep identity features output and standardized by the BNNeck structure. It is particularly well-suited for scenarios where feature distribution drift occurs across lighting conditions, devices, and time periods—for example, when multiple RGB cameras are deployed in different sheep pens in a pasture, lens distortion and white balance differences can cause fluctuations in the amplitude of the feature vector for the same sheep, but the direction remains stable. In this case, cosine similarity can maintain high matching stability. As an optional implementation, the system can configure temperature scaling parameters during the inference phase. Calibrate the original similarity: ,in The range of values is The optimal value is determined by minimizing the cross-entropy of the validation set, thereby alleviating the problem of excessive concentration of model confidence. Euclidean distance is defined as the straight-line distance between two vectors in Euclidean space, and the formula is as follows:
[0033] Its value range is A smaller distance indicates a closer spatial location. This metric is sensitive to differences in vector magnitude and is suitable for scenarios where normalization is not implemented or where the original feature energy information needs to be preserved—for example, after introducing domain-adaptive fine-tuning, some feature dimensions respond more effectively, allowing Euclidean distance to more precisely distinguish similar individuals (lambs of the same parity, breed, or coat color), thus improving fine-grained discrimination capabilities. As an optional implementation, the system supports mapping the Euclidean distance results to an inverse sigmoid transformation. Intervals are used to form equivalent similarity: ,in This is a scaling factor, with a value range of [value range missing]. This is used to adjust the distance sensitivity, making it easier to unify the threshold determination logic with cosine similarity.
[0034] In one embodiment of the present invention, an electronic device is provided, comprising a processor and a memory. The memory stores a computer program, which includes program instructions. The processor executes the program instructions stored in the computer storage medium. The processor may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to achieve a corresponding method flow or corresponding function. The processor described in this embodiment of the present invention can be used for the operation of a deep learning-based sheep face recognition and weight prediction method.
[0035] In one embodiment of the present invention, a storage medium is also provided, specifically a computer-readable storage medium (Memory), which is a memory device in a terminal device for storing programs and data. It is understood that the computer-readable storage medium here can include both the built-in storage medium in the terminal device and extended storage media supported by the terminal device; it can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. The computer-readable storage medium provides storage space that stores the terminal's operating system. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by a processor, which can be one or more computer programs (including program code). It should be noted that more specific examples (a non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0036] Computer-readable storage media also include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable storage medium can also be any readable medium other than a readable storage medium that can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0037] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C, Python, or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0038] One or more instructions stored in a computer-readable storage medium can be loaded and executed by a processor to implement the corresponding steps of the deep learning-based sheep face recognition and weight prediction method in the above embodiments.
[0039] One embodiment of the present invention provides a sheep face recognition and weight prediction system based on deep learning, comprising: The image acquisition module acquires images or video streams of sheep, and performs normalization and pixel standardization processing on the images or video streams of sheep to obtain the image to be processed. The target detection and segmentation module uses a target detection network to identify the image to be processed, and obtains the sheep face region, sheep body region and instance mask; The sheep face recognition module extracts features from the sheep face region to obtain a feature vector; it then compares the feature vector with the individual vectors in the feature library. If the maximum similarity is greater than or equal to a first threshold, the corresponding identity is output; otherwise, it is marked as a new individual candidate. The body size parameter estimation module estimates key points of the sheep body region based on the optional instance mask; and estimates body size based on the key point estimation results of the sheep body region, combined with camera calibration parameters and depth map recovery scale; the body size parameters include at least one of body length, chest circumference, body height and body width. The weight prediction module inputs the body size parameters and shape and texture features extracted from the sheep's body region into the weight regression network, and outputs the predicted weight value and an optional confidence level or confidence interval.
[0040] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for sheep face recognition and weight prediction based on deep learning, characterized in that, Includes the following steps: Acquire images or video streams of sheep and their corresponding depth maps, and perform normalization and pixel standardization processing on the images or video streams of sheep to obtain the image to be processed; An object detection network is used to identify the image to be processed, and the sheep face region, sheep body region and instance mask are obtained; Feature extraction is performed on the sheep face region to obtain a feature vector; the feature vector is compared with the individual vectors in the feature library. If the maximum similarity is greater than or equal to the first threshold, the corresponding identity is output; otherwise, it is marked as a new individual candidate. Based on the example mask, key points are estimated for the sheep body region; based on the key point estimation results of the sheep body region, combined with the camera calibration parameters and the recovery scale of the depth map, body size parameters are estimated; the body size parameters include at least one of body length, chest circumference, body height and body width. The body size parameters, along with the shape and texture features extracted from the sheep's body region, are input into a weight regression network to output a predicted weight value.
2. The sheep face recognition and weight prediction method based on deep learning according to claim 1, characterized in that, The target detection network uses the YOLO target detection model.
3. The sheep face recognition and weight prediction method based on deep learning according to claim 1, characterized in that, The feature extraction of the sheep face region employs a ResNet50 network including a BNNeck structure.
4. The sheep face recognition and weight prediction method based on deep learning according to claim 1, characterized in that, The similarity comparison is performed using cosine similarity or Euclidean distance.
5. The sheep face recognition and weight prediction method based on deep learning according to claim 1, characterized in that, The ViTPose network was used to estimate key points in the sheep's body region; the key points included the neck base, tail root, left acromion, right acromion, left knee, right knee, fore hooves, hind hooves, and back and loin.
6. The sheep face recognition and weight prediction method based on deep learning according to claim 1, characterized in that, Body length is calculated by fitting the curve of the line connecting the base of the neck and the base of the tail and the back and loin; chest circumference is calculated by the equivalent ellipse circumference of the chest cross-section contour; body height is calculated by the vertical distance from the ground to the left and right acromions; body width is calculated by the three-dimensional distance between the left and right acromions; the body size parameters are estimated using a multi-frame fusion method.
7. The sheep face recognition and weight prediction method based on deep learning according to claim 1, characterized in that, The weight regression network includes an attention fusion layer and a regression head; the regression head is an attention-enabled multilayer perceptron or a lightweight Transformer, trained using a Gaussian negative log-likelihood loss function or Huber loss, and outputs a confidence interval through uncertainty estimation.
8. An electronic device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the deep learning-based sheep face recognition and weight prediction method according to any one of claims 1-7.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the deep learning-based sheep face recognition and weight prediction method according to any one of claims 1-7.
10. A deep learning-based sheep face recognition and weight prediction system, characterized in that, include: The image acquisition module acquires images or video streams of sheep and corresponding depth maps, and performs normalization and pixel standardization processing on the images or video streams of sheep to obtain the image to be processed. The target detection and segmentation module uses a target detection network to identify the image to be processed, and obtains the sheep face region, sheep body region and instance mask; The sheep face recognition module extracts features from the sheep face region to obtain a feature vector; it then compares the feature vector with the individual vectors in the feature library. If the maximum similarity is greater than or equal to a first threshold, the corresponding identity is output; otherwise, it is marked as a new individual candidate. The body size parameter estimation module estimates key points of the sheep body region based on the instance mask; and estimates body size parameters based on the key point estimation results of the sheep body region, combined with camera calibration parameters and the recovery scale of the depth map; the body size parameters include at least one of body length, chest circumference, body height and body width. The weight prediction module inputs the body size parameters and the shape and texture features extracted from the sheep's body region into the weight regression network and outputs the predicted weight value.