A method for detecting daily behavior of group-reared pigs

By improving the YOLOv4 network model and using lightweight MobileNetv3 network and depth-separable convolution, the problems of equipment damage and large calculation load of traditional detection methods are solved, real-time detection of pig daily behaviors on embedded devices is achieved, and detection speed is improved. and accuracy.

CN113822185BActive Publication Date: 2024-10-29ANHUI AGRICULTURAL UNIVERSITY +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202111057182.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-09-09
Publication Date
2024-10-29
Estimated Expiration
2041-09-09

AI Technical Summary

Technical Problem

Among the existing pig daily behavior detection methods, traditional sensor detection technology has the risk of equipment damage and infection. However, the YOLOv4 algorithm in computer vision technology is difficult to implement on embedded devices with weak computing capabilities due to its large number of parameters and huge amount of calculations. Real time application.

Method used

Adopt the improved YOLOv4 network model, use the lightweight MobileNetv3 network, introduce deep separable convolution and inception network structures, reduce the number of parameters, reduce the amount of calculation, and replace the traditional convolution and pooling layers in the detector to improve the detection speed and real-time.

Benefits of technology

On the premise of ensuring the recognition accuracy, the detection speed and real-time performance are significantly improved. It is suitable for embedded devices and suitable for real-time detection of daily behaviors of pigs raised in groups.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113822185B_ABST
    Figure CN113822185B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for detecting the daily behavior of group-raised pigs. The method obtains images of the daily behavior of group-raised pigs in a target area to be detected, inputs them into an improved YOLOv4 network model for detection, and obtains the classification of the daily behavior of pigs in the output image. The improved YOLOv4 network model is: a lightweight MobileNetv3 network is used to replace the CSPDarknet53 network in the original model YOLOv4, which can reduce the number of parameters and reduce the amount of calculation without causing loss of accuracy; and further introduces a deep separable convolution and inception network structure in the detector to broaden the network width and depth, and on the premise of ensuring the recognition accuracy, the detection speed is faster and the real-time performance is stronger.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image recognition, and in particular to a method for detecting the daily behavior of group-raised pigs. Background Art

[0002] With the popularization of smart agriculture, intelligent farming is gaining more and more attention. The identification and positioning of daily behaviors of pigs is an important preliminary work for digital farming. If pigs keep lying or sitting for a long time, it indicates that they may be in abnormal state such as sickness. Using deep learning target detection technology to quickly and accurately detect abnormal behaviors of pigs in the farming process is of great significance for early warning of pig diseases and taking timely countermeasures.

[0003] At present, common methods for detecting daily behaviors of livestock include sensor detection technology and computer vision technology. Traditional sensor detection technology requires individual pigs to wear ear tag sensors. Traulsen et al. used ear-stick accelerometers to collect the motion acceleration of sows. Wang Kai et al. used sow neck behavior sensors to obtain behavior data and analyze sow estrus behavior. Although such methods can record various parameters of individual pigs, they may be damaged due to biting by pigs, and may cause problems such as parasite infection in pigs. With the continuous development of computer vision technology, visual analysis technology based on convolutional neural networks has made great progress in many fields of intelligent pig farming. For example, Marsort et al. proposed an adaptive pig face recognition method based on convolutional neural networks, with an accuracy rate of 83%; Gan Haiming et al. proposed a method based on spatiotemporal information fusion to identify sow lactation behavior, achieving a recognition rate of 97.85%; Yan Hongwen et al. proposed a pig facial behavior recognition method based on an improved Tiny-YOLO model, with an accuracy rate of 82.38%; Eric T. Psota et al. proposed a fully convolutional neural network for instance segmentation of pigs, with an accuracy rate of 91%.

[0004] Convolutional neural network detection algorithms can be divided into two-stage algorithms based on candidate regions, such as R-CNN and Fast R-CNN, and one-stage algorithms based on regression, such as SSD and YOLO series. Among them, the YOLOv4 algorithm has brought together previous research results and has greatly improved detection accuracy, but it also has obvious defects, such as the large number of parameters leading to a large amount of calculation, occupying a large amount of disk space, and it is difficult to implement real-time applications on embedded devices with weak computing power in actual production environments. Summary of the invention

[0005] The purpose of the present invention is to solve the shortcomings of the above-mentioned prior art and to propose a method for detecting the daily behavior of group-raised pigs.

[0006] To achieve the above object, the technical solution adopted by the present invention is:

[0007] The embodiment of the present invention provides a method for detecting daily behaviors of group-raised pigs, comprising:

[0008] S1. Acquire images of daily behaviors of group-raised pigs in the target area to be detected;

[0009] S2. Detecting the image by a pre-trained pig behavior detection model; the detection model is obtained by training an improved YOLOv4 network model with multiple sets of training data; each set of the multiple sets of training data includes a target frame of the daily behavior of the pig; the improved YOLOv4 network model adopts a lightweight MobileNetv3 network, and introduces a deep separable convolution and inception network structure in the detector;

[0010] S3. Determine the classification of the daily behavior of the pigs in the image according to the detection result of the detection model.

[0011] Furthermore, the improved YOLOv4 network model uses a lightweight MobileNetv3 network, including:

[0012] The improved YOLOv4 network model uses a lightweight MobileNetv3 network, deletes the convolutional layer and pooling layer network behind MobileNetv3, and retains the Bneck structure of the network for feature extraction, including the SE module;

[0013] Feature maps are extracted at the 7th, 13th and 16th layers of Bneck respectively.

[0014] Furthermore, a depth-wise separable convolution is introduced into the detector, including:

[0015] 1×1 point convolution and 3×3 depth convolution will be used to replace the original 3×3 traditional convolution, and the nonlinear h-swish function will be used as the activation function to replace the Leaky ReLU function used in the original detection network.

[0016] Furthermore, the inception network structure is introduced into the detector, including:

[0017] Use 1×3 and 3×1 convolution kernels to replace the 5×5 convolution kernel in the original structure;

[0018] Average pooling is used instead of the maximum pooling of the original structure.

[0019] Furthermore, the training steps of the improved YOLOv4 network model include:

[0020] The surveillance cameras are used to collect images of live pigs at different times and angles in the actual scene of the pig farm;

[0021] Processing the pig images and dividing them into a training set, a validation set and a test set according to a preset ratio;

[0022] The YOLOv4 network model is improved by using a lightweight MobileNetv3 network and introducing deep separable convolution and inception network structures into the detector to obtain an improved YOLOv4 network model.

[0023] Using the processed pig images included in the training set, performing iterative optimization training on the improved YOLOv4 network model;

[0024] When the preset conditions are met, the training is terminated and the trained pig behavior detection model is obtained.

[0025] Furthermore, the loss function of the trained pig behavior detection model is:

[0026] total_loss = L loc +L conf +L cls (4)

[0027] (4) In the formula, L loc Indicates the coordinate position loss, using CIOU error; L conf represents the confidence loss; L cls Represents category loss, using binary cross entropy function;

[0028]

[0029]

[0030]

[0031] In formulas (5)-(7), s 2 represents the number of grids; B represents the number of prior boxes in each grid; IOU(A,B) represents the intersection-over-union ratio of the predicted box and the true box; ρ(A ctr ,B ctr ) represents the Euclidean distance between the center points of the predicted box and the true box; m represents the diagonal distance of the smallest enclosed area that contains both the predicted box and the true box; w gt and h gt represents the width and height of the real box; w and h represent the width and height of the predicted box; Indicates whether the jth bounding box of the i-th grid cell contains the target, which is 1 or 0 respectively; Indicates whether the jth bounding box of the i-th grid cell does not contain the target, which is 0 or 1 respectively; represents the prediction confidence, represents the true confidence, λ noobj represents the weight coefficient; c represents the category, represents the probability that the target in the cell belongs to category c, represents the predicted probability.

[0032] Furthermore, processing the pig image includes:

[0033] Set a preset sampling interval to filter the collected pig images. The selected samples include samples of different time periods, different light intensities, and different shooting instructions, and the size is unified;

[0034] Use Mosaic data augmentation to increase the number of samples;

[0035] Use the labelImg image annotation tool to annotate the daily behaviors of pig images and assign label names.

[0036] Compared with the prior art, the present invention has the following beneficial effects:

[0037] The embodiment of the present invention provides a method for detecting the daily behavior of group-raised pigs. The method obtains images of the daily behavior of group-raised pigs in the target area to be detected, inputs them into the improved YOLOv4 network model for detection, and obtains the classification of the daily behavior of pigs in the output image. Among them, the improved YOLOv4 network model is: using a lightweight MobileNetv3 network to replace the CSPDarknet53 network in the original model YOLOv4, which can reduce the number of parameters and reduce the amount of calculation without causing loss of accuracy; and further introduces deep separable convolution and inception network structures in the detector to broaden the network width and depth, and on the premise of ensuring the recognition accuracy, the detection speed is faster and the real-time performance is stronger. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 A flow chart of a method for detecting daily behavior of group-raised pigs based on the YOLOv4 model provided in an embodiment of the present invention.

[0039] Figure 2 It is a schematic diagram of the overall network structure of YOLOv4 in the related technology.

[0040] Figure 3a Schematic diagram of CSP structure in related technology.

[0041] Figure 3b Schematic diagram of the spatial pyramid pooling (SPP) module structure in the related technology.

[0042] Figure 3c Schematic diagram of PANet structure in related technology.

[0043] Figure 4 A diagram showing the relationship between a preset box and a predicted bounding box in the related art.

[0044] Figure 5 This is the bneck structure diagram of MobileNetV3 in the related technology.

[0045] Figure 6 This is a structural diagram of the improved YOLOv4 network model provided by an embodiment of the present invention.

[0046] Figure 7a This is a traditional convolution structure diagram in the prior art.

[0047] Figure 7b An improved depthwise separable convolution structure diagram provided for an embodiment of the present invention.

[0048] Figure 8a A structural diagram of an improved CBL_block1 provided in an embodiment of the present invention.

[0049] Figure 8b A structural diagram of an improved CBL_block2 provided in an embodiment of the present invention.

[0050] Figure 9a This is the original inception structure diagram in the prior art.

[0051] Figure 9b This is a diagram of the improved inception structure provided by an embodiment of the present invention.

[0052] Fig.10a The overall improved Mini_YOLOv4 network structure diagram provided by the embodiment of the present invention.

[0053] Fig.10b A schematic diagram of the definitions of five types of daily behaviors of pigs provided in an embodiment of the present invention.

[0054] Fig.11a A schematic diagram of Mosaic data enhancement provided by an embodiment of the present invention.

[0055] Fig.11b This is a diagram of the labeling interface for the pig behavior dataset provided in an embodiment of the present invention.

[0056] Fig.12a This is a diagram of the detection results of the YOLOv4 on the test set provided by an embodiment of the present invention.

[0057] Figure 12bThis is a graph of the detection results of the test set by MobileNetv3_YOLOv4 provided in an embodiment of the present invention.

[0058] Fig.12c This is a graph of the detection results of the Mini_YOLOv4 on the test set provided by an embodiment of the present invention.

[0059] Fig.13a A schematic diagram of a predicted bounding box of YOLOv4 provided in an embodiment of the present invention.

[0060] Fig.13b A schematic diagram of a predicted bounding box of MobileNetv3_YOLOv4 provided in an embodiment of the present invention.

[0061] Fig.13c A schematic diagram of a predicted bounding box of Mini_YOLOv4 provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0062] In order to make the technical means, creative features, objectives and effects achieved by the present invention easy to understand, the present invention is further explained below in conjunction with specific implementation methods.

[0063] In the description of the present invention, it should be noted that the terms "upper", "lower", "inner", "outer", "front end", "rear end", "two ends", "one end", "the other end" and the like indicate positions or positional relationships based on the positions or positional relationships shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance.

[0064] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "provided with", "connected", etc. should be understood in a broad sense. For example, "connected" can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0065] Reference Figure 1 As shown, an embodiment of the present invention provides a method for detecting daily behaviors of group-raised pigs, comprising:

[0066] S1. Acquire images of daily behaviors of group-raised pigs in the target area to be detected;

[0067] S2. Detecting the image by a pre-trained pig behavior detection model; the detection model is obtained by training an improved YOLOv4 network model with multiple sets of training data; each set of the multiple sets of training data includes a target frame of the daily behavior of the pig; the improved YOLOv4 network model adopts a lightweight MobileNetv3 network, and introduces a deep separable convolution and inception network structure in the detector;

[0068] S3. Determine the classification of the daily behavior of the pigs in the image according to the detection result of the detection model.

[0069] This method obtains images of daily behaviors of group-raised pigs in the target area to be detected, and inputs them into the improved YOLOv4 network model for detection, and can obtain the classification of daily behaviors of pigs in the output images. Among them, the improved YOLOv4 network model is: using a lightweight MobileNetv3 network to replace the CSPDarknet53 network in the original model YOLOv4, which can reduce the number of parameters and reduce the amount of calculation without causing loss of accuracy; and further introduces deep separable convolution and inception network structures in the detector to broaden the network width and depth, and on the premise of ensuring recognition accuracy, the detection speed is faster and more real-time.

[0070] The following focuses on the specific description of step S2:

[0071] First, before describing the technical solution of the present invention in detail, the principle of the YOLOv4 algorithm in the related art is introduced:

[0072] 1. YOLOv4 model framework

[0073] The overall network structure of YOLOv4 is as follows Figure 2 As shown in Figure 2, its backbone feature extraction network adopts the network structure of CSPDarknet53, which adds a cross-stage local network structure CSP (Cross Stage Partial) on the basis of Darknet53. The learning ability of the convolutional neural network is enhanced by cross-level splicing and channel integration of the two branches. The CSP structure is as follows: Figure 3a In order to make full use of the up-sampled features in the early feature maps, YOLOv4 introduces the spatial pyramid pooling (SPP) module, which is located at the junction of the backbone feature extraction network and the neck detection network. The specific structure is as follows Figure 3bAs shown in the figure, the feature maps after different pools are concat-operated with the original feature maps to merge and output, which can better increase the receptive field of the feature map compared to the ordinary maximum pooling operation. In the feature fusion network, the path aggregation network (PAN) is used. The PAN network uses a bottom-up path, which shortens the fusion path between the bottom and top layers through lateral connections from the bottom to the top. When YOLOv4 uses PAN, in order to improve the accuracy of prediction, it changes the addition of adjacent layers to a splicing operation. The specific structure is as follows Figure 3c After multiple feature fusions, the three effective feature layers of the network are fully extracted, and the three output feature map sizes are 1 / 8, 1 / 16, and 1 / 32 of the original input size.

[0074] 2. Object Bounding Box Prediction

[0075] The YOLOv4 model uses the K-means method to cluster and select 9 preset boxes as the initial candidate boxes, and assigns them to feature maps of three scales according to the principle of large feature maps and small size boxes. During the detection process, the offset of the network output relative to the preset box is t x ,t y ,t w ,t h . Figure 4 A relationship diagram between the preset box and the predicted bounding box is given, where 1 represents the preset box and 2 represents the predicted bounding box.

[0076] where t x , t y represents the center offset of the predicted bounding box, t w , t h are the width and height scaling ratios of the predicted bounding box, respectively. x ,C y Respectively represent the horizontal and vertical coordinates of the current grid relative to the upper left corner of the feature map, p w ,p h Respectively represent the width and height of the preset box, b x , b y , b w , b h They are the center coordinates of the predicted box and the width and height of the box respectively. The calculation process is as follows:

[0077]

[0078] (1)In the formula, e represents a natural constant and σ represents a sigmoid function.

[0079] 3. MobileNetv3 network

[0080] Mobilenetv3 is a new generation of lightweight deep neural network proposed by Google in 2019. While inheriting the advantages of Mobilenetv1 and Mobilenetv2, it also introduces a lightweight attention model based on SE (squeeze and excitation) according to the Mnas Net model. The model structure considers the relationship between channels to improve network performance, and can explicitly establish the interdependence between channels. It obtains the importance of each channel through learning, and increases the weight of useful features according to the importance of the channel and suppresses features that are not very useful for the current task. At the same time, MobileNetv3 proposes a nonlinear h-swish activation function that can effectively improve network accuracy.

[0081]

[0082] As the network goes deeper, the cost of applying nonlinear activation functions will decrease, which can better reduce the number of parameters. Therefore, in the MobileNetV3 architecture, h-swish (HS) is only used in the second half of the model. In addition, MobileNetV3 uses AvgPooling to replace the part with large computational workload, which reduces the amount of computation without causing loss of accuracy. Figure 5 shown.

[0083] Then, based on the above-mentioned YOLOv4 network model, the present invention is improved. While the YOLOv4 network model improves the detection accuracy, it increases the computational complexity of the network, so it has higher GPU memory and model storage requirements, making it impossible to deploy on embedded platforms and mobile devices. Therefore, the present invention proposes a Mini_YOLOv4 model based on the original YOLOv4 model. The model first changes the feature extraction network of YOLOv4 to the MobileNetv3 network structure, reduces the parameters of the model, and obtains a certain accuracy. Secondly, in order to further lightweight the model, deep separable convolution is used instead of traditional convolution in the CBL_block1 and CBL_block2 modules of the detection network to avoid insufficient memory and high latency caused by complex models. Finally, the last layer of Conv2D 3×3 convolution at each scale of the original YOLOv4 network is changed to the inception network structure to improve the accuracy of the model in pig behavior detection.

[0084] The improvements involved are the feature extraction network and the detection network, as follows:

[0085] 1) Feature extraction network

[0086] In order to realize the lightweight and miniaturization of the pig daily behavior recognition model, the present invention uses the MobileNetV3 network as the backbone feature extraction network to replace the original CSPDarkNet-53 network in YOLOv4 to reduce the overall computational complexity and memory usage of the network. The improved network structure is as follows Figure 6 Exp size is the expansion factor, SE indicates whether to use the SE module,

[0087] NL is the activation function, HS is the activation using the Hard-Swish function, RE is the activation using the ReLU function, and Bneck is the botteleneck structure of MobileNetv3. This paper abandons the convolutional layer and pooling layer network behind MobileNetv3, and retains the Bneck structure of the network for feature extraction, including the SE module, so that the network has a primary and secondary learning of the features of each layer. At the same time, refer to CSPDarknet-53 to extract feature maps of different scales, and extract them in the 7th, 13th, and 16th layers of Bneck respectively. Based on the idea of ​​multi-scale prediction, richer semantic information and more fine-grained feature information can be obtained in the process of daily behavior recognition of pigs.

[0088] 2) Detection network

[0089] 2.1) Lightweight Detection Network

[0090] In order to further reduce the weight of the network model and improve the real-time performance of the algorithm, the present invention introduces a depth-separable convolution to replace the traditional convolution in the detection network, reducing the model's requirements for GPU memory and model storage. Figure 7a As shown, in the deep separable network, the convolution operation can be divided into two steps, such as Figure 7b Assume that the size of the convolution kernel is D k ×D k , the input feature map size is D F ×D F , M and N represent the number of input and output channels. The total amount of computation of traditional convolution is F1, and the total amount of computation of depthwise separable convolution is F2. The ratio of the computational amount between the two, F2 / F1, can be described by formula (3).

[0091]

[0092] The CBL_block1 before and after the original SPP structure, which contains 2 1×1 convolutional layers and 1 3×3 convolutional layer, and the CBL_block2 structure immediately following the concat operation in the PANet network, which includes 3 1×1 convolutional layers and 2 3×3 convolutional layers. Drawing on the idea of ​​depthwise separable convolution, this invention will use 1×1 point convolution and 3×3 depthwise convolution to replace the original 3×3 traditional convolution, and use the nonlinear h-swish function that has better effect in deep models as the activation function to replace the Leaky ReLU function used in the original detection network. The specific improvements are as follows: Figure 8a-8b Compared with the original detection network, the improved detection network not only speeds up the calculation, but also further increases the network depth and increases the nonlinearity of the network.

[0093] 2.2) Introducing the Inception network structure

[0094] Because the actual pig farm environment is different from the outdoor environment, there will be partition walls, fences, and other infrastructure, and pigs are non-rigid deformable individuals, there are body occlusions in the images collected by video surveillance, and the difference between pig behavior characteristics is not large. In order to further improve the accuracy of pig daily behavior detection, the inception structure is integrated into the YOLOv4 network to broaden the width of the neural network and improve the algorithm performance.

[0095] The Inception network structure maintains good computing performance while maintaining network sparsity, such as Figure 9a As shown in the figure, different convolution kernels of different sizes are used in the structure to correspond to different perception fields of view, and finally feature fusion is performed through the Concat operation to capture more target information. The present invention replaces the last 3×3 convolution of each detection size in the original network layer of YOLOv4 with an improved inception module. The structure is as follows: Figure 9b shown.

[0096] First, the convolution kernel (5×5) in the original structure is replaced by two (1×3) and (3×1) convolution kernels to improve the calculation speed; since the network is deeper at this time, the average pooling that can retain more overall data features is used to replace the maximum pooling of the original structure; batch normalization operations are used after each convolution layer to improve the robustness of the algorithm; at the same time, the number of feature maps in each layer of the inception network is reduced, but the total number of feature maps is kept the same as the total number of feature maps output by YOLOv4. Based on the above improvements, the training and testing performance of the algorithm is comprehensively improved. Fig.10a This is the overall improved Mini_YOLOv4 network structure.

[0097] In one embodiment, the training steps of the improved YOLOv4 network model include:

[0098] S21, collecting images of live pigs at different time periods and angles in the actual scene of the pig farm through monitoring cameras;

[0099] S22, processing the pig images and dividing them into a training set, a verification set and a test set according to a preset ratio;

[0100] S23. Improve the YOLOv4 network model by using a lightweight MobileNetv3 network and introducing deep separable convolution and inception network structures into the detector to obtain an improved YOLOv4 network model.

[0101] S24, using the processed pig images included in the training set to perform iterative optimization training on the improved YOLOv4 network model;

[0102] S25. When the preset conditions are met, the training is terminated to obtain a trained pig behavior detection model.

[0103] Among them, the data collection in step S21, for example, the behavioral samples of this experiment are from the Jinghuimeng Pig Farm in Mengcheng, Anhui Province, and the Logitech C920 Pro camera is used as a real-time collection tool. The pen where the camera is installed in the experiment has sufficient lighting. The behavior of pigs in the actual scene is random, and the experimental collection device can remotely control the rotation of the camera, so that the collected sample images have the daily behavior information of pigs from different angles. Data from different time periods are collected multiple times, with a duration of 1-2 hours. The resolution of the collected sample images is 1920 pixels × 1080 pixels, which is used for training and testing of network models. Due to different shooting angles, the information contained in the individual behaviors of pigs varies greatly. For example, the daily behaviors of pigs are finally labeled into 5 categories: standing, sitting, prone, lying on the belly, and lying on the side. The detailed labeling principles for each type of behavior are as follows Fig.10b shown.

[0104] In step S22, the collected video data is subjected to the following operations to construct a pig behavior data detection dataset. For example, the original dataset of 1656 images is subjected to mirror flipping, random flipping, etc. to generate 6624 samples. For example, the ratio of the training set, validation set, and test set is set to 8:1:1.

[0105] a) To ensure the continuity of the collected sample images and to identify whether individual pigs maintain the same behavior for a long time, the sampling interval of the experimental collection device is set to 20s. If the interval is too short, the similarity between the collected sample images will be too high or even the images will be almost repeated. The collected images are screened. In order to increase the richness of the model training data, the selected samples include samples of different time periods, different light intensities and different shooting angles, and the sample size is uniformly adjusted to 416 pixels × 416 pixels to reduce the amount of calculation and increase the speed of model training.

[0106] b) In order to avoid overfitting of the model during training, the Mosaic data augmentation method is used to increase the diversity of samples. Four images are read each time, and each image is horizontally flipped, randomly cropped, and the color gamut is changed, and then spliced ​​into one image. Fig.11a As shown, the background of the detected target can be greatly enriched.

[0107] c) Use the labelImg image annotation tool to manually label the daily behaviors of the pigs and assign label names, such as Fig.11b The annotation used is an XML file in PASCAL VOC format that contains information such as the size of the sample image and the coordinates of the upper left and lower right corners of the sample box.

[0108] In step S23, the YOLOv4 network model is improved by adopting a lightweight MobileNetv3 network, and introducing a deep separable convolution and inception network structure in the detector to obtain an improved YOLOv4 network model; for details, reference may be made to the description of the improved YOLOv4 network model in the above embodiment.

[0109] In step S24-25, the training process, for example, the experimental platform uses 16G memory, NVIDIA GeForce RTX2080Ti model GPU, Interi7 9700F 3.0GHz, 16G memory model CPU, Python version number is 3.7, and the selected deep learning framework is Tensorflow, version 2.2.0 to implement this algorithm. Cuda10.1 and cudnn7.6.5 are installed to help GPU accelerate computing, and a series of third-party libraries such as opencv3.4 are installed to support the operation of the code.

[0110] Model training method: For example, the input image size of network training is uniformly set to 416 pixels × 416 pixels. In order to enhance the anti-interference ability of the model, Mosaic data enhancement is used during training. The experiment is mainly divided into two stages: frozen training and full network training. The improved Mini_YOLOv4 algorithm and the YOLOv4 algorithm are different in the number of convolutional layers and the number of parameters. Due to insufficient local video memory, the batch size is set to 16 and 32 respectively during frozen training for the YOLOv4 model and the Mini_YOLOv4 model, and the batch size is set to 4 and 16 respectively during full network training. The initial learning rate is set to 0.001 and the minimum learning rate is set to 0.000001. The simulated cosine annealing strategy is used to adjust the learning rate of the network. At the same time, the intra-group label smoothing method is used to optimize the label class. The early stop value is set to 6, that is, the network training is terminated if the val_loss value does not decrease for 6 consecutive times.

[0111] The loss function of the model is divided into three parts: coordinate position loss L loc Using CIOU (complete intersection over union) error, confidence loss L conf and the class loss L cls The binary cross entropy function is used. The total loss function can be expressed as formula (4).

[0112] total_loss = L loc +L conf +L cls (4)

[0113]

[0114]

[0115]

[0116] In formulas (5)-(7), s 2 represents the number of grids; B represents the number of prior boxes in each grid; IOU(A,B) represents the intersection-over-union ratio of the predicted box and the true box; ρ(A ctr ,B ctr ) represents the Euclidean distance between the center points of the predicted box and the true box; m represents the diagonal distance of the smallest enclosed area that contains both the predicted box and the true box; w gt and h gt represents the width and height of the real box; w and h represent the width and height of the predicted box; Indicates whether the jth bounding box of the i-th grid cell contains the target, which is 1 or 0 respectively; Indicates whether the jth bounding box of the i-th grid cell does not contain the target, which is 0 or 1 respectively; represents the prediction confidence, represents the true confidence, λ noobj represents the weight coefficient; c represents the category, represents the probability that the target in the cell belongs to category c, Represents the predicted probability.

[0117] In order to shorten the training time and speed up the iterative convergence of the network, the experiment downloaded the pre-trained model parameters of the model on the PASCAL VOC2007 dataset as the initial parameters. After about 100 epochs, the network loss value gradually stabilized and the training tended to converge.

[0118] In one embodiment, the present invention will evaluate the Mini_YOLOv4 model trained in the above embodiment, and will use the average detection precision mAP, recall, FPS and model weight recognized in the field of target detection as evaluation criteria to measure the model's performance in detecting the daily behavior of pigs. Precision, Recall, AP and mAP are defined as in formula (8).

[0119]

[0120] TP represents the number of samples predicted by the model to be positive but actually are positive; FP represents the number of samples predicted by the model to be positive but actually are negative; FN represents the number of samples predicted by the model to be negative but actually are positive; P and R represent precision and recall respectively; C represents the total number of behavior categories; C i Indicates the current i-th category, where i ranges from 1 to 5.

[0121] In order to evaluate the performance of the improved algorithm of the present invention, the Mini_YOLOv4 algorithm proposed in the present invention is compared with the original YOLOv4 algorithm and the Mobilev3_YOLOv4 algorithm in various aspects. The algorithm comparison experiments all use the same experimental platform, the same training set and the same test set.

[0122] Table 1 Comparison of network parameters, weight files and training time

[0123]

[0124] First, it can be seen from Table 1 that the Mini_YOLOv4 algorithm has a significant improvement in parameter quantity and model size compared to the original YOLOv4 algorithm, accounting for only about 1 / 4 of the original algorithm. At the same time, on the same experimental platform, the algorithm of the present invention is only 1 / 2 of the original YOLOv4 algorithm in terms of training time. This is because the original YOLOv4 model has a large number of parameters. When performing full network training, due to the limited memory space of the local experimental platform, the batich_size value can only be set to 4, so the training time is long under the same hardware conditions. Only from the perspective of model size and parameter quantity, the Mini_YOLOv4 algorithm proposed in the present invention can meet the detection requirements of embedded mobile terminals.

[0125] In order to further evaluate the algorithm performance and verify the detection effect of the algorithm of the present invention on the pig behavior data set, the pig behavior test set was tested by calling the model weight file saved during the training process. Some of the test results are shown in Figure 2. Fig.12a , 12b , as shown in 12c. Fig.12a , 12b and 12c, the three models can correctly predict the pig behavior category, but the original YOLOv4 algorithm fails to filter out the bounding box with more accurate positioning, while the improved version successfully filters out the optimal box in pig behavior detection, which improves the false detection problem of the original YOLOv4 to a certain extent.

[0126] At the same time, the improved algorithm is compared with the YOLOv4 target detection algorithm for each category of pig behavior in terms of AP value, F1 value and recall rate. Table 2-4 gives the comparison results of different indicators of the three models when the IOU threshold is 0.5 and the target classification probability is ≥ 0.5. From the analysis of the data in the table, it can be seen that the mAP of the Mini_YOLOv4 algorithm can reach 73.67%, which is 4.01 percentage points higher than that of the original YOLOv4 algorithm, and the detection effect in each category is better than that of the original YOLOv4 algorithm. In terms of detection speed, compared with the original YOLOv4 algorithm, the algorithm proposed in the present invention has nearly doubled the FPS value. In terms of the F1 index, the F1 value of the algorithm of the present invention in each category is higher than that of the original YOLOv4 algorithm. In terms of the recall rate index, the algorithm of the present invention is higher than YOLOv4 in all categories except the side-lying category, which is lower than the YOLOv4 algorithm. From the comparative analysis of the above indicators, it can be concluded that the improvement method proposed in the present invention is an effective improvement on the pig behavior dataset.

[0127] Table 2 Comparison of detection accuracy and speed of models

[0128]

[0129]

[0130] Table 3 Comparison of recall rates of models

[0131]

[0132] Table 4 Comparison of F1 values ​​of models

[0133]

[0134] In order to comprehensively evaluate the performance of the algorithm of the present invention on the pig behavior dataset, the present invention sets a comparison of the mAP values ​​of the three algorithms when the classification probability threshold is 0.5 and the IOU thresholds are 0.5, 0.6, 0.7, and 0.75 respectively. The comparison results are shown in Table 5.

[0135] Table 5 Comparison of detection accuracy under different IOU thresholds

[0136]

[0137] From the data in Table 5 above, it can be seen that as the IOU threshold increases, the accuracy advantage of the algorithm of the present invention over the original YOLOv4 becomes more and more obvious. A good mAP value can still be maintained at a higher IOU threshold, which means that the overlap between the real box and the predicted box obtained by the algorithm of the present invention is higher, that is, the target positioning is more accurate. Fig.13a , 13b As can be seen from Figure 13c, the predicted bounding box generated by the Mini_YOLOv4 model proposed in the present invention is more accurate than the one generated by the YOLOv4 model, and the former can better include the detected target object in the detection frame.

[0138] The present invention uses MobileNet_v3 network as a feature extraction network to replace CSPDarknet53, obtains the detection model Mobile_YOLOv4, introduces deep separable convolution into the detection network of the model, and finally adds an improved inception module to the tail of the model, proposes a new detection model Mini_YOLOv4, and applies it to pig behavior recognition. When the classification probability threshold is set to ≥ 0.5 on the daily behavior data set of pigs, and the IoU threshold is 0.5, the average precision of the Mini_YOLOv4 model is 73.67%, and the detection speed is 65 frames / s. Compared with the original YOLOv4 model, its average precision is 4.01% higher than that of the YOLOv4 model, and the detection speed is increased by 32 frames / s. It shows that the demand for the embedded mobile terminal of the Mini_YOLOv4 model proposed by the present invention, that is, while ensuring the detection accuracy, it has good real-time performance, and provides a feasible technical solution for embedded edge computing.

[0139] The above shows and describes the basic principles and main features of the present invention and the advantages of the present invention. It should be understood by those skilled in the art that the present invention is not limited to the above embodiments. The above embodiments and descriptions are only for explaining the principles of the present invention. Without departing from the spirit and scope of the present invention, the present invention may have various changes and improvements, which fall within the scope of the present invention to be protected. The scope of protection of the present invention is defined by the attached claims and their equivalents.

Claims

1. A method for detecting daily behavior of group-raised pigs, characterized in that: include: S1. Acquire images of daily behaviors of group-raised pigs in the target area to be detected; S2. Detecting the image by a pre-trained pig behavior detection model; the detection model is obtained by training an improved YOLOv4 network model with multiple sets of training data; each set of the multiple sets of training data includes a target frame of the daily behavior of the pig; the improved YOLOv4 network model adopts a lightweight MobileNetv3 network, and introduces a deep separable convolution and inception network structure in the detector; S3. Determine the classification of the daily behavior of the pigs in the image according to the detection result of the detection model; The training steps of the improved YOLOv4 network model include: The surveillance cameras are used to collect images of live pigs at different times and angles in the actual scene of the pig farm; Processing the pig images and dividing them into a training set, a validation set and a test set according to a preset ratio; The YOLOv4 network model is improved by using a lightweight MobileNetv3 network and introducing deep separable convolution and inception network structures into the detector to obtain an improved YOLOv4 network model. Using the processed pig images included in the training set, performing iterative optimization training on the improved YOLOv4 network model; When the preset conditions are met, the training is terminated to obtain a trained pig behavior detection model; the loss function of the trained pig behavior detection model is: total_loss=L loc +L conf +L cls (4) (4) In the formula, L loc Indicates the coordinate position loss, using CIOU error; L conf represents the confidence loss; L cls Represents category loss, using binary cross entropy function; In formulas (5)-(7), s 2 represents the number of grids; B represents the number of prior boxes in each grid; IOU(A,B) represents the intersection-over-union ratio of the predicted box and the true box; ρ(A ctr ,B ctr ) represents the Euclidean distance between the center points of the predicted box and the true box; m represents the diagonal distance of the smallest enclosed area that contains both the predicted box and the true box; w gt and h gt represents the width and height of the real box; w and h represent the width and height of the predicted box; Indicates whether the jth bounding box of the i-th grid cell contains the target, which is 1 or 0 respectively; Indicates whether the jth bounding box of the i-th grid cell does not contain the target, which is 0 or 1 respectively; represents the prediction confidence, represents the true confidence, λ noobj represents the weight coefficient; c represents the category, represents the probability that the target in the cell belongs to category c, represents the predicted probability.

2. A method for detecting daily behavior of group-raised pigs according to claim 1, characterized in that: The improved YOLOv4 network model uses a lightweight MobileNetv3 network, including: The improved YOLOv4 network model uses a lightweight MobileNetv3 network, deletes the convolutional layer and pooling layer network behind MobileNetv3, and retains the Bneck structure of the network for feature extraction, including the SE module; Feature maps are extracted at the 7th, 13th and 16th layers of Bneck respectively.

3. A method for detecting daily behavior of group-raised pigs according to claim 2, characterized in that: Introducing depthwise separable convolutions in the detector, including: 1×1 point convolution and 3×3 depth convolution will be used to replace the original 3×3 traditional convolution, and the nonlinear h-swish function will be used as the activation function to replace the Leaky ReLU function used in the original detection network.

4. A method for detecting daily behavior of group-raised pigs according to claim 3, characterized in that: Introduce the inception network structure into the detector, including: Use 1×3 and 3×1 convolution kernels to replace the 5×5 convolution kernel in the original structure; Average pooling is used instead of the maximum pooling of the original structure.

5. The method for detecting daily behavior of group-raised pigs according to claim 1, characterized in that: Processing the pig image includes: Set a preset sampling interval to filter the collected pig images. The selected samples include samples of different time periods, different light intensities, and different shooting instructions, and the size is unified; Use Mosaic data augmentation to increase the number of samples; Use the labelImg image annotation tool to annotate the daily behaviors of pig images and assign label names.

Citation Information

Cited By

  • Piglet multi-behavior lightweight identification method based on improved RT-DETR model

    CN122618687A