Disease recognition method and system based on fusion of pig feces appearance and excretion behavior
By employing high- and low-position cameras combined with a lightweight MobileNetV4-YOLO network and a bidirectional GRU network in pig farming, the problems of high misjudgment rate and model adaptation in pig disease identification were solved, achieving efficient and real-time disease monitoring.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- SOUTH CHINA AGRICULTURAL UNIVERSITY
- Filing Date
- 2026-04-20
- Publication Date
- 2026-07-21
AI Technical Summary
Existing technologies lack the ability to effectively integrate the temporal behavioral characteristics and spatial appearance characteristics of the excretion process in pig farming, resulting in a high misjudgment rate in disease identification. Furthermore, high-precision models cannot be adapted to edge computing devices, making it difficult to achieve real-time monitoring.
A disease identification method based on the fusion of pig fecal appearance and excretion behavior is adopted. Data is collected by high- and low-position cameras, and the MobileNetV4-YOLO lightweight network and bidirectional GRU network are combined to perform data cleaning and enhancement, realize decision-level multimodal feature fusion, and generate comprehensive disease risk probability.
It improves the accuracy and recall of disease identification, reduces the computational complexity of the model, enables real-time monitoring on edge devices, and reduces human intervention and stress response.
Smart Images

Figure CN122067199B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of disease early warning methods, specifically relating to a disease identification method and system based on the fusion of pig fecal appearance and excretion behavior. Background Technology
[0002] Current monitoring technologies mainly include manual inspection, contact sensor monitoring, and non-contact computer vision monitoring. Manual inspection relies primarily on the naked eye of the farmer, which suffers from strong subjectivity and significant time lag. While contact monitoring using ear tags or collars can obtain body temperature data, it cannot detect digestive tract lesions and easily causes stress to pigs. In contrast, non-contact visual monitoring technology using cameras combined with deep learning algorithms has the advantages of being stress-free and having broad coverage, and has gradually become a research hotspot. Although computer vision technology has been applied to pig monitoring, existing technologies still have the following significant shortcomings in the comprehensive identification and edge applications of the complex physiological process of excretion.
[0003] First, existing technologies generally suffer from limitations in extracting single-modal features and lack deep fusion of appearance and temporal features. Regarding appearance features, current fecal detection methods are mostly based on general object detection algorithms for static images. However, due to the complex environment of pigsties, with interference from feed residue, old feces, urine stains, and slatted floors, and significant variations in target scale, existing models are prone to misclassifying background noise as pathological feces or missing minute bloody features. Regarding temporal features, existing behavioral monitoring focuses primarily on static postures such as standing or lying down, lacking analysis of long-term action processes in video streams. This makes it difficult to distinguish between physiological standing and resting and pathological constipation with arched backs, and also fails to capture the brief tremors during defecation. More critically, existing technologies lack effective decision-level fusion mechanisms, failing to spatiotemporally correlate the pig's ongoing defecation action with the features of the subsequent excrement, leading to a broken chain of diagnostic evidence and a high false alarm rate.
[0004] Secondly, there is a contradiction between the computational redundancy of high-precision models and the requirements for real-time monitoring at the edge. To address environmental interference and improve detection accuracy, existing research tends to use complex deep neural network models, which typically have a huge number of parameters and high floating-point computation requirements. However, modern smart farms are usually only equipped with edge devices such as embedded industrial PCs or mobile terminals with limited computing power. Existing large models are difficult to implement real-time inference of video streams on these devices, while existing lightweight models often sacrifice the accuracy of recognizing minute lesion features.
[0005] In summary, the existing technology lacks a swine disease identification scheme that can effectively integrate the temporal behavioral features and spatial appearance features of the excretion process, while also taking into account the lightweight model structure and strong anti-interference ability. Summary of the Invention
[0006] To address the aforementioned shortcomings in existing technologies, the disease identification method and system based on the fusion of pig fecal appearance and excretion behavior provided by this invention solves the problems of high misjudgment rate of single-modal features, high missed detection rate of minor pathological signs, and inability of high-precision models to adapt to edge computing devices in existing automated monitoring of pig farming.
[0007] To achieve the aforementioned objectives, the present invention employs the following technical solution: a disease identification method based on the fusion of pig fecal appearance and excretory behavior, comprising the following steps:
[0008] S1. Take images of pigs in the pigpen using the data acquisition module to obtain raw video stream data;
[0009] S2. The original video stream data is preprocessed by the preprocessing module to obtain preprocessed image frames;
[0010] S3. Input the preprocessed image frame into the spatial feature extraction module to generate a high-dimensional semantic feature matrix, the excrement appearance anomaly classification results of the image frame and its probability confidence;
[0011] S4. Input the high-dimensional semantic feature matrix into the time-series behavior analysis module to generate the abnormal probability of excretion behavior;
[0012] S5. Input the probability confidence of the excrement appearance abnormality classification results and the probability of abnormal excretion behavior into the decision-level fusion and diagnosis module to generate a comprehensive disease risk probability and detect high-risk pig diseases.
[0013] Furthermore: In S1, the data acquisition module includes a high-position camera and a low-position camera. The high-position camera and the low-position camera adopt an installation strategy of "one high and one low, diagonally intersecting". The high-position camera is installed at a higher position than the low-position camera. The high-position camera is located at the top of the diagonal of the pigpen and is used to take pictures of the pigs in the pigpen from all directions, and to collect the macroscopic movement status and overall excretion posture of the pig group. The low-position camera is located at the bottom of the diagonal of the pigpen and is used to collect microscopic morphological data of the excrement landing.
[0014] Both the high-position and low-position cameras use the IEEE 1588 precise time protocol for clock synchronization locking of the frames acquired by the two cameras.
[0015] The specific method for obtaining the raw video stream data is as follows:
[0016] In response to the high-position camera detecting a pre-set suspected pre-excretion action in a pig, the high-position camera and the low-position camera are controlled to capture a predetermined number of consecutive image frames to generate raw video stream data.
[0017] Furthermore, in S2, the preprocessing methods include data cleaning and data augmentation. Data cleaning employs a frame-by-frame limit-contrast adaptive histogram equalization method, specifically as follows:
[0018] The images in the original video stream data are divided into The non-overlapping grid is used to independently calculate the histogram within each grid and set a clipping threshold to prevent local environmental noise from being excessively amplified. The grid boundaries are smoothed by bilinear interpolation, and the weak texture contrast between the dark manure board and the excrement is forcibly increased in a nonlinear mapping manner. At the same time, rotation, horizontal flipping and local clipping operations are randomly applied to the image to simulate and eliminate the observation angle deviation caused by camera installation errors or pig movement.
[0019] Data augmentation employs a dynamic Mosaic reconstruction strategy, which specifically includes:
[0020] Four image frames with different backgrounds are randomly captured from the original video stream data. A stitching center point coordinate is randomly generated in a unified canvas space. The four image frames are multiplied by independent affine transformation matrices and placed in the four quadrants of the canvas space. The coordinates of the actual bounding boxes of the targets in the image frames are simultaneously linearly mapped, and the parts that exceed the canvas boundaries are truncated.
[0021] The beneficial effects of the above-mentioned further solutions are as follows: This invention introduces an adaptive cleaning and dynamic Mosaic reconstruction strategy that targets minute pathological features, restores the reflectivity of fecal mucus against a dark background at night, and artificially creates a high-entropy background to expand difficult samples, thereby improving the model's ability to generalize pathological identification in real breeding environments.
[0022] Furthermore, in S3, the spatial feature extraction module is equipped with a lightweight MobileNetV4-YOLO network, including a backbone network, a neck network, a Mobile MQA detection layer, a total loss function layer, and a detection output layer. The Mobile MQA detection layer includes a first Mobile MQA detection head and a second Mobile MQA detection head. The first output of the backbone network is connected to the first input and the third input of the neck network, respectively. The second output of the backbone network is connected to the second input of the neck network. The first output of the neck network is connected to the input of the first Mobile MQA detection head, and the second output of the neck network is connected to the input of the second Mobile MQA detection head. The outputs of the first and second Mobile MQA detection heads are both connected to the detection output layer through the total loss function layer.
[0023] The backbone network consists of a first-layer feature extraction subnetwork to a fifth-layer feature extraction subnetwork connected in sequence. The output of the fourth-layer feature extraction subnetwork serves as the first output of the backbone network, and the output of the fifth-layer feature extraction subnetwork serves as the second output of the backbone network.
[0024] The neck network comprises, in sequence, a first Mobile MQA Fusion, a first upsampling module, a first stitching module, a second Mobile MQA Fusion, a second upsampling module, a second stitching module, a third Mobile MQA Fusion, a first C2f-UIB module, a second C2f-UIB module, a fourth Mobile MQA Fusion, a third stitching module, a third upsampling module, a third C2f-UIB module, and a fifth Mobile MQA Fusion. The input of the first Mobile MQA Fusion serves as the first input of the neck network, the input of the first stitching module serves as the second input, the input of the first C2f-UIB module serves as the third input, the output of the second C2f-UIB module serves as the first output, and the output of the third C2f-UIB module serves as the second output. The output of the first Mobile MQA Fusion is also connected to the input of the fifth Mobile MQA Fusion, the input of the first stitching module is also connected to the output of the fifth Mobile MQA Fusion, the input of the second stitching module is also connected to the output of the third stitching module, and the output of the third Mobile MQA Fusion is also connected to the input of the fourth Mobile MQA Fusion. Input connection for MQA Fusion.
[0025] Furthermore, the specific workflow of the backbone network is as follows:
[0026] The preprocessed image frames are input into the backbone network, and feature extraction is performed through each layer's feature extraction subnetwork to obtain the feature maps of each layer. Among these, the first... The first layer of feature extraction subnetwork extracts the first layer of features. Feature map of layer The specific expression is:
[0027]
[0028] In the formula, For the first Feature map of the layer For channel dimensionality reduction Pointwise convolution, It is a non-linear activation function. For depthwise separable convolutions in the middle of the network, For use in channel dimensional upgrading Pointwise convolution, For depthwise separable convolutions at the network front end;
[0029] The first and second Mobile MQA detection heads have the same structure, both incorporating a mobile multi-query attention mechanism unit. This unit forces all attention heads to share the same key-value matrix and introduces a depthwise convolution with a stride of 2 as a space reduction operation. The mobile multi-query attention mechanism unit calculates the attention... The specific expression is:
[0030]
[0031] In the formula, For normalized exponential functions, For query, For space reduction operation, As key, For value, As a dimension, It is the transpose symbol;
[0032] The total loss function layer has a total loss function set up. The specific expression is:
[0033]
[0034] In the formula, To expand the intersection-union ratio loss, Let SlideLoss be the sliding loss function. For the distribution focus loss, The first weighting balancing coefficient, This is the second weighting balancing coefficient. This is the third weighting balancing coefficient.
[0035] The beneficial effects of the above-mentioned further solutions are as follows: This invention designs a lightweight micro-feature extraction network, MobileNetV4-YOLO, for edge computing in pigsties. It introduces the Mobile MQA attention mechanism and the SlideLoss loss function, which is specifically designed to capture extremely weak early swine dysentery bloody mucus or abnormal fecal features with high precision in complex interference backgrounds such as slatted floors.
[0036] Furthermore: In S4, the temporal behavior analysis module includes a bidirectional cyclic temporal backtracking submodule, a time step attention focusing submodule, a fully connected layer, and a Softmax classifier connected in sequence. The bidirectional cyclic temporal backtracking submodule includes a forward GRU layer and a backward GRU layer, both of which are connected to the attention layer.
[0037] The workflow of the time-series behavior analysis module is as follows:
[0038] S41. Input the high-dimensional semantic feature matrix into the forward GRU layer and the backward GRU layer, calculate the forward hidden state and the backward hidden state respectively, and concatenate the forward hidden state and the backward hidden state into a comprehensive context feature.
[0039] S42. Input the comprehensive contextual features into the time step attention focusing submodule to obtain the global context vector;
[0040] S43. Input the global context vector into the fully connected layer and the Softmax classifier in sequence to generate an abnormal probability of excretory behavior with clear clinical guidance.
[0041] The beneficial effects of the above-mentioned further solutions are as follows: This invention constructs a bidirectional GRU macroscopic pathological behavior inference network that combines time step self-attention. By completely backtracking long-term excretion causal chains such as "vomiting before defecation" and "defecation rigidity", it accurately extracts disease shivering or tenesmus with high-risk clinical diagnostic value and eliminates interference from normal physiological movements.
[0042] Furthermore: In S41, the workflow of the forward GRU layer and the backward GRU layer is the same, specifically as follows:
[0043] Based on the high-dimensional semantic feature matrix Computational update gate ;
[0044]
[0045] In the formula, For the sigmoid function, , This is the first high-level semantic feature vector. For the first High-level semantic feature vectors For the first High-level semantic feature vectors For a moment The hidden state, This is the first bias parameter. This is the first weight parameter;
[0046] Based on the high-dimensional semantic feature matrix Calculate the reset door ;
[0047]
[0048] In the formula, This is the second bias parameter. This is the second weighting parameter;
[0049] According to the reset door Calculation time Candidate hidden state ;
[0050]
[0051] In the formula, It is the hyperbolic tangent function. As the third weighting parameter, For Hadama accumulation, This is the third bias parameter;
[0052] According to time Candidate hidden state and Update Gate Calculation time Hidden state ;
[0053]
[0054] In S42, the workflow of the time step attention focusing submodule is as follows:
[0055] Based on comprehensive contextual features Calculation time Importance score ;
[0056]
[0057] In the formula, This is the fourth weighting parameter. This is the fourth bias parameter;
[0058] Using the context parameter matrix Calculate the calculation time absolute attention weight ;
[0059]
[0060] In the formula, For a moment Importance score;
[0061] Based on comprehensive contextual features With time absolute attention weight Calculate the global context vector ;
[0062] .
[0063] Furthermore: In S5, the decision-level fusion and diagnosis module includes a sub-module for correlation reasoning and judgment rules and a sub-module for disease typing and response;
[0064] The comprehensive epidemic risk probability is calculated through the association reasoning and judgment rule submodule. The specific method for calculating the comprehensive epidemic risk probability is as follows:
[0065] A1. Calculate the Shannon entropy of the probability distribution based on the probability confidence score of the excrement appearance anomaly classification results. This entropy is used to quantify the uncertainty noise of the current visual environment. Specifically, the calculation of the Shannon entropy of the probability distribution... The specific expression is:
[0066]
[0067] In the formula, It is a high-dimensional semantic feature matrix. For the first The confidence level of the predicted probability for each apparent state category (e.g., water sample, blood sample, etc.). , The probability confidence level of the classification results of apparent abnormalities in excrement;
[0068] A2. The high-dimensional semantic feature matrix after global average pooling With global context vector The data is stitched along the channels, input into a multilayer perceptron, and the dynamic weight allocation for the bimodal modes is solved using a temperature-scaling Softmax function. ;
[0069]
[0070] In the formula, Assign weights dynamically to the first one. For the second dynamic allocation of weights, For the Softmax function, It is a multilayer perceptron. It is a global average pooling layer. For splicing operations, This is a temperature scaling factor used to control the smoothness of the output feature weight distribution;
[0071] A3. Based on dynamically allocated weights Calculate the overall probability of disease risk ;
[0072]
[0073] In the formula, The probability of abnormal excretory behavior. It is the spatiotemporal joint resonance factor;
[0074] High-risk swine diseases are detected through the disease typing and response submodule. The specific method for detecting high-risk swine diseases is as follows:
[0075] Swine dysentery detection: probability confidence level of classification results based on apparent abnormalities in excrement The predicted probability confidence level of the "bloody mucus / watery stool" apparent status category is greater than the preset first apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the "abdominal retraction and tenesmus" apparent condition category is greater than the preset first behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a swine dysentery warning will be triggered.
[0076] Detection of porcine epidemic diarrhea and transmissible gastroenteritis: Probability confidence of classification results of apparent abnormalities in feces The predicted probability confidence level of the apparent state category "acute vomiting and abnormally active drinking" is greater than the set apparent threshold and greater than the preset second apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the "yellow foamy watery stool" apparent state category is greater than the preset second behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a warning for porcine epidemic diarrhea and transmissible gastroenteritis will be triggered.
[0077] Detection of severe systemic infection of swine fever: probability confidence level of classification results of apparent abnormalities in feces The predicted probability confidence level of the "bright red bloody diarrhea" apparent state category is greater than the set apparent threshold and greater than the preset third apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the apparent state category "extreme weakness and malignant tremors" is greater than the preset third behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a warning for severe systemic infection of swine fever will be triggered.
[0078] In response to a situation where the overall disease risk probability exceeds the high-risk threshold, triggering a swine dysentery warning, a swine epidemic diarrhea and transmissible gastroenteritis warning, or a severe systemic infection warning for classical swine fever, the system integrates the pigsty location, the unique ID of the target pig, and the highlighted warning segment into the disease warning information and sends it to the user.
[0079] The beneficial effects of the above-mentioned further solutions are as follows: The present invention adopts a dynamic multimodal spatiotemporal fusion diagnostic mechanism based on gated expert networks and Shannon entropy, which dynamically weights and cross-verifies organic changes in feces (such as watery or bloody stools) and abnormal excretion behaviors (such as tenesmus and shivering), accurately mapping them to veterinary clinical diagnostic matrices such as swine dysentery and epidemic diarrhea, effectively solving the problem of misdiagnosis in single-modality studies.
[0080] A disease identification system based on the fusion of pig fecal appearance and excretory behavior includes:
[0081] The data acquisition module includes a high-position camera and a low-position camera. The high-position camera is used to collect the macroscopic movement status and overall excretion posture of the pig herd, while the low-position camera is used to collect the microscopic morphological data of the excrement landing.
[0082] The preprocessing module includes a data cleaning submodule and an image enhancement submodule. The data cleaning submodule is used to clean the raw video stream data, and the image enhancement submodule uses a dynamic Mosaic reconstruction strategy to enhance the raw video stream data.
[0083] The spatial feature extraction module is used to extract key static appearance features from the preprocessed image frames, generate a high-dimensional semantic feature matrix, the excrement appearance anomaly classification results of the image frames and their probability confidence scores.
[0084] The temporal behavior analysis module includes a bidirectional cyclic temporal backtracking submodule and a time step attention focusing submodule. The bidirectional cyclic temporal backtracking submodule takes a high-dimensional semantic feature matrix as input and extracts comprehensive contextual features in both the positive and negative dimensions of time. The time step attention focusing submodule calculates the global context vector based on the comprehensive contextual features through a self-attention mechanism.
[0085] The abnormal probability input decision-level fusion and diagnosis module is used to perform in-depth analysis on the data extracted by the spatial feature extraction module and the temporal behavior analysis module, generate comprehensive disease risk probabilities, and detect high-risk pig diseases.
[0086] The beneficial effects of this invention are as follows:
[0087] (1) This invention solves the problem of high misjudgment rate of single modality features by using a decision-level multimodal fusion mechanism. By constructing parallel visual and temporal channels, the probability confidence of the excrement appearance abnormality classification results reflecting the microscopic pathological features of excrement is extracted, and the probability of excretion behavior abnormality reflecting the macroscopic action features of the excretion process is extracted. The two are weighted using a dynamic weighting strategy to calculate the comprehensive disease risk probability, thereby realizing the joint analysis of appearance and temporal features. This design aims to utilize the strong logical correlation and complementarity between excretion action and excretion result to effectively eliminate false positive interference caused by ambient light, object occlusion, or physiological actions of pigs, thereby significantly improving the accuracy and recall rate of early symptoms of diseases such as swine fever and swine dysentery.
[0088] (2) This invention proposes a lightweight network architecture for edge computing environments to address the problem of high-precision models being difficult to deploy on-site. Addressing the common computing power bottlenecks faced by livestock farms, this invention aims to lightweight reconstruct complex visual detection models. By introducing MobileNetV4 as the backbone network and combining it with a Universal Inverse Bottleneck (UIB) module based on neural architecture search, the goal is to significantly reduce the number of model parameters and memory access cost (MAC). This objective ensures that the model can run smoothly on low-power edge devices such as embedded industrial control computers or surveillance camera chips while maintaining high-precision feature extraction capabilities, thereby achieving low-cost, real-time disease monitoring without relying on expensive servers.
[0089] (3) Enhance the multi-scale feature extraction and anti-interference capabilities under complex breeding environments to solve the problem of high false negative rates for subtle pathological signs. Addressing the challenges of complex pigsty backgrounds and large target scale variations, this invention introduces a C2f-UIB dynamic module and a lightweight panoramic feature pyramid (PAN-FPN) in the network neck to achieve effective fusion of deep semantics and shallow details. Simultaneously, by integrating a Mobile MQA mechanism and a SlideLoss sliding loss function into the detection head, the model is designed to filter out high-frequency environmental noise such as red paint and rust, enabling it to accurately locate and identify "difficult boundary samples" with latent pathological features such as trace amounts of blood streaks and mucus, further improving the model's robustness and recall in practical applications.
[0090] (4) To achieve non-contact, all-weather automated monitoring to solve the problems of lagging traditional detection and biosafety hazards. This invention aims to establish a complete intelligent monitoring closed loop, using monitoring video streams to replace manual inspections and contact operations. Through the automatic capture and analysis of pig excretion behavior by algorithms, the goal is to shift the disease detection window from the clinical symptom stage to the subclinical stage, achieving real-time early warning of disease conditions. This not only significantly reduces the intensity of manual labor but also completely eliminates the stress response and cross-infection risk to pigs caused by contact detection, thereby improving the biosafety management level of farms. Attached Figure Description
[0091] Figure 1 This is a flowchart of the disease identification method based on the fusion of pig fecal appearance and excretion behavior according to the present invention.
[0092] Figure 2 This is a schematic diagram of the disease identification system based on the fusion of pig fecal appearance and excretion behavior according to the present invention.
[0093] Figure 3 This is a schematic diagram of the data acquisition and preprocessing module.
[0094] Figure 4Workflow diagram for MobileNetV4-YOLO lightweight network.
[0095] Figure 5 This is a flowchart of the time-series behavior analysis module. Detailed Implementation
[0096] The specific embodiments of the present invention are described below to enable those skilled in the art to understand the present invention. However, it should be understood that the present invention is not limited to the scope of the specific embodiments. For those skilled in the art, various changes are obvious as long as they are within the spirit and scope of the present invention as defined and determined by the appended claims. All inventions utilizing the concept of the present invention are protected.
[0097] like Figure 1 and Figure 2 As shown, in one embodiment of the present invention, a disease identification method based on the fusion of pig fecal appearance and excretory behavior includes the following steps:
[0098] S1. Take images of pigs in the pigpen using the data acquisition module to obtain raw video stream data;
[0099] S2. The original video stream data is preprocessed by the preprocessing module to obtain preprocessed image frames;
[0100] S3. Input the preprocessed image frame into the spatial feature extraction module to generate a high-dimensional semantic feature matrix, the excrement appearance anomaly classification results of the image frame and its probability confidence;
[0101] S4. Input the high-dimensional semantic feature matrix into the time-series behavior analysis module to generate the abnormal probability of excretion behavior;
[0102] S5. Input the probability confidence of the excrement appearance abnormality classification results and the probability of abnormal excretion behavior into the decision-level fusion and diagnosis module to generate a comprehensive disease risk probability and detect high-risk pig diseases.
[0103] In S1, the data acquisition module includes a high-position camera and a low-position camera. The high-position camera and the low-position camera adopt an installation strategy of "one high and one low, diagonally intersecting". The high-position camera is installed at a higher position than the low-position camera. The high-position camera is located at the top of the diagonal of the pigpen and is used to take pictures of the pigs in the pigpen from all directions to collect the macroscopic movement status and overall excretion posture of the pig group. The low-position camera is located at the bottom of the diagonal of the pigpen and is used to collect microscopic morphological data of the excrement landing.
[0104] like Figure 3 As shown, in this embodiment, the present invention exemplifies a camera deployment method: a high-position camera is located at the top diagonal of a pigpen, 2.1 meters above the ground, so as to... to The camera independently captures the macroscopic spatial trajectory and trunk posture of the pigs (such as arching their backs, standing up and lying down) from a downward angle. The low-position camera is located at the bottom diagonal of the pigpen, 1.8 meters above the ground. to The eye-level angle penetrates the gaps between the groups, focusing on the area of the slatted floor to capture the microscopic morphology and texture changes of excrement as it falls to the ground. Both devices are set to 2560×1440 (2K) ultra-high definition resolution and 25fps frame rate.
[0105] Both the high-position and low-position cameras use the IEEE 1588 Precise Time Protocol (PTP) to lock the clock for dual-camera frame acquisition and eliminate frame alignment errors in dual-camera stitching.
[0106] In this embodiment, the raw video stream data is transmitted to the edge computing node for use by the spatial feature extraction module and the temporal behavior analysis module. The edge computing server acts as the master clock, and the two cameras act as slave clocks. The master and slave devices continuously exchange Sync, Follow_Up, Delay_Req, and Delay_Resp data packets with hardware-level timestamps to dynamically calculate and compensate for network path delay, achieving sub-microsecond clock synchronization. This ensures that the high-position camera captures the "abnormal arched back" movement in the first... The first frame and low-angle camera captured the "bloody feces on the ground" The frame achieves high-precision clock synchronization locking at the sub-microsecond level.
[0107] The specific method for obtaining the raw video stream data is as follows:
[0108] In response to the high-position camera detecting a pre-set suspected pre-excretion action in a pig, the high-position camera and the low-position camera are controlled to capture a predetermined number of consecutive image frames to generate raw video stream data.
[0109] In S2, the preprocessing methods include data cleaning and data augmentation. Data cleaning employs a frame-by-frame limit-contrast adaptive histogram equalization method, specifically as follows:
[0110] The images in the original video stream data are divided into The image uses a non-overlapping grid, with histograms calculated independently within each grid and a clipping limit set to prevent excessive amplification of local environmental noise. Grid boundaries are smoothed using bilinear interpolation, and the subtle texture contrast between the dark slatted floorboards and excrement is forcibly enhanced through nonlinear mapping. Simultaneously, the image is randomly rotated. ), horizontal flipping and partial cropping operations, to simulate and eliminate viewing angle deviations caused by camera installation errors or pig movement;
[0111] For extremely small-scale targets such as trace amounts of bloody stool and mucus, which belong to the long-tailed distribution, this data augmentation introduces a dynamic Mosaic reconstruction strategy. The data augmentation adopts a dynamic Mosaic reconstruction strategy, which is specifically as follows:
[0112] Four image frames with different backgrounds (such as rusty iron railings, dried urine stains, and clean latrines) are randomly extracted from the raw video stream data. A stitching center point coordinate is randomly generated within a unified canvas space. Each of the four image frames is multiplied by an independent affine transformation matrix and placed in one of the four quadrants of the canvas space. Simultaneously, the true bounding box coordinates of the targets in each image frame are subjected to the same linear mapping, and portions exceeding the canvas boundaries are truncated. This operation not only artificially creates a high-entropy interference background but also compresses the effective pixel ratio of the target, forcing the model to learn the most essential pathological topological features under extreme occlusion conditions.
[0113] Considering that the dynamic Mosaic reconstruction strategy inevitably produces unnatural artificial edges at image boundaries, which may severely interfere with the model's final learning of real minor lesions (such as the edges of blood vessels) during the fine-tuning phase, the system features a dynamic decay and hard thresholding mechanism. In the last 15 epochs of training the MobileNetV4-YOLO lightweight network, the system automatically triggers the threshold switch, completely disabling the dynamic Mosaic reconstruction strategy and instead using naturally enhanced images without excessive distortion to fit the network's final parameters, ensuring that the feature distribution of the model's output layer is absolutely aligned with the data distribution of the real physical pigsty.
[0114] like Figure 4 As shown in Figure S3, the spatial feature extraction module is equipped with a lightweight MobileNetV4-YOLO network, including a backbone network, a neck network, a Mobile MQA detection layer, a total loss function layer, and a detection output layer. The Mobile MQA detection layer includes a first Mobile MQA detection head and a second Mobile MQA detection head. The first output of the backbone network is connected to the first input and the third input of the neck network, respectively. The second output of the backbone network is connected to the second input of the neck network. The first output of the neck network is connected to the input of the first Mobile MQA detection head, and the second output of the neck network is connected to the input of the second Mobile MQA detection head. The outputs of the first and second Mobile MQA detection heads are both connected to the detection output layer through the total loss function layer.
[0115] In this embodiment, the spatial feature extraction module runs on a lightweight MobileNetV4-YOLO network deployed at the edge (such as an embedded NPU), aiming to directly map the underlying pixel information to fecal pathological appearance classifications with high veterinary clinical value (such as watery diarrhea, bloody stools, mucus stools, etc.).
[0116] The backbone network consists of a first-layer feature extraction subnetwork to a fifth-layer feature extraction subnetwork connected in sequence. The output of the fourth-layer feature extraction subnetwork serves as the first output of the backbone network, and the output of the fifth-layer feature extraction subnetwork serves as the second output of the backbone network.
[0117] In this embodiment, the backbone network relies on a generalized inverted bottleneck (UIB) architecture based on neural architecture search (NAS). The model adaptively switches topologies according to the mapping requirements of pathological features at different network depths: when extracting high-frequency spatial features such as the texture of slatted floor edges, undigested small feed particles, or extremely weak mucus filaments, the shallow network automatically activates the Inverted Bottleneck (IB) mode (disabling...). Only enabled When capturing extremely large-scale, jet-like watery diarrhea caused by diseases such as porcine epidemic diarrhea (PED), the deep network activates the ExtraDW mode (while simultaneously enabling...). and To rapidly expand the sensory field.
[0118] The neck network comprises, in sequence, a first Mobile MQA Fusion (a mobile multi-query attention fusion module, which includes a spatial reduction unit and a shared key-value pair self-attention calculation unit, used to downsample features and calculate attention weights through depthwise convolutions with a stride of 2 after concatenating multi-scale feature maps, in order to filter out high-frequency environmental noise), a first upsampling module, a first concatenation module, a second Mobile MQA Fusion, a second upsampling module, a second concatenation module, a third Mobile MQA Fusion, a first C2f-UIB module, a second C2f-UIB module, a fourth Mobile MQA Fusion, a third concatenation module, a third upsampling module, a third C2f-UIB module, and a fifth Mobile MQA Fusion. The first Mobile MQA... The input of the Fusion module serves as the first input to the neck network, the input of the first stitching module serves as the second input to the neck network, the input of the first C2f-UIB module serves as the third input to the neck network, the output of the second C2f-UIB module serves as the first output to the neck network, the output of the third C2f-UIB module serves as the second output to the neck network, the output of the first Mobile MQA Fusion module is also connected to the input of the fifth Mobile MQA Fusion module, the input of the first stitching module is also connected to the output of the fifth Mobile MQA Fusion module, the input of the second stitching module is also connected to the output of the third stitching module, and the output of the third Mobile MQA Fusion module is also connected to the input of the fourth Mobile MQAFusion module.
[0119] In this embodiment, the neck network introduces the C2f-UIB dynamic module and incorporates the standard features from the Panoramic Feature Pyramid (PAN-FPN). All convolutions are replaced with depthwise separable convolutions (DSConv). This design reduces the theoretical computational complexity of the neck region from... sudden drop ,in, For the height of pixels, The width is in pixels. Input the number of channels. Number of output channels The kernel size enables efficient cross-scale fusion of deep, wide-area pathological semantics with superficial, localized, minute lesions (such as blood streaks).
[0120] The backbone network's workflow is as follows:
[0121] The preprocessed image frames are input into the backbone network, and feature extraction is performed through each layer's feature extraction subnetwork to obtain the feature maps of each layer. Among these, the first... The first layer of feature extraction subnetwork extracts the first layer of features. Feature map of layer The specific expression is:
[0122]
[0123] In the formula, For the first Feature map of the layer For channel dimensionality reduction Pointwise convolution, It is a non-linear activation function. For depthwise separable convolutions in the middle of the network, The size of the depth-separable convolution kernel. For use in channel dimensional upgrading Pointwise convolution, For depthwise separable convolutions at the network front end;
[0124] The first and second Mobile MQA detection heads have the same structure, both incorporating a Mobile Multi-Query Attention (Mobile MQA) unit. This unit forces all attention heads to share the same key and value matrix and introduces a depthwise convolution with a stride of 2 as a space reduction operation. The Mobile Multi-Query Attention unit calculates the attention... The specific expression is:
[0125]
[0126] In the formula, For normalized exponential functions, For query, For space reduction operation, As key, For value, As a dimension, It is the transpose symbol;
[0127] The core visual indicators of swine fever or swine dysentery (SD) both include red, bloody excrement. However, the red reflections from heat lamps on pigpen floors, rusty metal railings, and red paint markings can easily lead to false positives in the algorithm. Therefore, this embodiment sets up a Mobile MQA detection layer before the detection output layer. Through the built-in mobile multi-query attention mechanism unit, the network is given the ability to remove high-frequency environmental color noise, enabling it to accurately identify the essential difference between the "moist, reflective texture of fresh blood" and the "rough texture of dried rust" in the deep semantic space, and accurately locate the real diseased excrement area.
[0128] The total loss function layer has a total loss function set up. The specific expression is:
[0129]
[0130] In the formula, To extend the intersection-union ratio (IoU) loss. Let SlideLoss be the sliding loss function. This is the distribution focal loss. The first weighting balancing coefficient, This is the second weighting balancing coefficient. This is the third weighting balancing coefficient.
[0131] In the very early stages of swine dysentery (SD), the surface of formed feces may only have dark red blood streaks or translucent mucus less than a few millimeters long attached. These tiny, highly similar "hard-boundary positive samples" are easily overwhelmed by the massive background of healthy feces and missed under traditional cross-entropy loss. Therefore, this embodiment introduces the SlideLoss sliding loss function before the detection output layer, using the intersection-over-union (IoU) ratio between the predicted and ground truth boxes to set a non-linear sliding weighting factor. When the sample When in the boundary interval with high confidence but slight positioning deviation, It will assign it a very large gradient penalty weight, forcing the network to perform deep secondary learning on the subtle signs of "disease-like but not disease-like".
[0132] The MobileNetV4-YOLO lightweight network inference has concluded, outputting the excrement appearance anomaly classification result and the probability confidence score of the excrement appearance anomaly classification result. Furthermore, it simultaneously extracts a high-dimensional semantic feature matrix within the region of interest (ROI) after removing redundant background pixels. The data is directly pushed to the subsequent temporal behavior analysis module, achieving a complete "visual extraction equals dimensionality reduction and compression" data flow, avoiding computational power collapse caused by temporal networks directly processing massive pixels. The temporal behavior analysis module performs long-term analysis of macroscopic actions based on Attention-GRU, directly inputting a high-dimensional semantic feature matrix. In real veterinary clinical practice, excretion-related concurrent behavioral chains (such as "vomiting followed by diarrhea" or "diarrhea followed by exhaustion") are key to differentiating different gastrointestinal diseases.
[0133] like Figure 5As shown, in S4, the temporal behavior analysis module includes a bidirectional cyclic temporal backtracking submodule, a time step attention focusing submodule, a fully connected layer, and a Softmax classifier connected in sequence. The bidirectional cyclic temporal backtracking submodule includes a forward GRU layer and a backward GRU layer, both of which are connected to the attention layer.
[0134] The workflow of the time-series behavior analysis module is as follows:
[0135] S41. Input the high-dimensional semantic feature matrix into the forward GRU layer and the backward GRU layer, calculate the forward hidden state and the backward hidden state respectively, and concatenate the forward hidden state and the backward hidden state into a comprehensive context feature.
[0136] S42. Input the comprehensive contextual features into the time step attention focusing submodule to obtain the global context vector;
[0137] S43. Input the global context vector into the fully connected layer and the Softmax classifier in sequence to generate an abnormal probability of excretory behavior with clear clinical guidance.
[0138] In S41, the workflow of the forward GRU layer and the backward GRU layer is the same, specifically:
[0139] Based on the high-dimensional semantic feature matrix Computational update gate ;
[0140]
[0141] In the formula, For the sigmoid function, , This is the first high-level semantic feature vector. For the first High-level semantic feature vectors For the first High-level semantic feature vectors For a moment The hidden state, This is the first bias parameter. This is the first weight parameter;
[0142] In this embodiment, for the input of the first High-level semantic feature vector The GRU layer calculates the flow of pathological information through a sophisticated internal gated mathematical model. For example, in the case of transmissible gastroenteritis (TGE) or porcine epidemic diarrhea (PED), the typical symptoms are acute vomiting followed by watery diarrhea. It is responsible for long-term retention of the pre-excretion "vomiting" and "anxiety" motor memories until diarrhea occurs.
[0143] Based on the high-dimensional semantic feature matrix Calculate the reset door ;
[0144]
[0145] In the formula, This is the second bias parameter. This is the second weighting parameter;
[0146] According to the reset door Calculation time Candidate hidden state ;
[0147]
[0148] In the formula, It is the hyperbolic tangent function. As the third weighting parameter, For Hadama accumulation, This is the third bias parameter;
[0149] According to time Candidate hidden state and Update Gate Calculation time Hidden state ;
[0150]
[0151] In order to simultaneously capture the strong causal correlation between "painful incubation before defecation" and "instant exhaustion after defecation," the network uses forward hidden states... With reverse hidden state Concatenated into comprehensive contextual features This allows each frame to have a global perspective spanning the entire timeframe.
[0152] In S42, the workflow of the time step attention focusing submodule is as follows:
[0153] Based on comprehensive contextual features Calculation time Importance score ;
[0154]
[0155] In the formula, This is the fourth weighting parameter. This is the fourth bias parameter;
[0156] Using the context parameter matrix Calculate the calculation time absolute attention weight ;
[0157]
[0158] In the formula, For a moment Importance score;
[0159] Based on comprehensive contextual features With time absolute attention weight Calculate the global context vector ;
[0160] .
[0161] In this embodiment, the weights of lengthy and diagnostically worthless "normal standing" or "slow walking" frames are attenuated to near zero by the time-step attention-focusing submodule, while the weights of the aforementioned fleeting pathological spasm frames are exponentially amplified. Ultimately, the features from all time steps are weighted and folded into a global context vector that encapsulates the severity of the entire excretion process. .
[0162] Global Context Vector By mapping the terminal fully connected layer to the Softmax classifier, and aggregating the probability values of abnormal action categories (such as severe pain, diarrhea, and shivering during defecation), a precise output of an abnormal defecation behavior probability with clear clinical guidance is achieved. (Internal differentiation includes: probability of tenesmus and abdominal retraction syndrome, probability of vomiting followed by diarrhea dehydration syndrome, probability of ataxia and shivering syndrome, etc.).
[0163] In S5, the decision-level fusion and diagnosis module includes the correlation reasoning and judgment rule submodule and the disease classification and response submodule;
[0164] The comprehensive epidemic risk probability is calculated through the association reasoning and judgment rule submodule. The specific method for calculating the comprehensive epidemic risk probability is as follows:
[0165] A1. Calculate the Shannon entropy of the probability distribution based on the probability confidence score of the excrement appearance anomaly classification results. This entropy is used to quantify the uncertainty noise of the current visual environment. Specifically, the calculation of the Shannon entropy of the probability distribution... The specific expression is:
[0166]
[0167] In the formula, It is a high-dimensional semantic feature matrix. For the first The confidence level of the predicted probability for each apparent state category (e.g., water sample, blood sample, etc.). , The probability confidence level of the classification results of apparent abnormalities in excrement;
[0168] In this embodiment, when infrared blindness occurs at night or when the pig's torso severely obstructs the view, the spatial feature distribution tends to be smooth. This invention measures environmental uncertainty noise by calculating the Shannon entropy of its probability distribution.
[0169] A2. The high-dimensional semantic feature matrix after global average pooling With global context vector The data is stitched along the channels and input into a multilayer perceptron (MLP). The dynamic weight allocation for the bimodal modes is then solved using a temperature-scaled Softmax function. ;
[0170]
[0171] In the formula, Assign weights dynamically to the first one. For the second dynamic allocation of weights, For the Softmax function, It is a multilayer perceptron. It is a global average pooling layer. For splicing operations, This is the temperature scaling factor, used to control the smoothness of the output feature weight distribution;
[0172] In this embodiment, the dynamic weight allocation formula endows the system with extremely strong environmental adaptability: when insufficient light at night causes... When the value is too high, the network will automatically reduce its load significantly. And push up simultaneously This allows diagnostic decisions to naturally lean towards more reliable macroscopic temporal actions, thereby salvaging visual false negatives to the greatest extent possible.
[0173] A3. Based on dynamically allocated weights Calculate the overall probability of disease risk ;
[0174]
[0175] In the formula, The probability of abnormal excretory behavior. For spatiotemporal joint resonance factors; when two signals capture highly consistent pathological features (such as seeing both bloody stools and convulsions), the product term... This will increase the overall probability of disease risk. It shows an exponential surge, directly locking in a high-risk warning.
[0176] High-risk swine diseases are detected through the disease typing and response submodule. The specific method for detecting high-risk swine diseases is as follows:
[0177] Swine dysentery (SD) detection: probability confidence level of classification results based on apparent abnormalities in excrement The predicted probability confidence level of the "bloody mucus / watery stool" apparent status category is greater than the preset first apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the "abdominal retraction and tenesmus" apparent condition category is greater than the preset first behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a swine dysentery warning will be triggered.
[0178] Detection of porcine epidemic diarrhea (PED) and transmissible gastroenteritis (TGE): Probability confidence of classification results of apparent abnormalities in feces The predicted probability confidence level of the apparent state category "acute vomiting and abnormally active drinking" is greater than the set apparent threshold and greater than the preset second apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the "yellow foamy watery stool" apparent state category is greater than the preset second behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a warning for porcine epidemic diarrhea and transmissible gastroenteritis will be triggered.
[0179] Detection of severe systemic infection of swine fever: probability confidence level of classification results of apparent abnormalities in feces The predicted probability confidence level of the "bright red bloody diarrhea" apparent state category is greater than the set apparent threshold and greater than the preset third apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the apparent state category "extreme weakness and malignant tremors" is greater than the preset third behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a warning for severe systemic infection of swine fever will be triggered.
[0180] In response to a comprehensive disease risk probability exceeding the high-risk threshold, triggering a swine dysentery warning, a swine epidemic diarrhea and transmissible gastroenteritis (TGE) warning, or a severe systemic infection warning for classical swine fever, the system integrates the pigpen location, the unique ID of the target pig, and a highlighted warning segment into a disease warning message and sends it to the user. A disease warning message might be as follows: "Time: 2026-03-04 10:15; Suspected Disease: Classical Swine Fever; Affected Area: Fattening Pen A-1; Details: Bloody excrement detected (apparent confidence 0.94) accompanied by malignant high fever and shivering behavior (behavioral confidence 0.92), comprehensive risk score reaches 0.93; Recommended Measures: Immediately isolate the pigs, conduct virus testing, and initiate a vaccine prevention and control program."
[0181] like Figure 2 As shown, a disease identification system based on the fusion of pig fecal appearance and excretory behavior includes:
[0182] The data acquisition module includes a high-position camera and a low-position camera. The high-position camera is used to collect the macroscopic movement status and overall excretion posture of the pig herd, while the low-position camera is used to collect the microscopic morphological data of the excrement landing.
[0183] The preprocessing module includes a data cleaning submodule and an image enhancement submodule. The data cleaning submodule is used to clean the raw video stream data, and the image enhancement submodule uses a dynamic Mosaic reconstruction strategy to enhance the raw video stream data.
[0184] In this embodiment, the present invention constructs a data acquisition module and a preprocessing module, realizing non-contact pig health monitoring in extremely complex environments, providing video multimodal data from both macroscopic and microscopic perspectives, and providing comprehensive underlying information support for disease detection.
[0185] The spatial feature extraction module is used to extract key static appearance features from the preprocessed image frames, generate a high-dimensional semantic feature matrix, the excrement appearance anomaly classification results of the image frames and their probability confidence scores.
[0186] In this embodiment, in order to effectively extract the microscopic pathological features of pig excrement and reduce the impact of complex backgrounds in pigsties (such as slatted floors, urine stains, and feed residue) on model performance, this system is designed with a spatial feature extraction module. This module is used to process the raw video stream data collected by the data acquisition and preprocessing module and extract key static appearance features to provide high-quality spatial probability input for disease identification.
[0187] The spatial feature extraction module is equipped with a lightweight MobileNetV4-YOLO network. The backbone of this network is built upon a deeply lightweight reconstructed target detection network, designed for efficient operation on edge computing devices with limited computing power. It receives preprocessed image data, significantly reduces computational redundancy while maintaining feature representation capabilities, and performs real-time multi-scale spatial information extraction and fusion of target excrement.
[0188] The subsequent part of the network addresses the issues of easily missing subtle lesion features and extreme imbalance between positive and negative samples. Its built-in attention mechanism and dynamic loss assessment unit are responsible for automatically filtering environmental noise such as red paint and rust, accurately locating and deeply assessing areas with subtle lesion features such as blood streaks and mucus, ultimately achieving accurate classification of excrement and outputting the confidence level of the excrement's apparent abnormalities to the system.
[0189] The temporal behavior analysis module includes a bidirectional cyclic temporal backtracking submodule and a time-step attention focusing submodule. The bidirectional cyclic temporal backtracking submodule takes a high-dimensional semantic feature matrix as input and extracts comprehensive contextual features along both the forward and reverse temporal dimensions. The time-step attention focusing submodule calculates a global context vector based on the comprehensive contextual features using a self-attention mechanism. This submodule, based on the self-attention mechanism, constructs a keyframe weight allocation network, which predefines and captures high-frequency action features of various pathological conditions. For example, the trunk feature of highly pathogenic infections manifests as painful tremors; features of digestive tract diseases include rigidity, arched back, and tenesmus. This submodule provides global focusing capabilities on fleeting pathological moments, aiming to improve the model's visual recognition ability of subtle malignant behaviors in pigs and eliminate interference from ineffective actions such as ordinary wandering or cold stress tremors. Through an efficient weight aggregation mechanism, the temporal network ensures accurate output of the probability distribution of behavioral abnormalities, ensuring the reliability of diagnostic results.
[0190] The temporal behavior analysis module aims to perform long-term dynamic analysis of the excretion process based on high-dimensional semantic features extracted from space. This enables the model to distinguish between normal physiological actions and pathological behaviors in pigs, thereby improving the specificity and applicability of pig disease detection and achieving automatic identification of abnormal excretion behaviors in pigs.
[0191] The abnormal probability input decision-level fusion and diagnosis module is used to perform in-depth analysis on the data extracted by the spatial feature extraction module and the temporal behavior analysis module, generate comprehensive disease risk probabilities, and detect high-risk pig diseases.
[0192] The abnormal probability input decision-level fusion and diagnosis module includes an association reasoning and judgment rule submodule and a disease classification and response submodule.
[0193] The association reasoning and judgment rule submodule constructs a bimodal dynamic weight allocation method. Based on the dynamic weight allocation, the comprehensive disease risk probability is calculated. When the two features resonate in the same direction in time and space, the disease alarm weight is increased exponentially. If there is only a unidirectional high-sensitivity behavior (such as simple shivering), it is judged as non-pathological cold stress or other environmental interference. If a specific "feces-behavior" combination appears, it is accurately mapped to a specific disease category.
[0194] The disease typing and response submodule constructs detection methods for high-risk swine diseases, including detection of swine dysentery (SD), swine epidemic diarrhea (PED) and transmissible gastroenteritis (TGE), and detection of severe systemic infection of classical swine fever. It aims to close the loopholes in misdiagnosis that may be caused by a single detection modality, and ultimately achieve qualitative detection and early warning of specific swine diseases.
[0195] The beneficial effects of this invention are as follows: This invention adopts a "diagonal dual-camera" stereo perception architecture and combines it with the IEEE 1588PTP protocol to achieve sub-microsecond time synchronization, which not only significantly reduces equipment deployment costs but also completely eliminates cross-view spatiotemporal fusion errors from the ground up. This invention uses multiple data augmentation strategies such as adaptive histogram equalization (CLAHE) and dynamic Mosaic to artificially construct high-entropy complex backgrounds and expand difficult samples, significantly improving the model's generalization ability under complex slatted floor backgrounds and varying lighting conditions. Addressing the limited computing resources of edge devices, this invention uses MobileNetV4 to perform lightweight reconstruction of the YOLO detection network and combines it with the Mobile MQA attention mechanism and the SlideLoss loss function, reducing computing resource requirements while achieving high-precision capture of extremely subtle latent pathological signs (such as trace amounts of blood and mucus). Furthermore, by combining a self-attention mechanism with a bidirectional gated recurrent unit (Attention-GRU) to deeply deconstruct the long-term temporal dynamic semantics of excretion, interference from normal physiological movements of pigs is accurately filtered out. This invention also innovatively designs a gated expert network (GEN) based on Shannon entropy, realizing dynamic weighting and logical mutual verification of dual-modal features of visual appearance and temporal behavior. This enables the system to not only more accurately and comprehensively identify disease types, but also to minimize false negatives and false positives. In summary, this invention offers advantages in swine disease detection, including low hardware deployment costs, strong anti-interference capabilities of multimodal spatiotemporal mutual verification, efficient edge computing, and fully automated closed-loop blocking. These advantages significantly improve the accuracy and practicality of disease detection, reducing the risk of disease spread and economic losses in pig farms.
[0196] In the description of this invention, the above are merely preferred embodiments and are not intended to limit the scope of protection of this invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A disease identification method based on the fusion of pig fecal appearance and excretory behavior, characterized in that, Includes the following steps: S1. Take images of pigs in the pigpen using the data acquisition module to obtain raw video stream data; S2. The original video stream data is preprocessed by the preprocessing module to obtain preprocessed image frames; S3. Input the preprocessed image frame into the spatial feature extraction module to generate a high-dimensional semantic feature matrix, the excrement appearance anomaly classification results of the image frame and its probability confidence; S4. Input the high-dimensional semantic feature matrix into the time-series behavior analysis module to generate the abnormal probability of excretion behavior; S5. Input the probability confidence of the excrement appearance abnormality classification result and the probability of excretion behavior abnormality into the decision-level fusion and diagnosis module to generate a comprehensive disease risk probability and detect high-risk pig diseases. In S3, the spatial feature extraction module is equipped with a lightweight MobileNetV4-YOLO network, including a backbone network, a neck network, a Mobile MQA detection layer, a total loss function layer, and a detection output layer. The Mobile MQA detection layer includes a first MobileMQA detection head and a second MobileMQA detection head. The first output of the backbone network is connected to the first input and the third input of the neck network, respectively. The second output of the backbone network is connected to the second input of the neck network. The first output of the neck network is connected to the input of the first MobileMQA detection head, and the second output of the neck network is connected to the input of the second MobileMQA detection head. The outputs of the first and second MobileMQA detection heads are both connected to the detection output layer through the total loss function layer. The backbone network consists of a first-layer feature extraction subnetwork to a fifth-layer feature extraction subnetwork connected in sequence. The output of the fourth-layer feature extraction subnetwork serves as the first output of the backbone network, and the output of the fifth-layer feature extraction subnetwork serves as the second output of the backbone network. The neck network comprises, in sequence, a first Mobile MQA Fusion, a first upsampling module, a first stitching module, a second Mobile MQA Fusion, a second upsampling module, a second stitching module, a third Mobile MQA Fusion, a first C2f-UIB module, a second C2f-UIB module, a fourth Mobile MQA Fusion, a third stitching module, a third upsampling module, a third C2f-UIB module, and a fifth Mobile MQA Fusion. The input of the first Mobile MQA Fusion serves as the first input of the neck network, the input of the first stitching module serves as the second input, the input of the first C2f-UIB module serves as the third input, the output of the second C2f-UIB module serves as the first output, and the output of the third C2f-UIB module serves as the second output. The output of the first Mobile MQA Fusion is also connected to the input of the fifth Mobile MQA Fusion, the input of the first stitching module is also connected to the output of the fifth Mobile MQA Fusion, the input of the second stitching module is also connected to the output of the third stitching module, and the output of the third Mobile MQA Fusion is also connected to the input of the fourth Mobile MQA Fusion. Input connection for MQA Fusion.
2. The disease identification method based on the fusion of pig fecal appearance and excretory behavior according to claim 1, characterized in that, In S1, the data acquisition module includes a high-position camera and a low-position camera. The high-position camera and the low-position camera adopt an installation strategy of "one high and one low, diagonally intersecting". The high-position camera is installed at a higher position than the low-position camera. The high-position camera is located at the top of the diagonal of the pigpen and is used to take pictures of the pigs in the pigpen from all directions to collect the macroscopic movement status and overall excretion posture of the pig group. The low-position camera is located at the bottom of the diagonal of the pigpen and is used to collect microscopic morphological data of excrement landing. Both the high-position and low-position cameras use the IEEE 1588 precise time protocol for clock synchronization locking of the frames acquired by the two cameras. The specific method for obtaining the raw video stream data is as follows: In response to the high-position camera detecting a pre-set suspected pre-excretion action in a pig, the high-position camera and the low-position camera are controlled to capture a predetermined number of consecutive image frames to generate raw video stream data.
3. The disease identification method based on the fusion of pig fecal appearance and excretory behavior according to claim 2, characterized in that, In S2, the preprocessing methods include data cleaning and data augmentation. Data cleaning employs a frame-by-frame limit-contrast adaptive histogram equalization method, specifically as follows: The images in the original video stream data are divided into The non-overlapping grid is used to independently calculate the histogram within each grid and set a clipping threshold to prevent local environmental noise from being excessively amplified. The grid boundaries are smoothed by bilinear interpolation, and the weak texture contrast between the dark manure board and the excrement is forcibly increased in a nonlinear mapping manner. At the same time, rotation, horizontal flipping and local clipping operations are randomly applied to the image to simulate and eliminate the observation angle deviation caused by camera installation errors or pig movement. Data augmentation employs a dynamic Mosaic reconstruction strategy, which specifically includes: Four image frames with different backgrounds are randomly captured from the original video stream data. A stitching center point coordinate is randomly generated in a unified canvas space. The four image frames are multiplied by independent affine transformation matrices and placed in the four quadrants of the canvas space. The coordinates of the actual bounding boxes of the targets in the image frames are simultaneously linearly mapped, and the parts that exceed the canvas boundaries are truncated.
4. The disease identification method based on the fusion of pig fecal appearance and excretory behavior according to claim 3, characterized in that, The backbone network's workflow is as follows: The preprocessed image frames are input into the backbone network, and feature extraction is performed through each layer's feature extraction subnetwork to obtain the feature maps of each layer. Among these, the first... The first layer of feature extraction subnetwork extracts the first layer of features. Feature map of layer The specific expression is: In the formula, For the first Feature map of the layer For channel dimensionality reduction Pointwise convolution, It is a non-linear activation function. For depthwise separable convolutions in the middle of the network, For use in channel dimensional upgrading Pointwise convolution, For depthwise separable convolutions at the network front end; The first and second Mobile MQA detection heads have the same structure, both incorporating a mobile multi-query attention mechanism unit. This unit forces all attention heads to share the same key-value matrix and introduces a depthwise convolution with a stride of 2 as a space reduction operation. The mobile multi-query attention mechanism unit calculates the attention... The specific expression is: In the formula, For normalized exponential functions, For query, For space reduction operation, As key, For value, As a dimension, It is the transpose symbol; The total loss function layer has a total loss function set up. The specific expression is: In the formula, To expand the intersection-union ratio loss, Let SlideLoss be the sliding loss function. For the distribution focus loss, The first weighting balancing coefficient, This is the second weighting balancing coefficient. This is the third weighting balancing coefficient.
5. The disease identification method based on the fusion of pig fecal appearance and excretory behavior according to claim 4, characterized in that, In S4, the temporal behavior analysis module includes a bidirectional cyclic temporal backtracking submodule, a time step attention focusing submodule, a fully connected layer, and a Softmax classifier, which are connected in sequence. The bidirectional cyclic temporal backtracking submodule includes a forward GRU layer and a backward GRU layer, both of which are connected to the attention layer. The workflow of the time-series behavior analysis module is as follows: S41. Input the high-dimensional semantic feature matrix into the forward GRU layer and the backward GRU layer, calculate the forward hidden state and the backward hidden state respectively, and concatenate the forward hidden state and the backward hidden state into a comprehensive context feature. S42. Input the comprehensive contextual features into the time step attention focusing submodule to obtain the global context vector; S43. Input the global context vector into the fully connected layer and the Softmax classifier in sequence to generate an abnormal probability of excretory behavior with clear clinical guidance.
6. The disease identification method based on the fusion of pig fecal appearance and excretory behavior according to claim 5, characterized in that, In S41, the workflow of the forward GRU layer and the backward GRU layer is the same, specifically: Based on the high-dimensional semantic feature matrix Computational update gate ; In the formula, For the sigmoid function, , This is the first high-level semantic feature vector. For the first High-level semantic feature vectors For the first High-level semantic feature vectors For a moment The hidden state, This is the first bias parameter. This is the first weight parameter; Based on the high-dimensional semantic feature matrix Calculate the reset door ; In the formula, This is the second bias parameter. This is the second weighting parameter; According to the reset door Calculation time Candidate hidden state ; In the formula, It is the hyperbolic tangent function. As the third weighting parameter, For Hadama accumulation, This is the third bias parameter; According to time Candidate hidden state and Update Gate Calculation time Hidden state ; In S42, the workflow of the time step attention focusing submodule is as follows: Based on comprehensive contextual features Calculation time Importance score ; In the formula, This is the fourth weighting parameter. This is the fourth bias parameter; Using the context parameter matrix Calculation time absolute attention weight ; In the formula, For a moment Importance score; Based on comprehensive contextual features With time absolute attention weight Calculate the global context vector ; 。 7. The disease identification method based on the fusion of pig fecal appearance and excretory behavior according to claim 6, characterized in that, In S5, the decision-level fusion and diagnosis module includes the correlation reasoning and judgment rule submodule and the disease classification and response submodule; The comprehensive epidemic risk probability is calculated through the association reasoning and judgment rule submodule. The specific method for calculating the comprehensive epidemic risk probability is as follows: A1. Calculate the Shannon entropy of the probability distribution based on the probability confidence score of the excrement appearance anomaly classification results. This entropy is used to quantify the uncertainty noise of the current visual environment. Specifically, the calculation of the Shannon entropy of the probability distribution... The specific expression is: In the formula, It is a high-dimensional semantic feature matrix. For the first Confidence level of predicted probability for each apparent state category , The probability confidence level of the classification results of apparent abnormalities in excrement; A2. The high-dimensional semantic feature matrix after global average pooling With global context vector The data is stitched along the channels, input into a multilayer perceptron, and the dynamic weight allocation for the bimodal modes is solved using a temperature-scaling Softmax function. ; In the formula, Assign weights dynamically to the first one. For the second dynamic allocation of weights, For the Softmax function, It is a multilayer perceptron. It is a global average pooling layer. For splicing operations, This is a temperature scaling factor used to control the smoothness of the output feature weight distribution; A3. Based on dynamically allocated weights Calculate the overall probability of disease risk ; In the formula, The probability of abnormal excretory behavior. It is the spatiotemporal joint resonance factor; High-risk swine diseases are detected through the disease typing and response submodule. The specific method for detecting high-risk swine diseases is as follows: Swine dysentery detection: probability confidence level of classification results based on apparent abnormalities in excrement The predicted probability confidence level of the "bloody mucus / watery stool" apparent status category is greater than the preset first apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the "abdominal retraction and tenesmus" apparent condition category is greater than the preset first behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a swine dysentery warning will be triggered. Detection of porcine epidemic diarrhea and transmissible gastroenteritis: Probability confidence of classification results of apparent abnormalities in feces The predicted probability confidence level of the apparent state category "acute vomiting and abnormally active drinking" is greater than the set apparent threshold and greater than the preset second apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the "yellow foamy watery stool" apparent state category is greater than the preset second behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a warning for porcine epidemic diarrhea and transmissible gastroenteritis will be triggered. Detection of severe systemic infection of swine fever: probability confidence level of classification results of apparent abnormalities in feces The predicted probability confidence level of the "bright red bloody diarrhea" apparent state category is greater than the set apparent threshold and greater than the preset third apparent threshold, and the probability of abnormal excretion behavior is also higher. The predicted probability confidence level of the apparent state category "extreme weakness and malignant tremors" is greater than the preset third-behavior threshold and the overall disease risk probability. If all three conditions are met simultaneously and exceed the high-risk threshold, a warning for severe systemic infection of swine fever will be triggered. In response to a situation where the overall disease risk probability exceeds the high-risk threshold, triggering a swine dysentery warning, a swine epidemic diarrhea and transmissible gastroenteritis warning, or a severe systemic infection warning for classical swine fever, the system integrates the pigsty location, the unique ID of the target pig, and the highlighted warning segment into the disease warning information and sends it to the user.
8. A disease identification system based on the fusion of pig fecal appearance and excretory behavior, applied to the disease identification method based on the fusion of pig fecal appearance and excretory behavior as described in any one of claims 1 to 7, characterized in that, The system includes: The data acquisition module includes a high-position camera and a low-position camera. The high-position camera is used to collect the macroscopic movement status and overall excretion posture of the pig herd, while the low-position camera is used to collect the microscopic morphological data of the excrement landing. The preprocessing module includes a data cleaning submodule and an image enhancement submodule. The data cleaning submodule is used to clean the raw video stream data, and the image enhancement submodule uses a dynamic Mosaic reconstruction strategy to enhance the raw video stream data. The spatial feature extraction module is used to extract key static appearance features from the preprocessed image frames, generate a high-dimensional semantic feature matrix, the excrement appearance anomaly classification results of the image frames and their probability confidence scores. The temporal behavior analysis module includes a bidirectional cyclic temporal backtracking submodule and a time step attention focusing submodule. The bidirectional cyclic temporal backtracking submodule takes a high-dimensional semantic feature matrix as input and extracts comprehensive contextual features in both the positive and negative dimensions of time. The time step attention focusing submodule calculates the global context vector based on the comprehensive contextual features through a self-attention mechanism. The abnormal probability input decision-level fusion and diagnosis module is used to perform in-depth analysis on the data extracted by the spatial feature extraction module and the temporal behavior analysis module, generate comprehensive disease risk probabilities, and detect high-risk pig diseases.