CN116052211A - Knowledge distillation-based YOLOv5s lightweight sheep variety identification method and system - Google Patents

Knowledge distillation-based YOLOv5s lightweight sheep variety identification method and system Download PDF

Info

Publication number
CN116052211A
CN116052211A CN202310006737.3A CN202310006737A CN116052211A CN 116052211 A CN116052211 A CN 116052211A CN 202310006737 A CN202310006737 A CN 202310006737A CN 116052211 A CN116052211 A CN 116052211A
Authority
CN
China
Prior art keywords
sheep
yolov5s
network
knowledge distillation
loss
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310006737.3A
Other languages
Chinese (zh)
Inventor
郭瑛
徐艳红
王凤英
胡晓莉
杜永兴
秦岭
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Inner Mongolia University of Science and Technology
Original Assignee
Inner Mongolia University of Science and Technology
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Inner Mongolia University of Science and Technology filed Critical Inner Mongolia University of Science and Technology
Priority to CN202310006737.3A priority Critical patent/CN116052211A/en
Publication of CN116052211A publication Critical patent/CN116052211A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Image Analysis (AREA)
  • Image Processing (AREA)

Abstract

The invention discloses a knowledge distillation-based YOLOv5s lightweight sheep variety identification method and a knowledge distillation-based YOLOv5s lightweight sheep variety identification system, wherein the identification method comprises the following steps: s1: collecting videos of multiple varieties of sheep in a farm; s2: extracting an image frame in a video as an original image, preprocessing the original image, and dividing the processed image into a training set, a verification set and a test set; s3: constructing a knowledge distillation-based lightweight sheep strain identification neural network model of YOLOv5 s; s4: training the sheep variety identification neural network model by adopting a training set and a verification set to obtain an optimal weight; s5: and inputting the test set into a trained sheep variety identification network model and evaluating the performance of the model. The method provided by the invention utilizes knowledge distillation to transfer the effective characteristics learned by the teacher network with large parameter quantity and high identification precision to the student network, thereby improving the identification precision of the variety identification network and realizing the purposes of small network model parameters and light weight.

Description

Knowledge distillation-based YOLOv5s lightweight sheep variety identification method and system
Technical Field
The invention relates to the technical field of modern intelligent animal husbandry, in particular to a method and a system for identifying YOLOv5s lightweight sheep breeds based on knowledge distillation.
Background
The mutton sheep industry is an important component of the present animal husbandry, and plays a very important role in national economy. If the optimal grazing time, supplementary feeding amount and epidemic prevention medication can be formulated for different varieties, the cost can be effectively saved, the economic benefit of pastures can be improved, and the productivity of flocks of sheep can be improved by cultivating high-quality varieties. Therefore, the identification of sheep breeds is a premise and basis and has very important significance. At present, the identification of sheep breeds in actual production mainly comprises manual identification, body measurement and DNA identification. With popularization of the cross breeding technology, the phenotype of individuals subjected to several generations of cross breeding has high similarity with parents, and the difficulty of manual identification is high and error is very easy to occur; body measurements are not only time-consuming and labor-consuming but also prone to errors; although the DNA identification can realize accurate identification, the cost is higher, the identification period is longer, and meanwhile, the sheep only has stress reaction due to blood drawing, and the sheep only has a certain influence on the body health. In recent years, along with the development of the animal husbandry from the traditional mode to intellectualization, precision and scale, a non-contact type variety identification method based on computer vision is gradually paid attention to, and the method has the advantages of saving cost and improving identification accuracy. Ruian et al issued patent, "a pig breed identification method, device and computer readable storage medium," provides a method for identifying a pig breed, but the constructed two-step identification network model is complex, resulting in longer network reasoning time and unfavorable for deployment in practice. Yu Wenbo et al issued patent, "a method and a system for identifying individual sheep flocks in sheep houses based on YOLOv4," provides a method for identifying individual sheep flocks in sheep houses, but the constructed network has lower identification accuracy. Therefore, how to identify sheep breeds rapidly and accurately in a non-contact manner becomes a problem to be solved urgently.
In view of the above drawbacks, the present inventors have finally achieved the present invention through long-time studies and practices.
Disclosure of Invention
The invention aims to solve the problems of large background interference, large model parameter and low model generalization capability in a non-contact technology, thereby providing a method and a system for recognizing YOLOv5s lightweight sheep breeds based on knowledge distillation.
A method for identifying a YOLOv5s lightweight sheep variety based on knowledge distillation comprises the following steps:
s1: collecting videos of multiple varieties of sheep in a farm;
s2: extracting an image frame in a video as an original image, preprocessing the original image, and dividing the processed image into a training set, a verification set and a test set;
s3: the sheep variety identification neural network comprises a teacher network YOLOv5x and a student network YOLOv5s, knowledge distillation is adopted to transfer knowledge learned by the teacher network YOLOv5x with large parameter quantity and high identification precision to the light-weight student network YOLOv5s, and a light-weight sheep variety identification neural network model based on the knowledge distillation YOLOv5s is constructed;
s4: training the sheep variety identification neural network model by adopting training set and verification set data to obtain optimal weight;
s5: inputting the test set into a trained sheep variety identification network model, inputting sheep image prediction varieties, and evaluating the performance of the model according to the test result.
Further, step S1 includes the following:
numbering sheep of different varieties on the sheep, arranging a camera at the outlet of a sheep hurdle channel, shooting videos of the sheep flocks passing through the channel in different time periods and under different weather conditions, and transmitting the video files to a server by using a WIFI technology;
further, step S2 includes the steps of:
s21: extracting video frames from the stored video file to serve as an original image, setting the cut-off frequency as a preset value, and de-duplicating the original image;
s22: labeling the face area and variety category of the sheep on the image after the duplication removal, adding a label frame in the labeling process, and generating a label file, wherein the label file comprises the position information of the calibrated face area and the corresponding variety category;
s23: dividing the marked image into a training set, a verification set and a test set according to a preset proportion;
s24: and carrying out data enhancement on images of the training set and the verification set, wherein the data enhancement comprises brightness enhancement, brightness reduction, horizontal mirroring, vertical mirroring, multi-angle rotation and noise superposition operation.
Further, step S3 includes the steps of:
s31: respectively inputting the training set with the enhanced data into a teacher network YOLOv5x and a student network YOLOv5s, and respectively obtaining high-dimensional characteristics B after extracting the characteristics of the training set through a trunk convolutional neural network 1t and B2s
Respectively transmitting feature vectors into respective PANet networks by a teacher network YOLOv5x and a student network YOLOv5S, overlapping features with different scales by using a bottom-up and top-down method, completing multi-scale fusion of the features, and obtaining a plurality of feature vectors S and feature vectors P;
respectively carrying out global maximum pooling and channel splicing on a plurality of feature vectors S and feature vectors P to obtain a one-dimensional vector T i 、F i One-dimensional vector T i 、F i Respectively obtaining feature vectors after feature fusion among channels
Figure BDA0004037237960000021
and />
Figure BDA0004037237960000022
Feature vector
Figure BDA0004037237960000023
Inputting the soft label of the teacher network into a multi-classification softmax function with the temperature t, and guiding students to learn variety characteristic information and association information among different varieties through the soft label by knowledge distillation;
s32: constructing a loss function of the YOLOv5s sheep variety identification neural network based on knowledge distillation, wherein the loss function comprises target detection loss and relative entropy loss, and the integral loss function is obtained by adding the target detection loss and the relative entropy loss.
Further, the high-dimensional feature B in step S31 1t and B2s The expression formula of (2) is as follows:
Figure BDA0004037237960000031
wherein ft Representing a backbone convolutional neural network in a teacher network, f s The trunk convolution neural network representing the student network, H, W, C respectively represents the length, width and channel number of sheep images input into the training set, m (i,j,k) Representing the pixel values of the input sheep image.
Further, in step S31, a plurality of feature vectors S i and Pi Respectively carrying out global maximum pooling and channel splicing to obtain a one-dimensional vector T i 、F i One-dimensional vector T i 、F i The expression formula of (2) is as follows:
Figure BDA0004037237960000032
F i =[Max(P i H,W,1 ),Max(P i H,W,2 ),……,Max(P i H,W,j )]
wherein ,Ti and Fi Feature fusion between channels is performed through convolution of 1×1 to obtain feature vectors respectively
Figure BDA0004037237960000033
And
Figure BDA0004037237960000034
Figure BDA0004037237960000035
and />
Figure BDA0004037237960000036
The vector may be split into n+m, where N represents the number of sheep breeds and M represents the index and coordinates of a particular anchor frame.
Further, step S31 sets the feature vector
Figure BDA0004037237960000037
Inputting the soft label into a softmax multi-classification function with the temperature of t to obtain a soft label of a teacher network, wherein the definition formula of the soft label is as follows:
Figure BDA0004037237960000038
wherein Zi And finally outputting the characteristic vector of each variety for the trained teacher network, wherein the characteristic vector comprises indexes, coordinates and variety categories of the anchor frame.
Further, the step S32 includes the following specific steps:
s321, constructing target detection loss:
Figure BDA0004037237960000039
wherein Lbox For the bounding box regression loss, calculating for each target; l (L) obj Calculating for each grid for target object loss; l (L) cls For classification loss, each target is also calculated; lambda (lambda) 1 、λ 2 、λ 3 Weights of three losses respectively;
s322, calculating relative entropy loss according to the soft label obtained by the teacher network and the prediction vector obtained by the student network in the step S31, wherein the relative entropy loss is calculated by the following formula:
Figure BDA0004037237960000041
wherein ,
Figure BDA0004037237960000042
representing soft labels output by a teacher network, q (t) represents a prediction result output by a student network, and N represents the number of varieties;
s323: in the knowledge distillation network model training process, weighting and adding the target detection loss and the relative entropy loss to obtain the overall knowledge distillation loss:
Figure BDA0004037237960000043
where μ is the super-parameter of the addition of the two loss functions, t 2 For adjusting the specific gravity of the two loss functions.
Further, the step S4 specifically includes the following steps:
s41: pre-training a teacher network YOLOv5x by using a training set to obtain a soft label of each image data;
s42: and supervising the training process of the student network YOLOv5s by using the soft tag, continuously updating the parameters of the student network YOLOv5s in the training process, and finishing the parameter updating of the student network YOLOv5s when the loss value is stable or continuously oscillates within a preset range, thereby obtaining a trained sheep variety identification neural network model.
A YOLOv5s lightweight sheep variety identification system based on knowledge distillation, which applies the sheep variety identification method, comprises the following modules:
the sheep face detection device comprises a data set acquisition module, a sheep face detection module and a sheep face detection module, wherein the data set acquisition module is used for acquiring sheep face information of sheep passing through a sheep hurdle channel in a breeding farm, preprocessing face images, marking sheep faces by using a marking frame, obtaining a sheep variety image data set, and dividing the sheep variety image data set into a training set, a verification set and a test set;
the model construction module is used for constructing a knowledge distillation-based YOLOv5s lightweight sheep variety identification network model, wherein the network model comprises a teacher network YOLOv5x and a student network YOLOv5s, knowledge distillation is adopted to transfer knowledge learned by the teacher network YOLOv5x with large parameter quantity and high identification precision to the lightweight student network YOLOv5s, and a knowledge distillation-based YOLOv5s lightweight sheep variety identification neural network model is constructed;
the model training module is used for constructing a loss function, performing pre-training by using a training set, taking model parameters obtained after the pre-training as initial parameters of the sheep variety identification neural network model, and performing parameter adjustment on the model parameters by using the verification set to obtain a trained sheep variety identification neural network model; and finally inputting the test set into the trained neural network model, and evaluating the performance of the neural network model.
Compared with the prior art, the invention has the beneficial effects that: the invention discloses a knowledge distillation-based YOLOv5s lightweight sheep variety identification method, which does not need to manually extract characteristics, but repeatedly extracts and stacks the characteristics through a convolutional neural network-based target detection method, so as to obtain richer essential characteristics related to varieties; compared with the existing method for recognizing varieties based on deep learning, the method provided by the invention has the advantages that the target detection algorithm is used for directly extracting the face images of sheep, so that the background interference can be effectively removed, meanwhile, the effective characteristics learned by a teacher network with large parameter quantity and high recognition accuracy are transmitted to a student network by utilizing knowledge distillation, so that the recognition accuracy of the variety recognition network can be improved, and the purposes of small network model parameters and light weight are realized.
Drawings
FIG. 1 is a block flow diagram of steps of a knowledge distillation-based YOLOv5s lightweight sheep variety identification method;
FIG. 2 is a schematic flow chart of a knowledge distillation-based YOLOv5s lightweight sheep variety identification method;
FIG. 3 is a flow chart of the perceptual hash algorithm of the present invention;
FIG. 4 is an original image and an image-enhanced sample of the present invention;
FIG. 5 is a schematic diagram of a model structure of a YOLOv5s lightweight sheep variety identification neural network based on knowledge distillation;
FIG. 6 is a graph of the training validation loss of a teacher's network in accordance with the present invention;
FIG. 7 is a graph of the training validation loss of a YOLOv5s network incorporating knowledge distillation in accordance with the present invention;
FIG. 8 is a mAP indicator of the test result according to the invention;
FIG. 9 is a block diagram of a knowledge distillation-based YOLOv5s lightweight sheep variety identification system.
Detailed Description
The invention provides a knowledge distillation-based YOLOv5s lightweight sheep variety identification method, which solves the problems of large background interference, large model parameter and low model generalization capability in the existing non-contact technology.
The present invention will be further described in detail below with reference to the accompanying drawings by way of specific embodiments in order to make the objects, technical solutions and advantages of the present invention more apparent.
Example 1
As shown in fig. 1 and fig. 2, the method for identifying the light sheep variety of YOLOv5s based on knowledge distillation provided by the embodiment of the invention comprises the following steps:
s1: collecting videos of multiple varieties of sheep in a farm;
s2: extracting an image frame in a video as an original image, preprocessing the original image, and dividing the processed image into a training set, a verification set and a test set;
s3: the sheep variety identification neural network comprises a teacher network YOLOv5x and a student network YOLOv5s, knowledge distillation is adopted to transfer knowledge learned by the teacher network YOLOv5x with large parameter quantity and high identification precision to the light-weight student network YOLOv5s, and a light-weight sheep variety identification neural network model based on the knowledge distillation YOLOv5s is constructed;
s4: training the sheep variety identification neural network model by adopting a training set to obtain optimal weights;
s5: inputting the test set into a trained sheep variety identification network model, inputting sheep image prediction varieties, and evaluating the performance of the model according to the test result.
In one embodiment, the step S1 specifically includes: numbering the sheep bodies of different varieties so as to carry out variety classification on the data sets of sheep images in the follow-up process; the method is characterized in that the camera is arranged at the outlet of the passage of the sheep hurdle and is 5-10cm higher than the height of the sheep, the camera is set to 24 frames per second, videos of the sheep flock passing through the passage are shot in different time periods and different weather conditions, and the video files are transmitted to the server by using the WIFI technology.
In one embodiment, in the step S2, the video information is intercepted according to a preset intercepting frequency, the obtained sheep image is used as an input original image, and the original image is subjected to data preprocessing, which specifically includes the following steps:
s21: and extracting video frames from the stored video by using an OpenCV open source software library in python, setting the frame cutting frequency to be 24, and storing the video in a JPG format. The obtained sheep images are firstly cleaned, images which do not contain sheep face images and large-area face shielding images are removed, then similarity filtering is carried out on the cleaned images through a perception hash algorithm, 400 pictures are reserved for each variety after filtering, and the flow of the perception hash algorithm is shown in figure 3;
s22: firstly, storing all pictures of the same kind of sheep into the same folder according to the sheep variety labels for the filtered images, wherein the folder names are the same as the sheep variety label names, then labeling face areas and variety types of the sheep of all kinds, adding label frames by using labelimg in the labeling process, and generating corresponding label files for the sheep face areas in the images. The file mainly comprises four vertex coordinates of the calibrated rectangular area of the sheep face and corresponding sheep variety types in the area;
s23: dividing the marked pictures according to 7:2:1, dividing a training set, a verification set and a test set;
s24: the data enhancement is carried out on the images of the training set and the verification set, so that the generalization capability of the sheep variety identification model is improved; the data enhancement comprises operations such as brightness enhancement and reduction, mirroring, multi-angle rotation, noise superposition and the like, the images of the training set and the verification set after enhancement are increased by 7 times, as shown in fig. 4, and fig. 4 is an original image and a sample after image enhancement;
in one embodiment, as shown in fig. 5, in step S3, knowledge learned by a teacher network with large parameter quantity and high recognition accuracy is transferred to a light-weight student network YOLOv5S through knowledge distillation, so that the feature extraction capability of a PANet part in the student network is enhanced, and the purposes of light weight and accurate recognition of a network model are achieved. Constructing a knowledge distillation-based lightweight sheep-breed identification neural network model of YOLOv5S, wherein the step S3 specifically comprises the following steps:
s31: constructing a model of a YOLOv5s sheep variety identification neural network based on knowledge distillation and a loss function; the step S31 specifically includes the following steps:
firstly, training set images with the pixel size of 640 multiplied by 3 after data enhancement are respectively input into a teacher network and a student network, and high-dimensional characteristics B are respectively obtained after characteristic extraction through a trunk convolution neural network 1t and B2s
Figure BDA0004037237960000071
wherein ft Representing a backbone convolutional neural network in a teacher network, f s Backbone representing student networkConvolutional neural network H, W, C respectively represents length, width and channel number of sheep images input into training set, m (i,j,k) Representing the pixel values of the input sheep image.
High-dimensional feature vector B 1t Three dimensions are included: (80, 80, 320), (40, 40, 640), (20, 20, 1280); high-dimensional feature vector B 1s Three dimensions are included: (80, 80, 128), (40, 40, 256), (20, 20, 512). In the feature extraction stage of the trunk convolutional neural network, a teacher network YOLOv5x transmits feature vectors with the sizes of (80, 80, 320), (40, 40, 640), (20, 20, 1280) into the PANet network, and features with different scales are overlapped by a bottom-up and top-down method to complete multi-scale fusion of the features and obtain a feature vector S 1 (80,80,320)、S 2 (40, 40, 640) and S 3 (20, 20, 1280); the student network YOLOv5s also transmits the feature vectors with the sizes of (80, 80, 128), (40, 40, 256), (20, 20, 512) into the PANet network to obtain a feature vector P 1 (80,80,128)、P 2 (40, 40, 256) and P 3 (20,20,512)。
Then for the feature vector S 1 、S 2 、S 3 and P1 、P 2 、P 3 Respectively carrying out global maximum pooling and channel splicing to obtain a one-dimensional vector T i 、F i
Figure BDA0004037237960000072
F i =[Max(P i H,W,1 ),Max(P i H,W,2 ),……,Max(P i H,W,j )]
wherein ,Ti and Fi Feature fusion between channels is performed through convolution of 1×1 to obtain feature vectors respectively
Figure BDA0004037237960000073
And
Figure BDA0004037237960000074
Figure BDA0004037237960000075
and />
Figure BDA0004037237960000076
The vector may be split into n+m, where N represents the number of sheep breeds and M represents the index and coordinates of a particular anchor frame.
Finally, will
Figure BDA0004037237960000077
Inputting the soft label into a softmax (multi-classification) function with the temperature t to obtain a soft label of a teacher network, wherein the calculation formula is as follows:
Figure BDA0004037237960000078
Figure BDA0004037237960000079
soft tag representing teacher network, < >>
Figure BDA00040372379600000710
Output vector representing teacher network, t representing temperature, Z i Predictive probability representing the ith category
Knowledge distillation guides students to learn variety characteristic information and association information among different varieties through soft labels of teacher networks.
The prediction vector of the student network comprises indexes and coordinates of specific anchor frames, and is obtained by extracting the characteristics of the student network through sheep images. The relative entropy loss is calculated through Kullback-Leibler divergence (KL divergence) according to a soft label obtained by a teacher network and a prediction vector obtained by a student network, the relative entropy loss is added with a target detection loss to obtain overall knowledge distillation loss, the optimal weight is obtained according to the teacher network in the previous pre-training process, the student network is guided to learn through the optimal weight, finally, the student network obtains the recognition precision close to the teacher network, only parameters of a student network model are updated in the process of reversely transmitting the update weight, and model parameters of the teacher network do not participate in updating.
S32: constructing a loss function of a knowledge distillation-based Yolov5s sheep variety identification neural network, wherein the integral distillation loss comprises a target detection loss and a relative entropy loss, and specifically comprises the following steps:
target detection loss function:
Figure BDA0004037237960000081
wherein Lbox For the bounding box regression loss, calculating for each target; l (L) obj Calculating for each grid for target object loss; l (L) cls For classification loss, each target is also calculated; lambda (lambda) 1 、λ 2 、λ 3 The weights of the three losses are respectively.
Relative entropy loss function:
Figure BDA0004037237960000082
wherein ,
Figure BDA0004037237960000083
representing soft labels output by teacher network, q (t) representing prediction result output by student network, N representing variety number
In the knowledge distillation network model training process, weighting and adding the target detection loss function and the relative entropy loss function to obtain the overall knowledge distillation loss:
Figure BDA0004037237960000084
where μ is the super-parameter of the addition of the two loss functions, t 2 For adjusting the specific gravity of the two loss functions. Distillation loss is a feature that serves as a supervision for a student to learn over the teacher's network.
In one embodiment, training the knowledge distillation-based YOLOv5S light sheep breed identification network in step S4 to obtain an optimal weight, where the optimal weight is obtained by comparing loss values, so as to achieve the best identification effect, and specifically includes the following steps:
s41: firstly, training a teacher network YOLOv5x in a sheep variety identification neural network model by using a training set to obtain a soft label of each data; and then the training process of the output student network YOLOv5s is supervised by using the soft label.
Specifically, the invention collects the facial images of 823 sheep of 10 varieties, and carries out 500 rounds of training on 25200 sheep after data enhancement. After the teacher network is pretrained by a large number of sheep face pictures, the essential characteristics of the sheep faces closely related to varieties can be better extracted.
The teacher network training verification Loss verification curve is shown in fig. 6, the abscissa Epoch represents the training wheel number, the ordinate Loss represents the Loss value, the train Loss curve represents the Loss value of the teacher network on the training set, the val Loss curve represents the Loss value on the verification set, and the teacher network training verification Loss verification curve shows that the network model training is stable, and further training cannot achieve a better effect; after the teacher finishes the network training, the optimal weight is obtained by comparing the loss values, and the optimal weight obtained by the network model in the training process is stored.
S42: and then fixing the obtained optimal weight of the teacher network YOLOv5x, pre-training a knowledge distillation-based YOLOv5s sheep variety identification neural network model by using a training set, wherein the teacher network YOLOv5x does not participate in the updating of the weight in the knowledge distillation network model, the parameters of the student network YOLOv5s are continuously updated, and when the loss value reaches stability or continuously oscillates within a preset range, the parameters of the student network YOLOv5s are updated, so that the trained sheep variety identification neural network model is obtained.
The parameters of the knowledge distillation network model are respectively selected as follows: the distillation temperature t was 4 and the equilibrium coefficient of the loss function was 0.2. The overall network model is totally trained for 500 rounds, a training verification loss curve is shown in fig. 7, and the fact that the network model is not fitted and is converged can be seen through the loss function curve.
In the embodiment of the invention, 400 photos of the test set are input into the trained sheep variety identification neural network model for testing, and the obtained result is shown in figure 8, wherein the ordinate represents different sheep varieties, the abscissa represents mAP indexes, and the final average mAP value is 94.7%, which shows that the model achieves higher detection precision on the premise of not increasing the parameters of the network model.
Example two
As shown in fig. 9, the embodiment of the invention provides a YOLOv5s lightweight sheep variety identification system based on knowledge distillation, which comprises the following modules:
the sheep face marking device comprises a sheep face marking frame, a sheep face marking module, a sheep variety marking module and a sheep variety marking module, wherein the sheep face marking module is used for marking sheep faces of sheep through sheep hurdle channels, and the sheep face marking module is used for marking sheep faces of sheep through the sheep hurdle channels to obtain sheep variety image data sets;
the model construction module is used for constructing a knowledge distillation-based YOLOv5s lightweight sheep variety identification network model, wherein the network model comprises a teacher network YOLOv5x and a student network YOLOv5s, a test set is respectively input into the teacher network and the student network, and a high-dimensional characteristic B is respectively obtained after characteristic extraction is carried out through a main convolution neural network 1t and B2s . The teacher network and the student network respectively transmit the feature vectors into the respective PANet networks, and the features with different scales are overlapped by using a bottom-up and top-down method to complete multi-scale fusion of the features and obtain the feature vectors; global maximum pooling and channel splicing are respectively carried out on the feature vectors to obtain one-dimensional vectors
Figure BDA0004037237960000091
and />
Figure BDA0004037237960000092
Feature vector ∈of teacher network>
Figure BDA0004037237960000093
Inputting the characteristic information into a softmax function with the temperature t to obtain a soft label, and guiding students to learn the characteristic information of varieties and the associated information among different varieties through a network by the soft label。
The model training module is used for constructing a loss function, performing pre-training by using a face data training set, taking model parameters obtained after the pre-training as initial parameters of the sheep variety identification neural network model, and performing parameter adjustment by using the verification set to obtain a trained sheep variety identification neural network model; and finally, inputting the test set into the trained neural network model, and evaluating the performance of the neural network model.
The invention discloses a knowledge distillation-based YOLOv5s lightweight sheep variety identification method, which is a non-contact identification method and can not lead sheep to have stress reaction; different from the traditional machine learning feature point extraction method for realizing classification, the method provided by the invention does not need to manually extract features, but repeatedly extracts and stacks the features by a target detection method based on a convolutional neural network, so that richer essential features related to varieties are obtained; compared with the existing method for recognizing varieties based on deep learning, the method provided by the invention has the advantages that the target detection algorithm is used for directly extracting the face images of sheep, so that the background interference can be effectively removed, meanwhile, the effective characteristics learned by a teacher network with large parameter quantity and high recognition accuracy are transmitted to a student network by utilizing knowledge distillation, so that the recognition accuracy of the variety recognition network can be improved, and the purposes of small network model parameters and light weight are realized.
The foregoing description of the preferred embodiment of the invention is merely illustrative of the invention and is not intended to be limiting. It will be appreciated by persons skilled in the art that many variations, modifications, and even equivalents may be made thereto without departing from the spirit and scope of the invention as defined in the appended claims.

Claims (10)

1. A method for identifying a YOLOv5s lightweight sheep variety based on knowledge distillation is characterized by comprising the following steps:
s1: collecting videos of multiple varieties of sheep in a farm;
s2: extracting an image frame in a video as an original image, preprocessing the original image, and dividing the processed image into a training set, a verification set and a test set;
s3: the sheep variety identification neural network comprises a teacher network YOLOv5x and a student network YOLOv5s, knowledge distillation is adopted to transfer knowledge learned by the teacher network YOLOv5x with large parameter quantity and high identification precision to the light-weight student network YOLOv5s, and a light-weight sheep variety identification neural network model and a loss function of the YOLOv5s based on the knowledge distillation are constructed;
s4: training the sheep variety identification neural network model by adopting training set and verification set data to obtain optimal weight;
s5: inputting the test set into a trained sheep variety identification network model, inputting sheep image prediction varieties, and evaluating the performance of the model according to the test result.
2. The knowledge distillation based YOLOv5S lightweight sheep breed identification method of claim 1, step S1 comprising the following:
numbering is carried out on sheep of different varieties, a camera is arranged at the outlet of a sheep hurdle passage, videos of sheep flocks passing through the passage are shot under different weather conditions in different time periods, and a WIFI technology is utilized to transmit video files to a server.
3. The knowledge distillation based YOLOv5S lightweight sheep breed identification method of claim 1, step S2 comprising the steps of:
s21: extracting video frames from the stored video file to serve as an original image, setting the cut-off frequency as a preset value, and de-duplicating the original image;
s22: labeling the face area and variety category of the sheep on the image after the duplication removal, adding a label frame in the labeling process, and generating a label file, wherein the label file comprises the position information of the calibrated face area and the corresponding variety category;
s23: dividing the marked image into a training set, a verification set and a test set according to a preset proportion;
s24: and carrying out data enhancement on images of the training set and the verification set, wherein the data enhancement comprises brightness enhancement, brightness reduction, horizontal mirroring, vertical mirroring, multi-angle rotation and noise superposition operation.
4. The knowledge distillation based YOLOv5S lightweight sheep breed identification method of claim 3, wherein step S3 comprises the steps of:
s31: respectively inputting the training set with the enhanced data into a teacher network YOLOv5x and a student network YOLOv5s, and respectively obtaining high-dimensional characteristics B after extracting the characteristics of the training set through a trunk convolutional neural network 1t and B2s
Teacher network YOLOv5x and student network YOLOv5s respectively characterize B in high dimension 1t and B2s The method comprises the steps of transmitting the characteristics into respective PANet networks, superposing the characteristics of different scales by using a bottom-up and top-down method, completing multi-scale fusion of the characteristics, and obtaining a plurality of characteristic vectors S and characteristic vectors P;
respectively carrying out global maximum pooling and channel splicing on a plurality of feature vectors S and feature vectors P to obtain a one-dimensional vector T i 、F i One-dimensional vector T i 、F i Respectively obtaining feature vectors after feature fusion among channels
Figure FDA0004037237950000021
and />
Figure FDA0004037237950000022
Feature vector
Figure FDA0004037237950000023
Inputting the soft label of the teacher network into a multi-classification softmax function with the temperature t, and guiding students to learn variety characteristic information and association information among different varieties through the soft label by knowledge distillation;
s32: constructing a loss function of the YOLOv5s sheep variety identification neural network based on knowledge distillation, wherein the loss function comprises target detection loss and relative entropy loss, and the integral loss function is obtained by adding the target detection loss and the relative entropy loss.
5. The method for recognizing a YOLOv5S lightweight sheep variety based on knowledge distillation as claimed in claim 4, wherein the high-dimensional feature B in step S31 1t and B2s The expression formula of (2) is as follows:
Figure FDA0004037237950000024
wherein ft Representing a backbone convolutional neural network in a teacher network, f s The trunk convolution neural network representing the student network, H, W, C respectively represents the length, width and channel number of sheep images input into the training set, m (i,j,k) Representing the pixel values of the input sheep image.
6. The method for recognizing a YOLOv5S lightweight sheep variety based on knowledge distillation as claimed in claim 4, wherein in step S31, the plurality of feature vectors S are represented by i and Pi Respectively carrying out global maximum pooling and channel splicing to obtain a one-dimensional vector T i 、F i One-dimensional vector T i 、F i The expression formula of (2) is as follows:
Figure FDA0004037237950000025
F i =[Max(P i H,W,1 ),Max(P i H,W,2 ),……,Max(P i H,W,j )]
wherein ,Ti and Fi Feature fusion between channels is performed through convolution of 1×1 to obtain feature vectors respectively
Figure FDA0004037237950000026
and />
Figure FDA0004037237950000027
Figure FDA0004037237950000028
and />
Figure FDA0004037237950000029
The vector may be split into n+m, where N represents the number of sheep breeds and M represents the index and coordinates of a particular anchor frame.
7. The method for recognizing a YOLOv5S lightweight sheep variety based on knowledge distillation as set forth in claim 4, wherein step S31 is to use feature vectors
Figure FDA00040372379500000210
Inputting the soft label into a softmax multi-classification function with the temperature of t to obtain a soft label of a teacher network, wherein the definition formula of the soft label is as follows:
Figure FDA00040372379500000211
wherein Zi And finally outputting the characteristic vector of each variety for the trained teacher network, wherein the characteristic vector comprises indexes, coordinates and variety categories of the anchor frame.
8. The knowledge distillation based YOLOv5S lightweight sheep breed identification method of claim 4, wherein step S32 comprises the specific steps of:
s321: construction of target detection loss:
Figure FDA0004037237950000031
wherein Lbox For the bounding box regression loss, calculating for each target; l (L) obj Calculating for each grid for target object loss; l (L) cls For classification loss, each target is also calculated; lambda (lambda) 1 、λ 2 、λ 3 Weights of three losses respectively;
s322: calculating relative entropy loss according to the soft label obtained by the teacher network and the prediction vector obtained by the student network in the step S31, wherein the relative entropy loss is calculated by the following formula:
Figure FDA0004037237950000032
wherein ,
Figure FDA0004037237950000033
representing soft labels output by a teacher network, q (t) represents a prediction result output by a student network, and N represents the number of varieties; />
S323: in the knowledge distillation network model training process, weighting and adding the target detection loss and the relative entropy loss to obtain the overall knowledge distillation loss:
Figure FDA0004037237950000034
where μ is the super-parameter of the addition of the two loss functions, t 2 For adjusting the specific gravity of the two loss functions.
9. The knowledge distillation based YOLOv5S lightweight sheep variety identification method of claim 1, wherein step S4 comprises the steps of:
s41: pre-training a teacher network YOLOv5x by using a training set to obtain a soft label of each image data;
s42: and supervising the training process of the student network YOLOv5s by using the soft tag, continuously updating the parameters of the student network YOLOv5s in the training process, and finishing the parameter updating of the student network YOLOv5s when the loss value is stable or continuously oscillates within a preset range, thereby obtaining a trained sheep variety identification neural network model.
10. A YOLOv5s lightweight sheep variety identification system based on knowledge distillation, which uses the sheep variety identification method according to any one of claims 1-9, and is characterized by comprising the following modules:
the sheep face detection device comprises a data set acquisition module, a sheep face detection module and a sheep face detection module, wherein the data set acquisition module is used for acquiring sheep face information of sheep passing through a sheep hurdle channel in a breeding farm, preprocessing face images, marking sheep faces by using a marking frame, obtaining a sheep variety image data set, and dividing the sheep variety image data set into a training set, a verification set and a test set;
the model construction module is used for constructing a knowledge distillation-based YOLOv5s lightweight sheep variety identification network model, wherein the network model comprises a teacher network YOLOv5x and a student network YOLOv5s, knowledge distillation is adopted to transmit knowledge learned by the teacher network YOLOv5x with large parameter quantity and high identification precision to the lightweight student network YOLOv5s, and a knowledge distillation-based YOLOv5s lightweight sheep variety identification neural network model is constructed;
the model training module is used for constructing a loss function, performing pre-training by using a training set, taking model parameters obtained after the pre-training as initial parameters of the sheep variety identification neural network model, and performing parameter adjustment on the model parameters by using the verification set to obtain a trained sheep variety identification neural network model; and finally inputting the test set into the trained neural network model, and evaluating the performance of the neural network model.
CN202310006737.3A 2023-01-04 2023-01-04 Knowledge distillation-based YOLOv5s lightweight sheep variety identification method and system Pending CN116052211A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310006737.3A CN116052211A (en) 2023-01-04 2023-01-04 Knowledge distillation-based YOLOv5s lightweight sheep variety identification method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310006737.3A CN116052211A (en) 2023-01-04 2023-01-04 Knowledge distillation-based YOLOv5s lightweight sheep variety identification method and system

Publications (1)

Publication Number Publication Date
CN116052211A true CN116052211A (en) 2023-05-02

Family

ID=86121367

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310006737.3A Pending CN116052211A (en) 2023-01-04 2023-01-04 Knowledge distillation-based YOLOv5s lightweight sheep variety identification method and system

Country Status (1)

Country Link
CN (1) CN116052211A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117079195A (en) * 2023-10-13 2023-11-17 中国科学技术大学 Wild animal identification method and system based on image video
CN117610608A (en) * 2023-10-20 2024-02-27 重庆理工大学 Knowledge distillation method, equipment and medium based on multi-stage feature fusion
CN117831138A (en) * 2024-03-05 2024-04-05 天津科技大学 Multi-mode biological feature recognition method based on third-order knowledge distillation

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117079195A (en) * 2023-10-13 2023-11-17 中国科学技术大学 Wild animal identification method and system based on image video
CN117079195B (en) * 2023-10-13 2024-02-23 中国科学技术大学 Wild animal identification method and system based on image video
CN117610608A (en) * 2023-10-20 2024-02-27 重庆理工大学 Knowledge distillation method, equipment and medium based on multi-stage feature fusion
CN117831138A (en) * 2024-03-05 2024-04-05 天津科技大学 Multi-mode biological feature recognition method based on third-order knowledge distillation
CN117831138B (en) * 2024-03-05 2024-05-24 天津科技大学 Multi-mode biological feature recognition method based on third-order knowledge distillation

Similar Documents

Publication Publication Date Title
CN116052211A (en) Knowledge distillation-based YOLOv5s lightweight sheep variety identification method and system
CN111178197B (en) Mass R-CNN and Soft-NMS fusion based group-fed adherent pig example segmentation method
CN109961089A (en) Small sample and zero sample image classification method based on metric learning and meta learning
CN110532970B (en) Age and gender attribute analysis method, system, equipment and medium for 2D images of human faces
CN113688889A (en) Abnormality detection method, abnormality detection device, electronic apparatus, and computer-readable storage medium
CN108846413A (en) A kind of zero sample learning method based on global semantic congruence network
US20230162522A1 (en) Person re-identification method of integrating global features and ladder-shaped local features and device thereof
CN113887661B (en) Image set classification method and system based on representation learning reconstruction residual analysis
CN116091786B (en) Holographic body ruler self-coding method, system, equipment and storage medium for pig weight estimation
CN110969073B (en) Facial expression recognition method based on feature fusion and BP neural network
CN116311483B (en) Micro-expression recognition method based on local facial area reconstruction and memory contrast learning
CN116051560B (en) Embryo dynamics intelligent prediction system based on embryo multidimensional information fusion
CN111881958A (en) License plate classification recognition method, device, equipment and storage medium
CN112101333A (en) Smart cattle farm monitoring and identifying method and device based on deep learning
CN114550212A (en) Goat face detection and identification method based on lightweight model
CN115115830A (en) Improved Transformer-based livestock image instance segmentation method
CN113420709A (en) Cattle face feature extraction model training method and system and cattle insurance method and system
CN110490028A (en) Recognition of face network training method, equipment and storage medium based on deep learning
CN116295022A (en) Pig body ruler measurement method based on deep learning multi-parameter fusion
CN116612335A (en) Few-sample fine-granularity image classification method based on contrast learning
Zheng et al. Attention assessment based on multi‐view classroom behaviour recognition
CN117789037A (en) Crop growth period prediction method and device
CN116778391A (en) Multi-mode crop disease phenotype collaborative analysis model and device
CN107563327B (en) Pedestrian re-identification method and system based on self-walking feedback
CN116580243A (en) Cross-domain remote sensing scene classification method for mask image modeling guide domain adaptation

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination