A lightweight cattle herd detection method and device based on DC-SMKD
By introducing deep separation convolution and smooth multi-layer perceptual knowledge distillation technology into the herd detection model, the problem of degradation of detection accuracy after lightweighting of the model in the existing technology is solved, and efficient and accurate lightweight herd detection is achieved.
Patent Information
- Application Number
- CN202210123784.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-02-10
- Publication Date
- 2025-02-21
- Estimated Expiration
- 2042-02-10
AI Technical Summary
In the prior art, it is difficult to achieve lightweighting of the model without reducing the detection accuracy in cattle herd detection, resulting in a decrease in detection effect.
Using a method based on depth separable convolution-smooth multi-layer perceptual knowledge distillation (DC-SMKD), the model size is reduced by introducing deep separable convolution into the YOLOv5s model, and learning the teacher's model through smooth multi-layer perceptual knowledge distillation Multi-layer feature information to make up for feature loss and improve detection accuracy.
It realizes that the herd detection model is lightened without reducing the detection accuracy, reducing the model size and computing cost, and improving the detection accuracy, especially when dealing with complex features of the cattle body.
Smart Images

Figure CN114494923B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer vision, and in particular to a lightweight cattle herd detection method and device based on Depthwise Separable Convolution-Smooth Multi-layer Perceptual Knowledge Distillation (DC-SMKD). Background Art
[0002] In the prior art, in recent years, the YOLO series of algorithms have brought a new idea to the field of cattle detection, that is, integrating classification tasks and positioning tasks. After the image is extracted through the backbone network, the feature is directly further classified and regressed and the position is positioned, and finally the location information and category information of the object are obtained. Especially the latest YOLOv5 model, it uses an end-to-end design concept to extract full-image features. It not only further reduces the size of the network model, but also ensures the speed and accuracy of detection. However, the size of the YOLOv5 model is still not ideal, and the model can be compressed smaller according to demand. The lightweight model means lower requirements for chip deployment, which greatly reduces the operating cost of cattle farm monitoring. This has a far-reaching impact on transplanting the model to cattle farm monitoring equipment, which can not only save construction costs, but also improve the intelligence level of cattle farm monitoring.
[0003] More and more researchers have begun to study model lightweighting, and a large number of research results have emerged, mainly including low-rank decomposition, model quantization, and knowledge distillation. In order to achieve model lightweighting without reducing the accuracy of the model or slightly reducing the accuracy of the model, low-rank decomposition can be used. In the early development of convolutional neural networks, some researchers used low-rank filters to accelerate convolution. Some researchers borrowed the method of Dictionary Learning and improved a new type of low-rank filter, which has a certain acceleration effect on the detection speed. However, the disadvantages of this method are also obvious. The low-rank decomposition is not performed globally, but layer by layer, which will cause the cow pattern features to be sparse layer by layer. The backbone network cannot extract enough detailed features of the cow body, which will lead to reduced detection effect.
[0004] Some researchers have quantized the parameters of convolutional neural networks to reduce the burden of convolutional neural networks and thus reduce the size of the model. Model parameter quantization is also called low-bit expression. For example, the parameters of the feature maps extracted by the backbone network are all float types. By changing them to low-precision parameter types, the size of the model can be reduced and the model can be lightweight. Researchers use the k-mean method to quantize the parameters that have a large number of redundant parameters in the model. Based on the work of predecessors, some scholars have quantized the float type data in the convolutional network model to 8 bits, which can theoretically reduce the model to one-fourth of the original size. However, the shortcomings of these methods in the cattle herd detection model are obvious. Since the cattle herd model is directly quantized, when processing large convolutional neural networks such as the cattle herd model, the final model will lose more performance than the original model.
[0005] Knowledge distillation refers to training a student model with poor detection effect through the output of the last layer under the supervision of a teacher model with good detection effect, thereby improving the performance of the student model. However, the disadvantages of this method are also obvious. Since the body characteristics of a herd of cattle are relatively complex, if the shallow information of the cattle body characteristics is ignored and the student model is forced to learn only the final deep feature information of the teacher model, it is difficult to obtain the complete characteristics of the cattle body.
[0006] However, these lightweight model methods do not fully capture the characteristics of the cattle body, resulting in reduced effectiveness of the cattle herd detection model. Summary of the invention
[0007] One purpose of the present application is to provide a DC-SMKD-based lightweight cattle herd detection method and device to solve the problem of how to improve the lightweight cattle herd detection model in the prior art so as to obtain complete cattle body characteristics and improve detection accuracy during the cattle herd detection process.
[0008] According to one aspect of the present application, a DC-SMKD-based lightweight cattle herd detection method is provided, comprising:
[0009] Acquire a herd of cattle image, and process the herd of cattle image into a VOC dataset format;
[0010] A student model is obtained by using a deeply separable convolution in the YOLOv5s model. The student model learns the multi-layer feature information output by the teacher model through smooth multi-layer perceptual knowledge distillation to obtain a lightweight cattle herd detection model.
[0011] The processed cattle herd image is input into the lightweight cattle herd detection model to obtain the cattle herd detection result.
[0012] Furthermore, in the above-mentioned lightweight cattle herd detection method, the student model and the teacher model are respectively based on two classic models in the YOLOv5 model, namely the YOLOv5s model and the YOLOv5x model, the YOLOv5 model includes a backbone network layer, a network neck layer and a prediction layer, and the backbone network of the YOLOv5 includes a Focus structure, four DCBLs, three C3s and a spatial pyramid pooling (Spatial Pyramid Pooling, SPP) structure.
[0013] Furthermore, in the above-mentioned lightweight cattle herd detection method, a student model is obtained by using a deeply separable convolution in the YOLOv5s model, and the student model learns the multi-layer feature information output by the teacher model through smooth multi-layer perceptual knowledge distillation to obtain a lightweight cattle herd detection model, including:
[0014] In the backbone network of YOLOv5s, the deep separable convolution DConv is used instead of the standard convolution to obtain the student model;
[0015] The prediction layers in the student model and the teacher model respectively output a student model feature vector and a teacher model feature vector through a softmax function;
[0016] Based on the student model feature vector and the teacher model feature vector, a joint distillation loss function is determined in combination with a smoothing loss function, and a lightweight cattle herd detection model is obtained through continuous iterative training.
[0017] Furthermore, in the above lightweight cattle herd detection method, three student model feature vectors of different sizes are outputted by a softmax function in the prediction layer of the student model;
[0018] In the prediction layer of the teacher model, three teacher model feature vectors of different sizes are output through the softmax function.
[0019] Furthermore, in the above lightweight cattle herd detection method, based on the student model feature vector and the teacher model feature vector, a joint distillation loss function is determined in combination with a smoothing loss function, including:
[0020] After the student model feature vector and the teacher model feature vector are input into the smooth loss function, a smooth multi-layer perception loss function is obtained, and the formula is as follows:
[0021] L S-M =L smooth (P 1s ,P 1t )+L smooth (P 2s ,P 2t )+L smooth (P3s ,P 3t )
[0022] Among them, L smooth represents the smooth loss function, P1 s 、P2 s 、P3 s represents the student model feature vector, P1 t , P2 t , P3 t represents the teacher model feature vector;
[0023] The formula of the joint distillation loss function is as follows:
[0024] L KD =H(y,(P1 s ,P2 s ,P3 s ))+λL S-M
[0025] Among them, λ is the hyperparameter for adjusting the distillation loss, H(·) is the BCEWithLogitsLoss loss function,
[0026] H(y,P(T i ,τ′))=-(ylog(σ(P i (T i ,τ′)))+(1-y)log(1-σ(P i (T i ,τ′))))
[0027] Where y is the true value label, τ′ is the temperature coefficient of the distillation loss, σ(·) is the Sigmoid function, T is the feature vector, and T i Represents the i-th element in T.
[0028] According to another aspect of the present application, a computer-readable medium is provided, on which computer-readable instructions are stored. When the computer-readable instructions are processed and executed, the processor can implement the robot behavior decision method as described above.
[0029] According to another aspect of the present application, a DC-SMKD-based lightweight cattle herd detection device is also provided, the device comprising:
[0030] one or more processors;
[0031] A computer readable medium for storing one or more computer readable instructions,
[0032] When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement the lightweight cattle herd detection method as described above.
[0033] Compared with the prior art, the present application obtains cattle images and processes the cattle images into the VOC dataset format; uses deeply separable convolution in the YOLOv5s model to obtain a student model, and the student model learns the multi-layer feature information output by the teacher model through smoothed multi-layer perceptual knowledge distillation to obtain a lightweight cattle detection model; the processed cattle images are input into the lightweight cattle detection model to obtain cattle detection results, that is, in order to lightweight the model, deeply separable convolution is first introduced into the classic model YOLOv5s to reduce the model size. Since the cattle body pattern information is mostly large block patterns, the classic model YOLOv5s is subjected to deep separable convolution to obtain the student model DC-YOLOv5s. This method will make the cattle body pattern features sparse, resulting in a certain decrease in the model detection accuracy. Then, each layer of features output by the student model DC-YOLOv5s and the teacher model YOLOv5x are subjected to knowledge distillation through SmoothL1Loss, allowing the student model to learn the multi-layer feature information of the teacher model YOLOv5x, which makes up for the feature loss after separable convolution and is conducive to obtaining relatively complete cattle body features in the teacher model, thereby improving the accuracy of cattle herd detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0035] Figure 1 A schematic diagram of a DC-SMKD-based lightweight cattle herd detection method according to one aspect of the present application is shown;
[0036] Figure 2 A schematic diagram of a process for constructing a lightweight cattle herd detection model in a DC-SMKD lightweight cattle herd detection method according to one aspect of the present application is shown;
[0037] Figure 3 A schematic diagram of the network structure of a deep separable convolutional YOLOv5s model based on a DC-SMKD lightweight cattle herd detection method according to one aspect of the present application is shown;
[0038] Figure 4 A schematic diagram showing a smooth multi-layer perception knowledge distillation process based on a DC-SMKD lightweight cattle herd detection method according to one aspect of the present application
[0039] Figure 5 A pair of proportional renderings of lying posture occlusion conditions in a DC-SMKD lightweight cattle detection method according to one aspect of the present application are shown;
[0040] Figure 6A rendering of a lying position occlusion situation in a specific application scenario of a DC-SMKD lightweight cattle detection method according to one aspect of the present application is shown;
[0041] Figure 7 A pair of proportional standing posture occlusion effect diagrams of a DC-SMKD lightweight cattle herd detection method according to one aspect of the present application are shown;
[0042] Figure 8 A DC-SMKD lightweight cattle detection method according to one aspect of the present application is shown in a standing posture occlusion effect diagram of a specific application scenario;
[0043] Fig. 9 A pair of proportional edge occlusion effect diagrams of a DC-SMKD lightweight cattle herd detection method according to one aspect of the present application are shown;
[0044] Fig.10 A rendering of an edge occlusion situation in a specific application scenario of a DC-SMKD lightweight cattle herd detection method according to one aspect of the present application is shown.
[0045] The same or similar reference numerals in the drawings represent the same or similar components. DETAILED DESCRIPTION
[0046] The present application is described in further detail below in conjunction with the accompanying drawings.
[0047] In a typical configuration of the present application, the terminal, the device of the service network and the trusted party all include one or more processors (such as a central processing unit (CPU), an input / output interface, a network interface and a memory.
[0048] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0049] Computer readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer readable instructions, data structures, modules of programs or other data. Examples of computer storage media include, but are not limited to, Phase-Change RAM (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of random access memory (RAM), Read-Only Memory (ROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Flash memory or other memory technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disk (DVD) or other optical storage, magnetic cassettes, tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. According to the definition in this article, computer-readable media does not include non-transitory media such as modulated data signals and carrier waves.
[0050] Figure 1 A schematic flow chart of a DC-SMKD lightweight cattle herd detection method according to one aspect of the present application is shown. The method is applicable to various livestock detection intelligent management, which may be but is not limited to cattle herd detection intelligent management. The method includes step S11, step S12 and step S13, which specifically include:
[0051] Step S11, obtaining cattle images, and processing the cattle images into a VOC dataset format.
[0052] Step S12, using deeply separable convolution in the YOLOv5s model to obtain a student model, wherein the student model learns the multi-layer feature information output by the teacher model through smooth multi-layer perception knowledge distillation to obtain a lightweight cattle herd detection model.
[0053] Step S13, inputting the processed cattle herd image into the lightweight cattle herd detection model to obtain a cattle herd detection result.
[0054] In the above steps S1 to S3, by acquiring a cattle image, the cattle image is processed into a VOC dataset format; a student model is obtained by using a deeply separable convolution in the YOLOv5s model, and the student model learns the multi-layer feature information output by the teacher model through smooth multi-layer perceptual knowledge distillation to obtain a lightweight cattle detection model; the cattle image is input into the lightweight cattle detection model to obtain a cattle detection result, that is, in order to lightweight the model, firstly, a deeply separable convolution is introduced into the classic model YOLOv5s to reduce the model size. Since the cattle body pattern information is mostly large block patterns, the classic model YOLOv5s is subjected to deep separable convolution to obtain the student model DC-YOLOv5s. This method will make the cattle body pattern features sparse, resulting in a certain decrease in the model detection accuracy. Then, each layer of features output by the student model DC-YOLOv5s and the teacher model YOLOv5x are subjected to knowledge distillation through SmoothL1Loss, allowing the student model to learn the multi-layer feature information of the teacher model YOLOv5x, which makes up for the feature loss after separable convolution and is conducive to obtaining relatively complete cattle body features in the teacher model, thereby improving the accuracy of cattle herd detection.
[0055] For example, first, a camera is set up at the top of the cattle farm to shoot downwards to capture a herd of cattle images F, and the herd image F is processed into a VOC dataset grid. Then, a lightweight herd detection model is constructed, such as Figure 2 As shown. In the YOLOv5s model, the student model DC-YOLOv5s is obtained by using the deep separable convolution. The specific method can be to divide the standard convolution into two steps. In the first step, assuming that the number of channels of the input image is C, in the convolution process, convolution is performed with a single-channel convolution kernel on each channel to obtain an output image with a channel number of C; in the second step, the output image is convolved with a point convolution kernel of size 1×1×C to obtain a single-channel output image, and channel expansion is achieved by controlling the number of such point convolution kernels. Then, the student model DC-YOLOv5s learns the multi-layer feature information output by the teacher model YOLOv5x through smooth multi-layer perceptual knowledge distillation to obtain a lightweight cattle herd detection model DC-SMKD-YOLOv5s. Finally, the cattle herd image F is input into the lightweight cattle herd detection model to obtain the cattle herd detection result, and the number of cattle on the cattle herd image F and the position of each cattle are clearly determined, thereby improving the accuracy of cattle herd detection and avoiding missed detection.
[0056] Following the above embodiment, the student model and the teacher model are respectively based on two classic models in the YOLOv5 model, namely the YOLOv5s model and the YOLOv5x model. The YOLOv5 model includes a backbone network layer, a network neck layer and a prediction layer. The backbone network of the YOLOv5 includes a Focus structure, four DCBLs, three C3s and one SPP structure. Figure 3 shown.
[0057] Here, the difference between the YOLOv5s model and the YOLOv5x model is that the depth and width of the convolution layer in the backbone network are different; DCBL is composed of DConv, batch normalization (BN), and activation function LReLU; C3 is a cross-stage local network structure, which is also the basic structure in the backbone network, which can well solve the problem of gradient information duplication in network optimization in the backbone network; the Focus structure is to avoid the loss of cattle body feature information during feature downsampling, so as to extract more sufficient cattle body features when using convolution operations. The role of the Focus structure in the model is to segment the image before the cattle image enters the backbone network, in order to improve the feature extraction speed. The segmentation method is as follows: first, sample every other pixel of the image, splice these pixels to form an image with lower resolution and smaller size than the original image. This method can obtain four such small images, and splice these small images in the channel direction to obtain an image with increased channel number and smaller size. This image has no feature loss because no pixel is discarded. Finally, the image is sent to the convolution layer of the backbone network. The network neck is located between the backbone network and the prediction layer. Its purpose is to further enrich the diversity of the cow body features in order to improve the stability of the model. YOLOv5 introduces the pixel aggregation network (PAN) structure to fuse the cow body features based on the feature pyramid network (FPN); FPN is from top to bottom, and the deep cow body features are fused with the bottom cow body features through upsampling to obtain the predicted cow body feature map, but this operation is only to pass the high-level strong semantic cow body features downward. Although it enhances the model's learning ability for cow body features, it may lose some positioning features. For this reason, PAN is added after FPN to convey strong positioning cow body features in the opposite order of FPN. Due to the existence of these two modules, the parameters of different detection layers are fused from different backbone layers, which can comprehensively improve the robustness and learning performance of the cattle detection model.
[0058] Following the above embodiment, Figure 4As shown, a student model is obtained by using a deeply separable convolution in the YOLOv5s model. The student model learns the multi-layer feature information output by the teacher model through smooth multi-layer perceptual knowledge distillation to obtain a lightweight cattle herd detection model, including:
[0059] In the backbone network of YOLOv5s, the deep separable convolution DConv is used instead of the standard convolution to obtain the student model DC-YOLOv5s;
[0060] The prediction layers in the student model DC-YOLOv5s and the teacher model YOLOv5x respectively output the student model feature vector and the teacher model feature vector through the softmax function; here, it is assumed that the feature vector in the Prediction layer that has not been subjected to the softmax function is T i , after the softmax layer, we get P i :
[0061]
[0062] Among them, τ represents the distillation temperature. The higher the temperature coefficient, the more average the probability distribution will be after softmax, which is not conducive to target classification. In general, the value of τ is 1; the feature vector is T, T i Represents the i-th element in T.
[0063] Based on the student model feature vector and the teacher model feature vector, the joint distillation loss function is determined in combination with the smooth loss function, and a lightweight cattle herd detection model is obtained through continuous iterative training. The existing knowledge distillation is to use the final output result of the student model network structure to learn the output result of the last layer of the teacher model network structure. The smooth multi-layer perception knowledge distillation in this application is: let the student model learn the features of each layer output by the teacher model and then perform knowledge distillation through SmoothL1Loss (smooth loss), so that the student model learns the multi-layer feature information of the teacher model and obtains a relatively complete cattle body feature. The purpose of using smooth loss is to avoid gradient explosion and improve the generalization ability of the model.
[0064] For example, obtain and create a cattle detection dataset, and divide it into a training set and a test set. There are 100 cows in the cattle farm. The captured images are annotated with a size of 1280*720, and each image is annotated with about 5 cows. A total of 1200 images of cattle targets are annotated, of which 900 annotated images are used as training sets and 300 annotated images are used as test sets, and all images are made into a VOC dataset format. First, in the backbone network of YOLOv5s, the deeply separable convolution DConv is used instead of the standard convolution to obtain the student model DC-YOLOv5s; then, the prediction layers in the student model DC-YOLOv5s and the teacher model YOLOv5x output the student model feature vector and the teacher model feature vector respectively through the softmax function. Finally, based on the student model feature vector and the teacher model feature vector, the joint distillation loss function is determined in combination with the smooth loss function, and the lightweight cattle detection model DC-SMKD-YOLOv5s is obtained through iterative training of the cattle detection data set, which not only realizes the lightweight of the model, but also ensures the accuracy of cattle detection. DC-YOLOv5s uses separable convolution, which reduces the number of parameters of cattle body features, resulting in reduced detection performance. Smooth multi-layer perceptual knowledge distillation is then used to restore the detection performance. The cattle body features of multiple channels in DC-SMKD-YOLOv5s are restored, thereby improving the detection accuracy.
[0065] Following the above embodiment, in the prediction layer of the student model, three student model feature vectors of different sizes are output by the softmax function; in the prediction layer of the teacher model, three teacher model feature vectors of different sizes are output by the softmax function, such as Figure 4 shown.
[0066] Following the above embodiment, based on the student model feature vector and the teacher model feature vector, a joint distillation loss function is determined in combination with a smoothing loss function, including:
[0067] After the student model feature vector and the teacher model feature vector are input into the smooth loss function, a smooth multi-layer perception loss function is obtained, and the formula is as follows:
[0068] L S-M =L smooth (P 1s ,P 1t )+L smooth (P 2s ,P 2t )+L smooth (P 3s ,P 3t )
[0069] Among them, L smoothrepresents the smooth loss function, P1 s 、P2 s 、P3 s represents the student model feature vector, P1 t , P2 t , P3 t represents the teacher model feature vector;
[0070] The formula of the joint distillation loss function is as follows:
[0071] L KD =H(y,(P1 s ,P2 s ,P3 s ))+λL S-M
[0072] Among them, λ is the hyperparameter for adjusting the distillation loss, H(·) is the BCEWithLogitsLoss loss function,
[0073] H(y,P(T i ,τ′))=-(ylog(σ(P i (T i ,τ′)))+(1-y)log(1-σ(P i (T i ,τ′))))
[0074] Where y is the true value label, τ′ is the temperature coefficient of the distillation loss, σ(·) is the Sigmoid function, T is the feature vector, and T i Represents the i-th element in T. The student model is enabled to learn the multi-layer feature information output by the teacher model, making up for the loss of features caused by the use of deeply separable convolution, thereby improving the accuracy of cattle herd detection.
[0075] In the test comparison of this application, the confidence of the cow is set to 0.50, the IOU threshold is set to 0.45, and DC-YOLOv5s and DC-SMKD-YOLOv5s are used to test the effect of different cow occlusion conditions in the image. The detection effect is as follows Figure 5 , Figure 6 , Figure 7 , Figure 8 , Fig. 9 and Fig.10 shown. Figure 5 , 7 , 9 are images tested by DC-YOLOv5s, Figure 6 , 8 , 10 are images tested by DC-SMKD-YOLOv5s. It can be seen that in the case of lying occlusion, Figure 5 The cow pointed by the middle arrow was not detected. Figure 6 The cow pointed by the middle arrow is detected, and Figure 6 The confidence of cattle in the Figure 5 ; In the case of standing occlusion, Figure 8 The cow pointed by the arrow in the middle is detected. Figure 7 was not detected, and Figure 8 The confidence of cattle in the Figure 7 ; In the case of edge occlusion, Fig.10 The cow pointed by the arrow in the middle is detected. Fig. 9 was not detected, and Fig.10 The confidence of cattle in the Fig. 9 From the above test results, it can be seen that after the separable convolution reduces the model size and accuracy, the SMKD algorithm of this application can effectively restore the detection accuracy of the model.
[0076] In addition, in the Linux environment, the IOU threshold is set to 0.80, the confidence threshold is set to 0.50, and the cattle are tested using YOLO5x, YOLOv5s, DC-YOLOv5s, SSD, and DC-KD-YOLOv5s. The AP data set is 780 labeled cattle images. The frame rate is obtained by averaging the same image 1000 times in a loop. In the experimental results, the size of the DC-SMKD-YOLOv5s model used in this application is significantly reduced, and the AP value is greatly improved, with the best overall performance.
[0077] According to another aspect of the present application, a computer-readable medium is provided, on which computer-readable instructions are stored. The computer-readable instructions can be executed by a processor to enable the processor to implement the above-mentioned method for controlling user confrontation.
[0078] According to another aspect of the present application, a DC-SMKD-based lightweight cattle herd detection device is also provided, the device comprising:
[0079] one or more processors;
[0080] a computer-readable medium for storing one or more computer-readable instructions;
[0081] When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement the above-mentioned method for controlling user confrontation on a device.
[0082] Here, for the detailed contents of each embodiment of the device, please refer to the corresponding part of the embodiment of the method for controlling user confrontation on the device side mentioned above, which will not be repeated here.
[0083] In summary, the present application obtains cattle images and processes the cattle images into the VOC dataset format; uses deeply separable convolution in the YOLOv5s model to obtain a student model, and the student model learns the multi-layer feature information output by the teacher model through smoothed multi-layer perceptual knowledge distillation to obtain a lightweight cattle detection model; the cattle images are input into the lightweight cattle detection model to obtain cattle detection results, that is, in order to lightweight the model, deeply separable convolution is first introduced into the classic model YOLOv5s to reduce the model size. Since the cattle body pattern information is mostly large block patterns, the classic model YOLOv5s is subjected to deep separable convolution to obtain the student model DC-YOLOv5s. This method will make the cattle body pattern features sparse, resulting in a certain decrease in the model detection accuracy. Then, each layer of features output by the student model DC-YOLOv5s and the teacher model YOLOv5x are subjected to knowledge distillation through SmoothL1Loss, allowing the student model to learn the multi-layer feature information of the teacher model YOLOv5x, which makes up for the feature loss after separable convolution and is conducive to obtaining relatively complete cattle body features in the teacher model, thereby improving the accuracy of cattle herd detection.
[0084] It should be noted that the present application can be implemented in software and / or a combination of software and hardware, for example, can be implemented using an application specific integrated circuit (ASIC), a general purpose computer or any other similar hardware device. In one embodiment, the software program of the present application can be executed by a processor to implement the steps or functions described above. Similarly, the software program of the present application (including relevant data structures) can be stored in a computer-readable recording medium, for example, a RAM memory, a magnetic or optical drive or a floppy disk and similar devices. In addition, some steps or functions of the present application can be implemented using hardware, for example, as a circuit that cooperates with a processor to perform each step or function.
[0085] In addition, a part of the present application may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present application through the operation of the computer. The program instruction for calling the method of the present application may be stored in a fixed or removable recording medium, and / or transmitted through a data stream in a broadcast or other signal-bearing medium, and / or stored in a working memory of a computer device that runs according to the program instruction. Here, according to an embodiment of the present application, a device is included, the device including a memory for storing computer program instructions and a processor for executing program instructions, wherein, when the computer program instruction is executed by the processor, the device is triggered to run the method and / or technical solution based on the aforementioned multiple embodiments according to the present application.
[0086] It is obvious to those skilled in the art that the present application is not limited to the details of the above exemplary embodiments, and that the present application can be implemented in other specific forms without departing from the spirit or basic features of the present application. Therefore, from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the present application is limited by the attached claims rather than the above description, so it is intended to include all changes that fall within the meaning and scope of the equivalent elements of the claims in the present application. Any figure mark in the claims should not be regarded as limiting the claims involved. In addition, it is obvious that the word "comprising" does not exclude other units or steps, and the singular does not exclude the plural. Multiple units or devices stated in the device claim can also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to indicate names, and do not indicate any particular order.
Claims
1. A DC-SMKD-based lightweight cattle herd detection method, characterized in that: The method comprises: Acquire a herd of cattle image, and process the herd of cattle image into a VOC dataset format; The student model is obtained by using the deeply separable convolution in the YOLOv5s model. The student model learns the multi-layer feature information output by the teacher model through the smooth multi-layer perception knowledge distillation to obtain a lightweight cattle detection model, including: In the backbone network of YOLOv5s, a deeply separable convolution DConv is used instead of a standard convolution to obtain a student model; the prediction layers in the student model and the teacher model respectively output a student model feature vector and a teacher model feature vector through a softmax function; based on the student model feature vector and the teacher model feature vector, a joint distillation loss function is determined in combination with a smooth loss function, and a lightweight cattle herd detection model is obtained through continuous iterative training, including: inputting the student model feature vector and the teacher model feature vector into a smooth loss function to obtain a smooth multi-layer perception loss function, the formula is as follows: L S-M =L smooth (P 1s ,P 1t )+L smooth (P 2s ,P 2t )+L smooth (P 3s ,P 3t ) Among them, L smooth represents the smooth loss function, P 1s , P 2s , P 3s represents the student model feature vector, P 1t , P 2t , P 3t represents the teacher model feature vector; The formula of the joint distillation loss function is as follows: THE KD =H(y,(P 1s ,P 2s ,P 3s ))+λL S-M Among them, λ is the hyperparameter for adjusting the distillation loss, H(·) is the BCEWithLogitsLoss loss function, H(y,P(T i ,τ′))=-(ylog(σ(P i (T i ,τ′)))+(1-y)log(1-σ(P i (T i ,t′)))) Where y is the true value label, τ′ is the temperature coefficient of the distillation loss, σ(·) is the Sigmoid function, T is the feature vector, and T i represents the i-th element in T; Assume that the feature vector that has not passed the softmax function in the Prediction layer is T i , after the softmax layer, we get P i : Among them, τ represents the distillation temperature. Generally, the value of τ is 1; the eigenvector is T, T i represents the i-th element in T; The processed cattle herd image is input into the lightweight cattle herd detection model to obtain the cattle herd detection result.
2. The method according to claim 1, characterized in that The student model and the teacher model are respectively based on two classic models in the YOLOv5 model, namely the YOLOv5s model and the YOLOv5x model. The YOLOv5 model includes a backbone network layer, a network neck layer and a prediction layer. The backbone network of the YOLOv5 includes a Focus structure, four DCBLs, three C3s and one SPP structure.
3. The method according to claim 2, characterized in that Outputting three student model feature vectors of different sizes through a softmax function in the prediction layer of the student model; In the prediction layer of the teacher model, three teacher model feature vectors of different sizes are output through the softmax function.
4. A computer-readable medium having computer-readable instructions stored thereon, wherein the computer-readable instructions can be executed by a processor to enable the processor to implement the method according to any one of claims 1 to 3.
5. A DC-SMKD-based lightweight cattle detection device, characterized in that: The equipment includes: one or more processors; A computer readable medium for storing one or more computer readable instructions, When the one or more computer-readable instructions are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Image recognition model training method and device, electronic equipment and readable storage medium
CN113111968A
RCNN-based cattle herd target detection method and equipment
CN113780193A