SAM2-C2F model-based group health-preserving pig daily behavior identification method
By independently designing the adapter module and feature fusion module on the SAM2 backbone network, and combining dynamic detection heads, a daily behavior recognition model for healthy pigs in SAM2-C2F group was constructed, solving the problems of slow identification speed and low accuracy in the existing technology, and achieving accurate identification of the daily behaviors of various types of pigs.
Patent Information
- Application Number
- CN202510070348.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-04-29
- Estimated Expiration
- 2045-01-16
AI Technical Summary
The existing pig behavior recognition technology has problems such as slow recognition speed, large model size, high calculation cost and low detection accuracy, and is difficult to apply in actual feeding.
Using SAM2 backbone network as the basis, the Symmetric Adapter module and Adjustment Channel module are independently designed, and the C2F feature fusion module and dynamic detection head are integrated to build a daily behavior recognition model for health pigs in SAM2-C2F group.
Accurate identification of up to seven daily behaviors of pigs has been achieved, the accuracy of behavior recognition and the application efficiency of models has been improved, and an innovative solution has been provided for the behavior recognition of group health pigs.
Smart Images

Figure CN119904913A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer vision and behavior recognition technology, and specifically provides a method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model. The technology is particularly suitable for group-raised pig environments and can realize various daily behavior recognition of multiple pigs. Background Art
[0002] As a major pig-raising country in the world, my country will have a national pig output of 670 million heads in 2021 and nearly 700 million heads in 2022. With such a huge output, more attention should be paid to pig safety, so biocontrol in pig farms is more important than ever. Pig farms should reduce the flow of personnel, vehicles, and materials as much as possible, and it is inconvenient for management personnel to frequently enter and exit pig farms. The intelligentization and de-humanization of pig production management processes have become urgent problems that pig farms need to solve. Among them, accurate identification of pigs' daily behaviors through images or videos can improve pig farming efficiency and economic benefits, while reducing the risk of human-pig disease infection during pig production, which is conducive to the health and sustainable development of the breeding industry.
[0003] Pig behavior identification is of great significance in agriculture and animal husbandry. For example: 1) Precision feeding. By identifying the behavior patterns of pigs, we can better understand individual needs and implement personalized feeding plans. For example, adjust the feed ratio according to the activity level and eating habits of pigs to improve feed utilization. 2) Reduce stress response. By monitoring the behavior of pigs, we can find out which environmental factors or management behaviors will cause stress response, thereby optimizing the breeding environment, reducing stress, and improving the quality of life of pigs. 3) Health management. Timely detection of abnormal behaviors, such as loss of appetite and slow movement, can help diagnose diseases early, take preventive measures, and reduce the risk of disease transmission.
[0004] Early pig behavior recognition mainly used electronic sensors and traditional image methods for perception, but there were disadvantages such as intervention in pig behavior, complex steps, and slow recognition speed. Subsequent scholars applied deep learning to pig behavior recognition and achieved relatively good results. However, most researchers only identified one or two or three types of pig behavior, and the pig behavior detected by the model was relatively simple. In addition, many researchers only considered the accuracy of model detection or the speed of model operation. If only the accuracy of model detection is considered, the model will be large in size, with high computational cost and slow computational speed, and the model will be difficult to apply in the actual breeding process; and if only the model running speed is considered, although the model is small, the detection accuracy is low, and it cannot be applied in the actual breeding process.
[0005] In view of the limitations of the prior art, the present invention proposes a method for identifying the daily behaviors of group-raised pigs based on the SAM2-C2F model. This method adopts the SAM2 backbone network, which is very popular in the field of transfer learning. On the basis of freezing the pre-trained weight parameters of the SAM2 backbone network, the Symmetric Adapter module and Adjustment Channel module are independently designed, so that the model can make full use of the powerful feature extraction capabilities of the SAM2 backbone network to be more accurately applied to the downstream task of identifying the daily behaviors of group-raised pigs. In addition, the C2F feature fusion module is integrated to fully integrate feature information from different scales to improve the representation ability and task performance of the model; the dynamic detection head is used to improve the accuracy of identifying the daily behaviors of group-raised pigs.
[0006] The present invention independently designs the Symmetric Adapter module and Adjustment Channel module based on the SAM2 backbone network, integrates the C2F feature fusion module and the dynamic detection head, and thus constructs the SAM2-C2F group-raised pig daily behavior recognition model. Compared with previous methods, the present invention is the first to introduce the SAM2 backbone network in the field of group-raised pig daily behavior recognition, which can accurately identify up to seven daily behaviors of pigs, providing an innovative solution for group-raised pig behavior recognition. Summary of the invention
[0007] The present invention aims to provide a method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model. The technology uses self-collected and self-built pig multi-type behavior data sets, and independently designs the Symmetric Adapter module and Adjustment Channel module on the basis of freezing the pre-trained weight parameters of the SAM2 backbone network, and integrates the C2F feature fusion module and the dynamic detection head, thereby constructing the SAM2-C2F group-raised pig daily behavior recognition model, and realizing very accurate recognition of multi-type behaviors of pigs.
[0008] A method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model is provided. A recognition model is constructed for various daily behaviors of pigs to automatically identify daily behaviors of group-raised pigs. The method comprises the following steps:
[0009] S1. Use online video equipment to obtain video data of pig activities in the pig pen at different time periods in a group pig house environment.
[0010] S2. Use video frame extraction technology to obtain and organize key frame images of pig activities, and use data enhancement technology to expand pig behavior data images.
[0011] S3. Label the pigs in the pictures according to their different behaviors, including seven daily behaviors: drink, eat, mount, stand, lie, lateral, and sit. Build a multi-category daily behavior recognition dataset for pigs and divide the dataset into training set, validation set, and test set.
[0012] S4. Based on the SAM2 backbone network, on the basis of freezing the pre-trained weight parameters of the SAM2 backbone network, we independently designed the Symmetric Adapter module and Adjustment Channel module, integrated the C2F feature fusion module and the dynamic detection head, and then constructed a daily behavior recognition model for group-raised pigs based on the SAM2-C2F model.
[0013] S5. Input the images in the training set and the validation set into the SAM2-C2F model for training to obtain the optimal weight parameters of the SAM2-C2F model.
[0014] S6. Input the test set images into the SAM2-C2F model loaded with the optimal weight model, and output the results of pig behavior recognition in the pig house environment, including the target box position, behavior category and confidence.
[0015] Furthermore, the online camera device in step S1 is a Hikvision network camera, model DS-IPC-T13HV3-IA, with a resolution of 1920×720 and a video frame rate of 25fps. A python script is used to record the pig activities in four time periods of 5:00-9:00, 11:00-15:00, 17:00-21:00, and 23:00-3:00 every day in real time, and the pigs are organized and saved as pig behavior data videos.
[0016] Furthermore, in step S2, representative pig behavior data videos are screened, and pig behavior data images are obtained using a video frame extraction script, and specifically, the Opencv program is used to extract key frame images of pig activities in the video. Due to the uneven distribution of pig behavior instances in the pig behavior data images, the data enhancement techniques in step S2 include Cutout and Cutmix, and the Cutout data enhancement method and the Cutmix data enhancement method are used to solve the problem of the long-tail effect of the number of pig behaviors. The Cutout data enhancement method generates a new image by randomly cutting out a part of the image, which is conducive to making the model more robust and avoiding excessive reliance on specific areas; the Cutmix data enhancement method generates a new image by mixing local areas of two images, which is conducive to solving problems of different categories and using data more efficiently.
[0017] Furthermore, in step S3, LabelImg is used to label the behavior categories of the pigs in the picture, and the labeled file has a txt suffix, and the file name is consistent with the picture name. The image and label file are matched, and the data set is divided into a training set, a validation set, and a test set in a ratio of 8:1:1 to construct a multi-category daily behavior recognition data set for pigs.
[0018] Furthermore, the Symmetric Adapter module designed independently in step S4 is an Adapter added to the top and bottom of the frozen SAM2 backbone network respectively. The adapter is composed of a downsampling fully connected layer, an activation function layer, an upsampling fully connected layer and an activation function layer. Since the backbone network is frozen and will not change with the training of the adapter, it can ensure that the feature representation provided by the backbone network is stable, while allowing the adapter to focus on learning the nuances of the specific task of daily behavior recognition of group-raised pigs. The design of the symmetric adapter helps the model to perform targeted optimization of feature maps at different levels in the frozen SAM2 backbone network, thereby making full use of the powerful feature extraction capabilities of the SAM2 backbone network.
[0019] Furthermore, the independently designed Adjustment Channel in step S4 is used to adjust the number of channels of the feature map output by the last three layers of encoders of the SAM2 backbone network. It is mainly composed of a channel attention mechanism and a channel adjustment convolution layer. The channel adjustment module can dynamically assign weights to each channel, highlight the features that are more important for pig behavior recognition, and suppress irrelevant features. By focusing on important features, the channel adjustment module can make the model more robust and better able to cope with noise, occlusion or other adverse conditions. In addition, the channel adjustment module can help reduce unnecessary calculations, facilitate subsequent feature fusion, and thus optimize the use of computing resources of the model.
[0020] Furthermore, the C2F feature fusion module in step S4 mainly refers to the C2F module designed by predecessors. It is used to integrate feature information from different scales to improve the representation ability and task performance of the model. Feature maps of different scales usually contain information at different levels. Low-level feature maps capture more local details and edge information, while high-level feature maps contain more extensive contextual information. Specifically, by adopting FPN (feature pyramid network) and PAN (path aggregation network) to integrate the C2F module into the feature fusion network, which is used to fuse feature maps from different levels, the model can benefit from local details and global context at the same time, thereby improving the accuracy of the SAM2-C2F model in identifying the daily behaviors of group-raised pigs.
[0021] Furthermore, the dynamic detection head in the SAM2-C2F model in step S4 mainly includes offset and mask calculation, dynamic convolution, scale attention module and task attention module. The offset and mask are calculated through a convolution layer, and the module is used to calculate the offset and mask required for dynamic convolution; the dynamic convolution is used to process feature maps of different scales; the scale attention module can allocate the importance of features of different scales; the task attention module is used to adjust the feature map to better adapt to the task requirements.
[0022] Furthermore, the SAM2-C2F model in step S5 includes an input end, a symmetric adapter and a frozen SAM2 backbone network, a channel adjustment module, a C2F feature fusion module and a dynamic detection head connected in this way, and the method of inputting the image into the SAM2-C2F model for model training is:
[0023] S5-1, the image is preprocessed through the input end, and the preprocessing includes Mosaic data enhancement and adaptive image scaling;
[0024] S5-2, the preprocessed image enters the backbone network composed of the symmetric adapter and the frozen SAM2 backbone network in SAM2-C2F, and three feature maps of different sizes are obtained after the channel adjustment module;
[0025] S5-3, inputting the three feature maps of different sizes obtained in step S5-2 into the C2F feature fusion module to fuse the features from different scales to obtain feature maps of three scales;
[0026] S5-4, inputting the feature maps of the three scales obtained in step S5-3 into the motion detection head end to obtain three feature tensors, and then obtaining the position and behavior category of the prediction box;
[0027] S5-5. During the training phase, the predicted box is matched with the true box to obtain positive and negative samples, and then the weight parameters are adjusted by calculating the loss function. At the end of each iteration, the validation set is used to calculate the accuracy and average precision to continuously optimize the model parameters.
[0028] Furthermore, the SAM2-C2F model sets the maximum number of training iterations (epochs) to 100 times, the number of input images (batch) for each model training is 12, and the initial learning rate of the model is 0.0001; the learning rate is updated by preheating for the first three iterations, and then the cosine annealing algorithm is used to update the learning rate.
[0029] Furthermore, the backbone network composed of the symmetric adapter and the frozen SAM2 backbone network comprises a SAM2 backbone network and a symmetric adapter. The symmetric adapter is an adapter added to the top and bottom ends of the frozen SAM2 backbone network respectively. The adapter is composed of a downsampling fully connected layer, an activation function layer, an upsampling fully connected layer and an activation function layer. The SAM2 backbone network adopts a multi-layer VIT (Vision Transformer) structure, which is combined with a symmetric adapter to extract image features, extract image features A1, A2, A3 of 44×44, 22×22 and 11×11 pixels, and obtain semantic information of different scales.
[0030] Furthermore, the channel adjustment module is mainly composed of a channel attention mechanism and a channel adjustment convolution layer. The channel adjustment module can dynamically assign weights to each channel, highlight the features that are more important for pig behavior recognition, and suppress irrelevant features. By focusing on important features, the channel adjustment module can make the model more robust and better able to cope with noise, occlusion or other adverse conditions. In addition, the channel adjustment module can help reduce unnecessary calculations and facilitate subsequent feature fusion, thereby optimizing the model's computing resource usage. The channel adjustment module is used to uniformly adjust the three feature maps A1, A2, and A3 with different numbers of channels to feature maps B1, B2, and B3 with 64 channels.
[0031] Furthermore, the C2F feature fusion module adopts FPN (Feature Pyramid Network) and PAN (Path Aggregation Network). FPN uses upsampling to transfer and fuse information, and PAN transfers deep target positioning from bottom to top. The lightweight neck upsamples the feature map B3, then fuses it with the feature map B2 and passes through C2F to obtain a 22×22 feature map C2; the feature map C2 is fused with the feature map B1 through upsampling and then passes through the C2F module to obtain a 44×44 feature map C1; the feature map C1 passes through the Conv module, is fused with the feature map C2 and then passes through the C2F module to obtain a 22×22 feature map D2; the feature map D2 passes through the Conv module, is fused with the feature map B3 and then passes through the C2F module to obtain a 11×11 feature map D3.
[0032] Furthermore, after the feature maps C1, D2, and D3 are input to the motion detection head, three feature tensors (4×reg_max+nc)×44×44, (4×reg_max+nc)×22×22, and (4×reg_max+nc)×11×11 are obtained, where reg_max is the number of channels output by each anchor point, and nc is the behavior category (there are seven categories in total). reg_max is 16 and nc is 7.
[0033] Furthermore, the weight parameters are adjusted by classification loss and rectangular box loss. The classification loss is obtained by first using the binary cross entropy loss function for each of the seven categories and then taking the average. The rectangular box loss includes DFL loss and CIoU loss. DFL trains the model by minimizing the cross entropy between the true label distribution and the model prediction distribution, so that the network can focus on the probability distribution near the target position more quickly, effectively handle the difficult samples in the target detection task, and improve the performance and robustness of the model. CIoU is an improved version of IoU, which takes the center point distance, overlap rate and minimum circumscribed matrix diagonal length as parameters, and introduces a direction factor to consider the rotation and direction of the bounding box. The CIoU loss calculation formula is as follows, where α is the weight coefficient and ν represents the parameter for measuring the similarity of the aspect ratio. Taking into account multiple factors such as position, shape and direction, the model can learn the characteristics of the target box more comprehensively. Its calculation formula is shown in formulas (1)-(3).
[0034]
[0035]
[0036]
[0037] Beneficial effects of the present invention:
[0038] 1. This invention introduces the SAM2 backbone network into the field of daily behavior recognition of group-raised pigs in the form of transfer learning for the first time, constructs the SAM2-C2F group-raised pig daily behavior recognition model, and provides a new solution for group-raised pig behavior recognition;
[0039] 2. The present invention independently designs the Symmetric Adapter module and AdjustmentChannel module, which helps to fully apply the powerful feature extraction capability of the SAM2 backbone network to the downstream task of daily behavior recognition of group-raised pigs, thereby improving the accuracy of pig behavior recognition;
[0040] 3. The present invention has built a dataset for the identification of various types of daily behaviors of pigs, which is convenient for other researchers to continue to carry out related research. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a network structure diagram of the daily behavior recognition model of group-raised pigs based on the SAM2-C2F model of the present invention.
[0042] Figure 2 It is a schematic diagram of the training set in the self-built data set of the present invention after data processing.
[0043] Figure 3It is a schematic diagram of the test set in the self-built data set of the present invention after data processing.
[0044] Figure 4 yes Figure 3 Schematic diagram of corresponding recognition of the test set. DETAILED DESCRIPTION
[0045] The principles and features of the present invention are described below in conjunction with the accompanying drawings. The examples given are only used to explain the present invention and are not used to limit the scope of the present invention.
[0046] As shown in the figure, the present invention provides a method for identifying the daily behaviors of group-raised pigs based on the SAM2-C2F model, wherein the SAM2-C2F model is based on the SAM2 backbone network, and independently designs a Symmetric Adapter module and an Adjustment Channel module, and integrates a C2F feature fusion module and a dynamic detection head, thereby constructing a SAM2-C2F group-raised pig daily behavior recognition model.
[0047] The backbone network composed of the symmetric adapter and the frozen SAM2 backbone network is mainly used to extract multi-level features from the input image and gradually reduce the spatial size of the image. Since the SAM2 backbone network is frozen and will not change with the training of the adapter, it can ensure that the feature representation provided by the SAM2 backbone network is stable, while allowing the symmetric adapter to focus on learning the nuances of the specific task of daily behavior recognition of group-raised pigs, which helps the model to optimize the feature maps of different levels in the frozen SAM2 backbone network in a targeted manner, thereby making full use of the powerful feature extraction capabilities of the SAM2 backbone network. After receiving feature maps of different numbers of channels from the backbone network, the channel adjustment module can dynamically assign weights to each channel using the channel attention mechanism and the channel adjustment convolution layer, highlighting the features that are more important for pig behavior recognition and suppressing irrelevant features. In addition, it can also help reduce unnecessary calculations and facilitate subsequent feature fusion, thereby optimizing the use of computing resources of the model. The C2F feature fusion module is used to integrate feature maps from different scales processed by the channel adjustment module to improve the representation ability and task performance of the model. Feature maps of different scales usually contain information at different levels. Low-level feature maps capture more local details and edge information, while high-level feature maps contain more extensive contextual information. The C2F feature fusion module can fuse these features of different scales to enable the model to benefit from both local details and global context, thereby improving the ability to understand complex scenes, and further improving the accuracy of the SAM2-C2F model in identifying the daily behaviors of group-raised pigs. The dynamic detection head mainly includes offset and mask calculation, dynamic convolution, scale attention module and task attention module. The offset and mask are calculated through a convolution layer, which is used to calculate the offset and mask required for dynamic convolution; dynamic convolution is used to process feature maps of different scales; the scale attention module can assign the importance of features of different scales; and the task attention module is used to adjust the feature map to better adapt to the task requirements. The dynamic detection head adaptively adjusts its internal parameters and structure, so that the model can better process feature maps of different scales, thereby improving the recognition accuracy of multiple types of pig behavior recognition.
[0048] The loss function of the SAM2-C2F model includes classification loss and rectangular box loss. The classification loss is obtained by comparing seven categories pairwise and taking the average after calculation using the binary cross entropy loss function. The rectangular box loss consists of two losses: DFL and CIoU. DFL enables the network to focus on the position near the target more quickly by minimizing the difference between the true label distribution and the model prediction distribution, thereby effectively processing those difficult-to-distinguish samples and improving the performance and robustness of the model. CIoU is an improved version of IoU. It not only considers the distance and overlap ratio of the center point, but also includes the minimum diagonal length of the circumscribed matrix, and introduces a direction factor to consider the rotation angle of the bounding box. In addition, the CIoU loss function is used to measure the similarity of the aspect ratio by introducing the parameter ν. Therefore, CIoU comprehensively considers multiple factors such as position, shape and direction, enabling the model to learn the characteristics of the target box more comprehensively. The classification loss and rectangular box loss work together in the training process of the model. The former optimizes the classification performance by comparing the losses of multiple categories, and the latter improves the accuracy of bounding box regression by combining DFL and CIoU. This comprehensive loss function design enables the model to show higher accuracy and robustness in multi-category object detection tasks.
[0049] Based on the self-built dataset, the daily behavior recognition dataset of multiple categories of pigs, this paper takes the daily behaviors of multiple categories of pigs as the object, and conducts research on the daily behavior recognition method based on the SAM2-C2F model for group-raising pigs in pig house environments. The daily behavior recognition dataset of multiple categories of pigs is a self-built dataset based on LabelImg software. It is the first daily behavior recognition dataset of multiple categories of pigs based on target detection tasks. It contains 977 high-definition images with a resolution of 1280×720, covering more than 5500 behavior instances, including seven daily behaviors of drink, eat, mount, stand, lie, lateral, and sit, which include common behaviors of pigs. In order to carry out effective training and evaluation, this paper randomly divides the dataset into training set (781 images), validation set (98 images) and test set (98 images) in a ratio of 8:1:1.
[0050] The present invention uses Pytorch2.2.2 deep learning framework, Pycharm compiler, python3.8. The hardware environment is Intel Core i7-5930K processor, NVIDIA GeForce RTX 4090 24GB graphics card, and operating system Ubuntu20.04.6LTS. After the environment is deployed, the SAM2-C2F model is used for iterative training. During the experiment, the SGD optimizer is used, the initial learning rate is 0.0001, the SGD optimizer momentum is 0.937, the weight decay is 0.0005, the iteration is 100 rounds, and the batch-size is 12.
[0051] In order to analyze the performance of the model, the model performance evaluation indicators are precision rate P (Precision), recall rate R (Recall), target accuracy AP (Average Precision), average target accuracy mAP (mean Average Precision), model volume and number of parameters. In the experiment, the mAP takes the IoU threshold as 0.5, that is, mAP@0.5. The calculation formula of the indicator is shown in formulas (1)-(4).
[0052]
[0053]
[0054]
[0055]
[0056] Among them, TP represents the number of instances of a certain behavior category of pigs that the model correctly detects, FP represents the number of instances of a certain behavior category of pigs that the model fails to accurately detect, and FN represents the number of instances of a certain behavior category of pigs that the model fails to detect. c represents the total number of pig behavior categories, and APi represents the target accuracy of the i-th category.
[0057] The above is an example of the best implementation of the present invention, and the parts not described in detail are common knowledge of ordinary technicians in the field. The protection scope of the present invention shall be based on the content of the claims, and any equivalent transformation based on the technical enlightenment of the present invention is also within the protection scope of the present invention.
Claims
1. A method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model, characterized in that: According to the various daily behaviors of pigs, a recognition model is constructed to automatically recognize the daily behaviors of group-raised pigs, including the following steps: Step S1, using online camera equipment to obtain pig behavior data videos at different time periods in the pig pen; Step S2, using video frame extraction technology to obtain and organize pig behavior data pictures and expand the pig behavior data pictures based on data enhancement; Step S3, using LabelImg software to label seven daily behaviors of pigs and construct a multi-category daily behavior recognition dataset for pigs; Step S4: Based on the SAM2 backbone network, on the basis of freezing the pre-trained weight parameters of the SAM2 backbone network, independently designing a symmetric adapter module and a channel adjustment module, integrating the C2F feature fusion module and the dynamic detection head, and constructing a pig daily behavior recognition model based on the SAM2-C2F model; Step S5, training a pig daily behavior recognition model based on the SAM2-C2F model; Step S6: Use the trained pig daily behavior recognition model to recognize the daily behavior of group-raised pigs.
2. The method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model according to claim 1 is characterized in that: In step S1, a Hikvision DS-IPC-T13HV3-IA online camera is installed in a group pig house environment, and a python script is used to record the pig activities in four time periods of 5:00-9:00, 11:00-15:00, 17:00-21:00, and 23:00-3:00 every day in real time, and the data are organized and saved as pig behavior data videos.
3. The method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model according to claim 1, characterized in that: In the step S2, representative pig behavior data videos are screened, and pig behavior data images are obtained using a video frame extraction script; and the Cutout data enhancement method and the Cutmix data enhancement method are used to solve the problem of the long-tail effect of the pig behavior quantity; wherein the Cutout data enhancement method generates a new data image by randomly cutting out a part of the image; and the Cutmix data enhancement method generates a new data image by mixing local areas of two images.
4. The method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model according to claim 1, characterized in that: The seven daily behaviors of pigs in step S3 are drink, eat, mount, stand, lie, lateral and sit; the pig behavior data pictures expanded in step S2 are annotated with the image annotation tool LabelImg to construct a multi-category daily behavior recognition dataset for pigs.
5. The method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model according to claim 1, characterized in that: The group-raised pig daily behavior recognition model based on the SAM2-C2F model in step S4 includes an input end, a symmetric adapter module, a frozen SAM2 backbone network, a channel adjustment module, a C2F feature fusion module and a dynamic detection head connected in this way; wherein the symmetric adapter module is an adapter added to the top and bottom ends of the frozen SAM2 backbone network respectively; the adapter is composed of a downsampling fully connected layer, an activation function layer, an upsampling fully connected layer and an activation function layer; wherein the adapter focuses on learning the nuances of the specific task of group-raised pig daily behavior recognition, and can help the model to optimize the feature maps of different levels in the frozen SAM2 backbone network in a targeted manner; the channel adjustment module is used to adjust the number of channels of the feature map output by the last three layers of the SAM2 backbone network encoder, and is composed of a channel attention mechanism and a channel adjustment convolutional layer; the channel adjustment module can dynamically assign weights to each channel, highlight the features that are more important for pig behavior recognition, and suppress irrelevant features; and can reduce unnecessary calculations, facilitate subsequent feature fusion, thereby The C2F feature fusion module adopts the FPN feature pyramid network and the PAN path aggregation network to integrate feature information from different scales to improve the representation ability and task performance of the model. Feature maps of different scales usually contain information at different levels. The low-level feature maps capture more local details and edge information, while the high-level feature maps contain more extensive contextual information. The C2F feature fusion module enables the model to benefit from both local details and global context by fusing these features of different scales, thereby improving the ability to understand complex scenes, thereby improving the accuracy of the SAM2-C2F model in identifying the daily behavior of group-raised pigs. The dynamic detection head includes offset and mask calculation, dynamic convolution, scale attention module and task attention module. The offset and mask are calculated through a convolution layer to calculate the offset and mask required for dynamic convolution. Dynamic convolution is used to process feature maps of different scales. The scale attention module is used to assign the importance of features of different scales. The task attention module is used to adjust the feature map to better adapt to task requirements.
6. The method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model according to claim 5 is characterized in that: The specific steps of step S5 include: S5-1, the image is preprocessed through the input end, and the preprocessing includes Mosaic data enhancement and adaptive image scaling; S5-2, the preprocessed image enters the backbone network composed of the symmetric adapter and the frozen SAM2 backbone network in SAM2-C2F, and three feature maps of different sizes are obtained after the channel adjustment module; S5-3, inputting the three feature maps of different sizes obtained in step S5-2 into the C2F feature fusion module to fuse the features from different scales to obtain feature maps of three scales; S5-4, inputting the feature maps of the three scales obtained in step S5-3 into the motion detection head end to obtain three feature tensors, and then obtaining the position and behavior category of the prediction box; S5-5. During the training phase, the predicted box is matched with the true box to obtain positive and negative samples, and then the weight parameters are adjusted by calculating the loss function. At the end of each iteration, the validation set is used to calculate the accuracy and average precision to continuously optimize the model parameters.
7. The method for identifying daily behaviors of group-raised pigs based on the SAM2-C2F model according to claim 6, characterized in that: In step S5-1, the number of input images each time is 12, and the initial learning rate of the model is 0.0001; the learning rate is updated by preheating for the first three iterations, and then the learning rate is updated by the cosine annealing algorithm; In the step S5-2, image features A1, A2, A3 of 44×44, 22×22 and 11×11 pixels are extracted to obtain semantic information of different scales; the feature maps A1, A2, A3 of three different numbers of channels are uniformly adjusted to feature maps B1, B2, B3 with 64 channels through a channel adjustment module; In the step S5-3, the feature map B3 is upsampled, and then fused with the feature map B2 and then passed through C2F to obtain a 22×22 feature map C2; the feature map C2 is fused with the feature map B1 through upsampling and then passed through the C2F module to obtain a 44×44 feature map C1; the feature map C1 passes through the Conv module, is fused with the feature map C2 and then passes through the C2F module to obtain a 22×22 feature map D2; the feature map D2 passes through the Conv module, is fused with the feature map B3 and then passes through the C2F module to obtain a 11×11 feature map D3, and finally obtains feature maps C1, D2, and D3 of three scales; In step S5-4, after the feature maps C1, D2, and D3 are input into the dynamic detection head, three feature tensors (4×reg_max+nc)×44×44, (4×reg_max+nc)×22×22, and (4×reg_max+nc)×11×11 are obtained, where reg_max is the number of channels output by each anchor point, and the value is 16; nc is the behavior category, and the value is 7; In the step S5-5, the weight parameters are adjusted by the classification loss and the rectangular box loss, wherein the rectangular box loss includes the DFL loss and the CIoU loss.
Citation Information
Patent Citations
Group health-preserving pig fighting behavior identification method fusing space-time double attention mechanism
CN114299436A
Method for identifying and tracking behaviors of health-preserving pigs in group
CN115223191A
Pig behavior identification method and system
CN119131877A
Cited By
Panda behavior identification method and system based on large model
CN121904840A