A method for training a pigsty monitoring model and the pigsty monitoring model
By optimizing the pig farm monitoring system using a semi-supervised semantic segmentation model and a cross-sample attention module, the problems of manual dependence and high requirements for labeled data in the pig farm monitoring system are solved, and high-precision, low-cost real-time monitoring and detection effects are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 青岛兴牧畜牧科技发展有限公司
- Filing Date
- 2023-07-21
- Publication Date
- 2026-06-30
AI Technical Summary
In existing technologies, pig house monitoring systems rely on manual inspections, which have problems such as high labor costs, difficulty in real-time monitoring, easy omissions, and low accuracy. Furthermore, semi-supervised learning algorithms have high requirements for labeled data and cannot fully utilize the information potential of unlabeled data.
A semi-supervised semantic segmentation model is adopted. Through a collaborative learning architecture and a cross-sample attention module, it utilizes a small amount of labeled data and a large amount of unlabeled data, combined with a global relevance consistency loss module, to optimize the model training parameters and improve the accuracy and generalization ability of image segmentation.
It achieves high-precision image segmentation with a small amount of labeled data, reduces the workload of manual labeling, lowers costs, improves the accuracy and adaptability of the monitoring system, and can detect the location of piglets in the pigsty in real time and respond to problems in a timely manner.
Smart Images

Figure CN116883791B_ABST
Abstract
Description
Technical Field
[0001] This invention discloses a training method for a pigsty monitoring model and a pigsty monitoring model, belonging to the field of image recognition technology. Background Technology
[0002] With the development of smart technology, cameras are being used in various scenarios across all industries. Cameras can monitor the dynamics of areas of concern in a timely and effective manner, and can be dealt with promptly in case of any unexpected situations. This is of great significance for ensuring the security of important areas.
[0003] In agriculture, traditional monitoring systems heavily rely on manual inspections, which can easily lead to oversights and delays in identifying problems in unexpected situations. These systems suffer from high labor costs, difficulty in real-time monitoring, susceptibility to oversights, and low accuracy. Therefore, employing artificial intelligence (AI) to segment monitoring images of the monitored area is a solution. Image segmentation, a crucial step in image processing and recognition, can accurately extract image content, locate preset targets, and precisely identify problems in the monitored area. This helps eliminate the need for manual inspections, reduces labor costs, and prevents oversights.
[0004] Semi-supervised learning algorithms utilize labeled and unlabeled image data to learn a model that achieves the required performance. However, labeling data is time-consuming, labor-intensive, and requires a certain level of expertise; therefore, training a semi-supervised model with a large amount of labeled data is often costly. Furthermore, current semi-supervised learning techniques focus on extracting information from unlabeled data, neglecting the potential of labeled data to guide the extraction of information from unlabeled data. Summary of the Invention
[0005] The purpose of this application is to provide a monitoring model, its training method, and its application to solve the technical problems in the prior art, such as high requirements for labeled data and difficulty in fully utilizing supervised data information. To achieve the above objective, this invention provides a training method for a pigsty monitoring model and a pigsty monitoring model.
[0006] A method for training a pigsty monitoring model includes the following steps:
[0007] Step 1: Obtain pigsty monitoring data, which includes tagged data and untagged data;
[0008] Step 2: Input the labeled data and the unlabeled data into the semi-supervised semantic segmentation model respectively to obtain the supervised loss and the cross-pseudo-supervised loss.
[0009] Step 3: Determine the prototype features of the labeled data and the mapping features of the unlabeled data, and calculate the cross-entropy loss based on the prototype features and the mapping features;
[0010] Step 4: Determine the training parameters of the semi-supervised semantic segmentation model based on the supervised loss, the cross-pseudo-supervised loss, and the cross-entropy loss, and train the semi-supervised semantic segmentation model based on the training parameters.
[0011] Preferably, the training parameters of the semi-supervised semantic segmentation model are determined based on the supervised loss, the cross-pseudo-supervised loss, and the cross-entropy loss, specifically including:
[0012] The training parameters of the semi-supervised semantic segmentation model are determined based on the sum of the supervised loss, the cross-pseudo-supervised loss, and the cross-entropy loss.
[0013] Preferably, determining the prototype features of the labeled data specifically includes:
[0014] The labeled data is input into the original segmentation network in the semi-supervised semantic segmentation model to obtain the original prototype features;
[0015] The labeled data is input into the auxiliary segmentation network in the semi-supervised semantic segmentation model to obtain auxiliary prototype features;
[0016] The prototype features are determined based on the original prototype features and the auxiliary prototype features.
[0017] Preferably, the mapping features of the unlabeled data include a first mapping feature and a second mapping feature;
[0018] The first mapping feature is obtained by inputting the unlabeled data into the original segmentation network in the semi-supervised semantic segmentation model;
[0019] The second mapping feature is obtained by inputting the unlabeled data into the auxiliary segmentation network in the semi-supervised semantic segmentation model.
[0020] Preferably, the cross-entropy loss is calculated based on the prototype features and the mapping features, specifically including:
[0021] A first similarity matrix is determined based on the prototype features and the first mapping features;
[0022] A second similarity matrix is determined based on the prototype features and the second mapping features;
[0023] The cross-entropy loss is calculated based on the first similarity matrix and the second similarity matrix.
[0024] Preferably, the semi-supervised semantic segmentation model includes an auxiliary segmentation network, which includes a cross-sample attention module;
[0025] The labeled data and the unlabeled data undergo attention calculation through the cross-sample attention module.
[0026] Preferably, the cross-sample attention module includes two consecutive first self-attention encoding layers and second self-attention encoding layers;
[0027] The labeled data and the unlabeled data undergo in-sample self-attention computation in the first self-attention encoding layer;
[0028] The labeled data and the unlabeled data undergo inter-sample self-attention computation in the second self-attention encoding layer.
[0029] A pigsty monitoring model, the model being obtained using the aforementioned pigsty monitoring model training method.
[0030] A method for monitoring pigsties includes the following steps:
[0031] Step 1: Obtain a layout image of the pigsty, including a restricted area for piglets;
[0032] Step 2: Obtain real-time monitoring images of the pigsty;
[0033] Step 3: Input the real-time monitoring images into the pigsty monitoring model of the present invention to obtain the area where the piglets are located in each frame of the real-time monitoring image;
[0034] Step 4: Compare the area where the piglets are located in each frame of the real-time monitoring image with the prohibited area for piglets. If they are the same, an alarm will be issued.
[0035] A pigsty monitoring system based on the aforementioned pigsty monitoring method includes: a data acquisition module, a data processing module, and an alarm module;
[0036] The data acquisition module is used to acquire layout images of the pigsty and real-time monitoring images inside the pigsty. The layout images include a restricted area for piglets.
[0037] The acquisition and processing module is used to input the real-time monitoring image into the pigsty monitoring model of the present invention to obtain the area where the piglets are located in each frame of the real-time monitoring image;
[0038] The alarm module is used to compare the area where the piglets are located in each frame of real-time monitoring image with the prohibited area for piglets. If they are the same, an alarm is issued.
[0039] Beneficial Effects: The semi-supervised semantic segmentation model of this invention achieves high-precision image segmentation with a small number of labeled samples, significantly improving the effectiveness of semi-supervised learning, greatly reducing dependence on labeled samples, reducing the workload of manual labeling, and saving a significant amount of time and human resources. Through a cross-sample attention module and a global relevance consistency loss module, this invention enables the semi-supervised semantic segmentation model to better capture features and contextual information in images, improving the accuracy and generalization ability of image segmentation. The pigsty monitoring system of this invention can monitor image data within the pigsty in real time, quickly and accurately detect the location of piglets, and adapt to changes in different scenarios and environments, reducing labor costs, improving monitoring accuracy, and responding in real time to any potential problems. Attached Figure Description
[0040] Figure 1 This is a schematic diagram of the algorithm framework in an embodiment of the present invention. Detailed Implementation
[0041] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and do not limit the scope of protection of the invention.
[0042] The technical solution of this invention is as follows: the monitoring model of this invention is a semi-supervised semantic segmentation model. This model is based on a semi-supervised segmentation architecture of collaborative learning, utilizing a global relevance consistency loss module and a cross-sample attention module. The collaborative learning mode of the model includes an original segmentation network and an auxiliary segmentation network. To achieve effective cross-sample relationship modeling within a small batch of datasets, a cross-sample attention module is inserted into the auxiliary segmentation network; simultaneously, the original segmentation network maintains the original V-Net structure. To achieve information propagation between labeled and unlabeled data, the model uses a global relevance consistency loss module to further adjust the representation learning of unsupervised data, thereby deeply and effectively utilizing labeled data and improving the supervision of unsupervised samples by the gradient backpropagation signal from supervised data. This enables the model to achieve better segmentation results with limited labeled data, has lower requirements for labeled data, and significantly improves the semi-supervised learning effect with a small number of labeled samples.
[0043] The following describes an embodiment of the pigsty monitoring model training method provided by the present invention. (See also...) Figure 1 Example 1 includes:
[0044] Step 1: Obtain pigsty monitoring data, which includes tagged and untagged data;
[0045] Specifically, in this embodiment, images of the pigsty are first acquired using monitoring or sensor devices to obtain pigsty monitoring images. Then, some of these monitoring images are labeled to obtain labeled data, while the remaining unlabeled images are the unlabeled data. The labeling of some images involves annotating the masks of piglets in selected monitoring images, facilitating better understanding and processing of the data by the computer. To reduce the workload of data labeling, this invention uses a small amount of labeled data and a large amount of unlabeled data. After data labeling, the image data is input into a semi-supervised semantic segmentation model for training. Labeled and unlabeled data are input into the model in small batches for training.
[0046] Step 2: Input the labeled data and unlabeled data into the semi-supervised semantic segmentation model respectively to obtain the supervised loss and cross-pseudo-supervised loss.
[0047] A semi-supervised semantic segmentation model is constructed, and the model parameters are initialized. The model is based on co-learning and includes the original segmentation network. and auxiliary segmentation network The labeled data is input into the original segmentation network. and auxiliary segmentation network Gaining supervisory losses Input unlabeled data into the original segmentation network model and auxiliary segmentation network model Obtain cross-spurious supervision loss In this embodiment, the supervised loss is obtained. and cross-monitoring loss Obtained through the cross-supervision module, such as Figure 1 The cross-supervision module is shown within the box.
[0048] Specifically, for the same sample data, the auxiliary segmentation network will be used. The prediction results are used as the original segmentation network. The pseudo-labels are optimized using cross-entropy loss; meanwhile, the original segmentation network... The prediction results are used as an auxiliary segmentation network The pseudo-labels are optimized using cross-entropy loss. and These represent the corresponding cross-entropy losses.
[0049] Step 3: Determine the prototype features of the labeled data Mapping features to unlabeled data, and based on prototype features Calculate cross-entropy loss using mapping features ;
[0050] like Figure 1As shown, in this embodiment of the invention, to achieve information propagation between labeled and unlabeled data, a global relevance consistency loss module is used to further adjust the representation learning of unsupervised data. The global relevance consistency loss module is used to calculate the correlation degree, that is, to calculate the similarity matrix between the pixel-level features of unlabeled data and a set of pixel-level prototype features sampled from the features of labeled data. The matrix reflects the similarity relationship between unlabeled pixels and a set of labeled data reference pixels. During training, data from the original segmentation network... and auxiliary segmentation network The similarity matrices corresponding to the same unlabeled data pixel-level mapping features are consistent. In implementation, an interaction similarity matrix is used to model the similarity distribution between the mapping features and the prototype features of the labeled data. This invention uses the prototype features of the labeled data as a control group to guide the representation learning of the mapping features of the unlabeled data, enabling the model to learn a wider range of feature representations among unlabeled data, thereby improving the accuracy and generalization ability of image segmentation.
[0051] Determine the prototype characteristics of labeled data Specifically, this includes: inputting labeled data into the original segmentation network of the semi-supervised semantic segmentation model. Obtain the original prototype features; input the labeled data into the auxiliary segmentation network in the semi-supervised semantic segmentation model. Obtain auxiliary prototype features, and determine prototype features based on the original prototype features and auxiliary prototype features. In this embodiment, cross-entropy loss Obtained through the global correlation consistency loss module, such as Figure 1 The block shown is within the Global Relevance Consistency Loss module.
[0052] Specifically, such as Figure 1 As shown, storage This is a memory pool used to store pixel-level features sampled from the corresponding features in the labeled data. We use storage... This is used to iteratively update the prototype feature vectors used for computation in the global correlation consistency loss module.
[0053] Specifically, in the original segmentation network and auxiliary segmentation network The following connection has two mapping headers. and storage First, N slots are initialized for each labeled training sample, and then... and The features of the mapped labeled data are used to update the prototype feature vector. To ensure... To improve the stability of storing feature vectors, we choose two segmentation networks. and The feature vectors corresponding to the same positions in the prediction results are used, and the corresponding positions are obtained by... and Update the storage by fusing the mean of the mapped features. During the training process, It will update the labeled samples in the current batch. Features corresponding to the slots in the data. Prototype features of the labeled data. This indicates that the data is mapped from the marked data through the mapping header. and A set of features sampled from the obtained features, among which This represents the number of prototype features obtained from sampling; in this embodiment, the prototype features... That is, sampling from storage. A set of features. Specifically, sampling of prototype features includes: from storage... Randomly sampled from the feature vector corresponding to each category in the data. One prototype feature vector is used as a prototype feature vector extracted from labeled features to increase the diversity of features participating in similarity calculation. and The relationship between them can be represented as:
[0054]
[0055] The mapping features of the unlabeled data include a first mapping feature. Second mapping features The first mapping feature By feeding unlabeled data into the original segmentation network of the semi-supervised semantic segmentation model Obtain; Second mapping feature By feeding unlabeled data into the auxiliary segmentation network in a semi-supervised semantic segmentation model get.
[0056] Specifically, to ensure computational efficiency, the similarity matrix does not use feature vectors from all locations on both labeled and unlabeled samples. Instead, it selects a subset of features through sampling to participate in subsequent similarity calculations. Specifically, pixel-level feature vectors are collected from unlabeled data based on confidence levels. In this embodiment, the original segmentation network... and auxiliary segmentation network The two mapping headers that are connected afterward and Untagged data is passed through the mapping header. A set of features is sampled from the obtained mapping features, namely the first mapping features. Untagged data is passed through the mapping header. A set of features, namely the second mapping features, is sampled from the obtained mapping features. ,in Indicates the number of features retained in the sampling. This represents the dimension of the mapped features. (The above sampling is used for this purpose.) and From the same location in the unlabeled data. The unlabeled data is located via the mapping header. and A set of features is sampled from the obtained mapping features, specifically including: first from and We select pixels whose predictions are consistent. For each category, we sort the confidence scores of these pixels and select the feature vectors corresponding to the top i pixels as the feature vectors sampled from the unlabeled features. Therefore... and The relationship between them can be represented as
[0057]
[0058] Indicates the number of categories.
[0059] Based on prototype characteristics Calculate cross-entropy loss using mapping features Specifically, this includes: determining a first similarity matrix based on prototype features and a first mapping feature; determining a second similarity matrix based on prototype features and a second mapping feature; and calculating cross-entropy loss based on the first and second similarity matrices.
[0060] Specifically, in this embodiment, based on prototype features and the first mapping feature Determine the first similarity matrix The calculation formula is:
[0061]
[0062] in Represents cosine similarity. Indicates the temperature coefficient. This is the first similarity matrix obtained through calculation. .
[0063] Based on prototype characteristics Second mapping features Determine the second similarity matrix The calculation formula is:
[0064]
[0065] in Represents cosine similarity. Indicates the temperature coefficient. This is the calculated second similarity matrix. .
[0066] Based on the first similarity matrix Second similarity matrix Calculate cross-entropy loss The consistency of relationships in the similarity matrix is calculated using the cross-entropy loss function, which is as follows:
[0067]
[0068] Step 4: Based on the monitoring loss Cross-monitoring loss and cross-entropy loss Determine the training parameters of the semi-supervised semantic segmentation model, and train the semi-supervised semantic segmentation model based on the training parameters.
[0069] Specifically, based on the monitoring loss Cross-monitoring loss and cross-entropy loss The sum of these values determines the total loss of the semi-supervised semantic segmentation model; the total loss is obtained using the following formula:
[0070]
[0071] in, This represents the cross-entropy loss of the globally correlated consistency loss module. and These represent the supervised loss and the cross-pseudo-supervision loss in the cross-pseudo-supervision module, respectively. and It is used to control separately and The weight, and This is done manually. During training, a batch of mixed labeled and unlabeled data is fed into the network. The supervised loss is applied only to the labeled data, while all data is used to build cross-supervised learning.
[0072] This invention also includes: an auxiliary segmentation network comprising a cross-sample attention module. To achieve information transfer at any position in any sample within a mini-batch, the feature vector of each pixel can be regarded as a label, and self-attention computation is performed on all labels in the mini-batch. However, the complexity of this computation is proportional to the number of labels. The computational cost of this method is relatively high. Therefore, to achieve efficient computation of mutual attention among all pixels, this invention constructs a cross-sample attention module, which includes two consecutive attention modules. These two attention modules perform attention computation on different dimensions. Specifically, attention computation is first performed at all locations within each sample, and then cross-sample attention computation is performed on the batch dimension, thereby achieving efficient computation of mutual attention among all pixels.
[0073] The cross-sample attention module significantly enhances the common features between labeled and unlabeled data. The supervision signals from labeled and unlabeled data are backpropagated separately, which effectively improves the supervision of unsupervised samples by the gradient backpropagation signal from supervised data, thereby improving the semi-supervised learning effect with a small amount of labeled data.
[0074] Specifically, such as Figure 1 As shown, the cross-sample attention module includes two consecutive first self-attention encoding layers and a second self-attention encoding layer; denoted as... and Each encoding layer contains a multi-head attention module and an MLP module, and each encoding layer is followed by hierarchical normalization. For a mini-batch of input samples... ,in , Indicates the batch size. express The feature dimensions. Labeled data and the unlabeled data in the first self-attention encoding layer. Perform in-sample self-attention calculation, i.e. First, in the spatial dimension of each sample Intra-sample self-attention computation is performed on the first sample to model the information transmission path of features at different pixel positions within each sample. Then, to further achieve cross-sample information transmission, the cross-sample attention module performs inter-sample self-attention computation on the batch dimension. Labeled data and unlabeled data are processed in the second self-attention encoding layer. Self-attention computation is performed between samples. That is, pixels located at the same spatial position in different samples are input into a self-attention mechanism to construct cross-sample relationships.
[0075] In this invention, the original segmentation network serves as the backbone of the model. When the total loss of the semi-supervised semantic segmentation model reaches a preset standard, or after a preset number of training iterations, the auxiliary segmentation network is deleted, resulting in a semi-supervised semantic segmentation model with the original segmentation network as the backbone. This model is used to segment piglets in surveillance images to obtain the region where the piglets are located in the real-time surveillance image. This invention can also be used for the segmentation of other objects and can be widely applied in various fields, such as pedestrian detection, fingerprint recognition, and satellite imagery.
[0076] The results of this invention, after testing, show that with only 5% labeled data, the model obtained by this invention achieves a DICE coefficient (a performance metric in segmentation networks) of 87.34%, which is higher than the DICE coefficient of models trained with the same amount of labeled data using existing technologies. When the labeled data reaches 20%, the model of this invention is comparable to the results of fully supervised learning. Therefore, with the same amount of labeled and unlabeled data, the model trained by this invention performs better; and to obtain a model with equivalent performance, this invention requires less labeled and unlabeled data. This invention reduces the cost of manual labeling by reducing the amount of labeled data required.
[0077] Example 2
[0078] Based on the same concept, this embodiment of the invention also provides a pigsty monitoring model, which is obtained using the pigsty monitoring model training method as described in Embodiment 1.
[0079] Example 3
[0080] Based on the same concept, this invention also provides a pigsty monitoring method, comprising the following steps:
[0081] Step 1: Obtain a layout image of the pigsty, including a restricted area for piglets;
[0082] Step 2: Obtain real-time monitoring images of the pigsty;
[0083] Step 3: Input the real-time monitoring images into the pigsty monitoring model described in Example 2 to obtain the area where the piglets are located in each frame of the real-time monitoring image;
[0084] Step 4: Compare the area where the piglets are located in each frame of the real-time monitoring image with the restricted area for piglets. If they are the same, issue an alarm.
[0085] Example 4
[0086] Based on the same concept, this invention also provides a pigsty monitoring system, which includes a data acquisition module, a data processing module, and an alarm module.
[0087] The data acquisition module is used to acquire layout images of the pigsty and real-time monitoring images inside the pigsty, wherein the layout images include a restricted area for piglets;
[0088] The data processing module is used to input the real-time monitoring images into the pigsty monitoring model described in Embodiment 2 to obtain the area where the piglets are located in each frame of the real-time monitoring image;
[0089] The alarm module is used to compare the area where the piglets are located in each frame of real-time monitoring image with the prohibited area for piglets. If they are the same, an alarm is issued.
[0090] The semi-supervised semantic segmentation model of this invention achieves high-precision image segmentation with a small number of labeled samples, significantly improving the effectiveness of semi-supervised learning, greatly reducing dependence on labeled samples, reducing the workload of manual labeling, and saving a significant amount of time and human resources. This invention, through a cross-sample attention module and a global relevance consistency loss module, enables the semi-supervised semantic segmentation model to better capture features and contextual information in images, improving the accuracy and generalization ability of image segmentation. The pigsty monitoring system of this invention can monitor image data within the pigsty in real time, quickly and accurately detect the location of piglets, and adapt to changes in different scenes and environments, reducing labor costs, improving monitoring accuracy, and responding in real time to any potential problems.
[0091] The above embodiments merely illustrate several implementation methods of the present invention, and their descriptions are relatively specific and detailed, but they should not be construed as limiting the scope of the present invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of the present invention, and these all fall within the protection scope of the present invention. Therefore, the protection scope of this patent should be determined by the appended claims.
Claims
1. A method for training a pig house monitoring model, characterized in that, Includes the following steps: Step 1: Obtain pigsty monitoring data, which includes tagged data and untagged data; Step 2: Input the labeled data and the unlabeled data into the semi-supervised semantic segmentation model respectively to obtain the supervised loss and the cross-pseudo-supervised loss. Step 3: Determine the prototype features of the labeled data and the mapping features of the unlabeled data, and calculate the cross-entropy loss based on the prototype features and the mapping features; Step 4: Determine the training parameters of the semi-supervised semantic segmentation model based on the supervised loss, the cross-pseudo-supervised loss, and the cross-entropy loss, and train the semi-supervised semantic segmentation model based on the training parameters; The mapping features of the unlabeled data include a first mapping feature and a second mapping feature; The first mapping feature is obtained by inputting the unlabeled data into the original segmentation network in the semi-supervised semantic segmentation model; The second mapping feature is obtained by inputting the unlabeled data into the auxiliary segmentation network in the semi-supervised semantic segmentation model; The cross-entropy loss is calculated based on the prototype features and the mapping features, specifically including: A first similarity matrix is determined based on the prototype features and the first mapping features; A second similarity matrix is determined based on the prototype features and the second mapping features; The cross-entropy loss is calculated based on the first similarity matrix and the second similarity matrix.
2. The pig house monitoring model training method according to claim 1, characterized in that, The training parameters of the semi-supervised semantic segmentation model are determined based on the supervised loss, the cross-pseudo-supervised loss, and the cross-entropy loss, specifically including: The training parameters of the semi-supervised semantic segmentation model are determined based on the sum of the supervised loss, the cross-pseudo-supervised loss, and the cross-entropy loss. 3.The pig house monitoring model training method of claim 1, wherein, Determining the prototype features of the labeled data specifically includes: The labeled data is input into the original segmentation network in the semi-supervised semantic segmentation model to obtain the original prototype features; The labeled data is input into the auxiliary segmentation network in the semi-supervised semantic segmentation model to obtain auxiliary prototype features; The prototype features are determined based on the original prototype features and the auxiliary prototype features. 4.The pig house monitoring model training method of claim 1, wherein, The semi-supervised semantic segmentation model includes an auxiliary segmentation network, which includes a cross-sample attention module. The labeled data and the unlabeled data undergo attention calculation through the cross-sample attention module.
5. The pig house monitoring model training method according to claim 4, characterized in that, The cross-sample attention module includes two consecutive first self-attention encoding layers and second self-attention encoding layers; The labeled data and the unlabeled data undergo in-sample self-attention computation in the first self-attention encoding layer; The labeled data and the unlabeled data undergo inter-sample self-attention computation in the second self-attention encoding layer.
6. A method for monitoring pigsties, characterized in that, Includes the following steps: Step 1: Obtain a layout image of the pigsty, including a restricted area for piglets; Step 2: Obtain real-time monitoring images of the pigsty; Step 3: Input the real-time monitoring image into the pigsty monitoring model obtained by the pigsty monitoring model training method according to any one of claims 1-5 to obtain the area where the piglets are located in each frame of the real-time monitoring image; Step 4: Compare the area where the piglets are located in each frame of the real-time monitoring image with the prohibited area for piglets. If they are the same, an alarm will be issued.
7. A pigsty monitoring system based on the pigsty monitoring method of claim 6, characterized in that, include: Data acquisition module, data processing module, and alarm module; The data acquisition module is used to acquire layout images of the pigsty and real-time monitoring images inside the pigsty. The layout images include a restricted area for piglets. The data processing module is used to input the real-time monitoring image into the pigsty monitoring model obtained by the pigsty monitoring model training method according to any one of claims 1-5, so as to obtain the area where the piglets are located in each frame of the real-time monitoring image; The alarm module is used to compare the area where the piglets are located in each frame of real-time monitoring image with the prohibited area for piglets. If they are the same, an alarm is issued.