A method for identifying ear tags for epidemic prevention based on neural network

Through algorithms and data augmentation technology based on convolutional neural networks, the problem of existing ear tag recognition difficulty is solved, and rapid recognition on mobile devices is achieved, the recognition cost and difficulty is reduced, and the recognition accuracy and generalization ability are improved.

CN114255382BActive Publication Date: 2024-11-08CHINACCS INFORMATION IND
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111629133.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-28
Publication Date
2024-11-08
Estimated Expiration
2041-12-28

AI Technical Summary

Technical Problem

The matrix codes of existing plastic ear tags do not have standard QR QR codes and require special equipment to read, which increases the difficulty of data collection and management, and is difficult to automatically identify in digital and informatization construction.

Method used

Using an algorithm based on convolutional neural network, the CNN convolutional neural network model is constructed by obtaining and enhancing the ear label sample picture data set, model training and hyperparameter optimization are carried out to achieve rapid identification of epidemic prevention ear labels and reduce the difficulty of identification.

Benefits of technology

It realizes the direct identification of ear tag numbers through mobile devices (such as mobile phones and tablets), which reduces the identification cost, improves the identification accuracy and generalization capabilities, and simplifies the collection process of ear tag information.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114255382B_ABST
    Figure CN114255382B_ABST
Patent Text Reader

Abstract

The present invention provides an epidemic prevention ear tag recognition method based on a neural network, which belongs to the field of ear tag recognition technology. Its technical scheme is: a method for epidemic prevention ear tag recognition based on a neural network, comprising the following steps S1, obtaining a basic data set: obtaining a sample ear tag picture as a basic data set; S2, based on the basic data set, expanding and generating an incremental data set; S3, enhancing the incremental data set to generate a training data set; S4, constructing a CNN convolutional neural network, and performing model training on the training data set; S5, CNN network parameter adjustment: guided by the set accuracy, network parameter adjustment is performed during the model training process; S6, result verification; S7, output model; S8, model transplantation. The beneficial effects of the present invention are: a training data set can be generated using fewer ear tag sample pictures; model training is performed based on a convolutional neural network, and the epidemic prevention ear tag can be directly identified through a mobile terminal.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of ear tag recognition, and in particular to an epidemic prevention ear tag recognition method based on a neural network. Background Art

[0002] At present, the pig immunization ear tag specified in the "Animal Immunization Identification Management Measures" of the Ministry of Agriculture and Rural Affairs of my country is widely used in the breeding, transportation and slaughtering of pigs. It is a plastic ear tag with many advantages such as low cost, less trauma, durability, non-toxicity and harmlessness. However, the matrix code in the ear tag is not a standard QR code and requires special equipment to read. It is not conducive to daily production management and government supervision, and increases the difficulty of data collection and management. With the gradual advancement of digitalization and informatization, the demand for automatic and low-cost identification of the number on the ear tag is becoming more and more urgent. Summary of the invention

[0003] In view of the above-mentioned problems in the prior art, the purpose of the present invention is to provide an epidemic prevention ear tag recognition method based on neural network, which realizes the recognition algorithm of epidemic prevention ear tags through an algorithm based on convolutional neural network, and then realizes the rapid recognition of ear tag numbers through mobile devices with cameras such as mobile phones and tablets, thereby reducing the difficulty of ear tag information collection.

[0004] The present invention is implemented by the following technical solution: a method for identifying ear tags for epidemic prevention based on neural network, comprising the following steps;

[0005] S1. Obtain basic data set: obtain a sample image of ear tags as the basic data set;

[0006] S2. Generate incremental data set: Based on the basic data set, expand and generate incremental data set;

[0007] S3, generating a training data set: performing enhancement processing on the incremental data set to generate a training data set;

[0008] S4. CNN network design: construct a CNN convolutional neural network and perform model training on the training data set;

[0009] S5. CNN network parameter adjustment: Guided by the set recognition accuracy, the network parameters are adjusted during the model training process, and the hyperparameters are continuously optimized; the hyperparameters (number of convolution kernels, number of network layers, etc.) cannot be obtained through the training process and must be set manually. After parameter adjustment, the accuracy of this model structure in the sample set can reach 93.4%. The software environment TensorFlow is used as a model training tool, and the hardware environment uses a workstation equipped with 2 GPU cards with 8G video memory. After multiple rounds of iterations, the hyperparameters are continuously optimized, and finally the hyperparameters described in this method are obtained.

[0010] S6, result verification: after the training is completed, the formed model is saved, and the accuracy of the basic data set is verified using the saved model;

[0011] S7, output model: when the accuracy reaches the requirement, the saved model is packaged into a persistent model file;

[0012] S8. Model porting: Use the tools provided by TensorFlow to compile the model file into a binary file (.so) that can be used on mobile devices.

[0013] Taking into account that the basic data set is usually manually sorted, in order to improve the generalization effect of samples when the number is small, further, S2 is specifically: based on the basic data set, using python's cv2 library related functions, using different fonts, different word spacing and angles, and finally obtaining an incremental data set, wherein the number of images in the incremental data set is b times that of the basic data set, and the images in the incremental data set all remove redundant elements and only retain the ear tag numbers, taking a=100, b=200, the number of images in the enhanced data set is 20,000.

[0014] In order to further increase the generalization ability of samples, S3 is specifically: the following enhancement operations are performed on each data in the incremental data set: random brightness (m pictures), random edge cutting (n pictures), random rotation (i pictures), and random noise addition (j pictures); after each picture is enhanced, k pictures are formed, where k = m + n + i + j, and the number of pictures included in the training data set is k times that of the incremental data set; take m = 5, n = 4, i = 5, j = 5, then k = 19, so the training data set will include 380,000 pictures.

[0015] Furthermore, the images in the training data set are all set to 256*256 pixels.

[0016] Furthermore, the CNN convolutional neural network includes an input layer, a Cov1 layer, a Maxpool1 layer, a Cov2 layer, a Maxpool2 layer, a Cov3 layer, a Cov4 layer, a Maxpool3 layer, an FC fully connected layer, and a softmax layer. The convolution kernel is similar to the receptive field of a neuron. If it is too small, it cannot extract effective local features, and if it is too large, the extracted features are too complex. Setting the appropriate size of the convolution kernel is very important for the performance of the CNN network, so adjusting the size of the convolution kernel is also a key step in the parameter adjustment process.

[0017] Furthermore, the process of the CNN convolutional neural network is as follows:

[0018] The input layer: grayscale the training data set images, and the input layer image size is set to 221*221 pixels; after adjusting to the grayscale image, the channel of the image is 1, reducing the training parameters of the network. The input layer inputs the image data set into the convolutional neural network for feature extraction in subsequent layers;

[0019] The Cov1 layer: 96 5*5 convolution kernels are set for feature extraction to generate a 96*55*55 tensor; the purpose of the convolution operation is to extract different features of the input, and the first convolution layer can only extract some low-level features such as edges and lines;

[0020] The Maxpool1 layer: uses a 3*3 convolution kernel for pooling operation to generate a 96*27*27 tensor; the pooling layer does not extract features but is used to reduce the spatial size of the data, so the number of parameters and the amount of calculation will also decrease;

[0021] The Cov2 layer: sets 256 3*3 convolution kernels for feature extraction, generates a 256*25*25 tensor; extracts more complex features from the upper convolution layer;

[0022] The Maxpool2 layer: uses a 3*3 convolution kernel for pooling operation to generate a 256*12*12 tensor; Maxpool2 is equivalent to compressing the features to prevent overfitting;

[0023] The Cov3 layer: sets 256 2*2 convolution kernels for feature extraction, generates a 256*7*7 tensor; extracts more complex features from the upper convolution layer;

[0024] The Cov4 layer: sets 256 2*2 convolution kernels for feature extraction, generates a 256*10*10 tensor, and extracts more complex features from the upper convolution layer;

[0025] The Maxpool3 layer: uses a 3*3 convolution kernel for pooling operation to generate a 256*8*8 tensor;

[0026] The FC fully connected layer: connects the 256*8*8 feature map, that is, uses 4096 256*8*8 convolution kernels to get a value for the 256*8*8 tensor, which is a feature point, and then corresponds to a point in the 4096 neurons; each neuron in this layer is connected to all neurons in the previous layer. Integrate the local information with category distinction in the convolution layer or pooling layer;

[0027] The softmax layer: uses softmax for classification, thereby mapping the features to the corresponding classification space.

[0028] Furthermore, before using the saved model to verify the accuracy of the basic data set, data is first selected from the incremental data set in a certain proportion to verify its accuracy.

[0029] The beneficial effects of the present invention are as follows: the present invention can generate a large number of training data sets through data enhancement and automatic generation technology using less ear tag sample image data, thereby reducing the difficulty of constructing the training data set; the model training is based on a convolutional neural network with strong generalization ability; the function of directly identifying the epidemic prevention ear tag through the camera of a mobile terminal (mobile phone, tablet computer and other devices) is realized, thereby reducing the recognition cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Figure 1 It is a schematic diagram of the overall process of the present invention.

[0031] Figure 2 This is a schematic diagram of the ear tag sample picture.

[0032] Figure 3 This is the picture effect diagram in the incremental dataset.

[0033] Figure 4 This is the effect diagram of the pictures in the training data set.

[0034] Figure 5 This is the structure diagram of the CNN convolutional neural network. DETAILED DESCRIPTION

[0035] In order to clearly illustrate the technical features of this solution, this solution is described below through a specific implementation method.

[0036] Example 1, see Figure 1-Figure 5 , the present invention is implemented by the following technical scheme: a method for identifying ear tags for epidemic prevention based on neural network, comprising the following steps;

[0037] S1. Obtain basic data set: Obtain 100 ear tag sample images as the basic data set, such as Figure 2 As shown,

[0038] S2. Generate incremental data set: Based on the basic data set, use the relevant functions of Python's cv2 library, use different fonts, different word spacing and angles, and finally generate an incremental data set. The incremental data set includes 20,000 pictures, and all pictures in the incremental data set are free of redundant elements and only retain the ear tag numbers; the basic effects of the pictures in the incremental data set are as follows: Figure 3 As shown;

[0039] S3, generate training data set: perform the following enhancement operations on each picture in the incremental data set: random brightness (m pictures), random edge cutting (n pictures), random rotation (i pictures), random noise addition (j pictures); after each picture is enhanced, k pictures are formed, where k = m + n + i + j, and the number of pictures included in the training data set is k times the number of pictures in the incremental data set; take m = 5, n = 4, i = 5, j = 5, then k = 19, so the training data set will include 380,000 pictures. The size of all sample pictures is 256*256 pixels, and the picture effects in the training data set are as follows Figure 4 As shown;

[0040] S4. CNN network design: Figure 5 As shown, a CNN convolutional neural network is constructed, and the model training is performed on the training data set; the CNN convolutional neural network includes an input layer, a Cov1 layer, a Maxpool1 layer, a Cov2 layer, a Maxpool2 layer, a Cov3 layer, a Cov4 layer, a Maxpool3 layer, an FC fully connected layer, and a softmax layer; the convolution kernel is similar to the receptive field of a neuron. If it is too small, it cannot extract effective local features, and if it is too large, the extracted features are too complex. Setting the appropriate size of the convolution kernel is very important for the performance of the CNN network, so adjusting the size of the convolution kernel is also a key step in the parameter adjustment process; the receptive field size F of the neurons in the convolution layer, the step size S, the number of convolution kernels K, and the number of zero padding P are calculated and output, W is the output tensor width, H is the tensor height, and D is the tensor depth. The formula is as follows:

[0041] W2=(W1-F+2P) / S+1

[0042] H2=(H1-F+2P) / S+1

[0043] D2=K

[0044] The input layer: grayscale the images in the training data set that are not grayscale images. After adjusting to grayscale images, the channel of the image is 1, and the training parameters of the network are reduced. Since the size of all images has been set to 256*256 pixels when the data set is generated, the size of the input image needs to be adjusted according to the parameters of the network in the input layer, and the image size of the input layer is set to 221*221 pixels; the input layer inputs the image data set into the convolutional neural network for feature extraction in subsequent layers;

[0045] The Cov1 layer: Set a 5*5 convolution kernel for feature extraction, perform convolution operation on the 221*221 image, and according to the formula, finally obtain a feature matrix of [(221-5+2*0) / 4+1]*[(221-5+2*0) / 4+1]=55*55. A total of 96 convolution kernels are set, and finally a 96*55*55 tensor will be generated; the 55*55 matrix obtained by convolution needs to be calculated through an activation function to convert the result into nonlinearity to enhance the generalization ability of the network. This layer uses ReLu as the activation function. At the same time, a bias term y=relu(wx+b) is added; the purpose of the convolution operation is to extract different features of the input. The first convolution layer can only extract some low-level features such as edges and lines.

[0046] The Maxpool1 layer: uses a 3*3 convolution kernel for pooling operation, and finally obtains a feature matrix of [(55-3+2*0) / 2+1]*[(55-3+2*0) / 2+1]=27*27. Since it does not operate on the depth, it finally generates a tensor of 96*27*27. The pooling layer does not extract features but is used to reduce the spatial size of the data, so the number of parameters and the amount of calculation will also decrease.

[0047] The Cov2 layer: sets a 3*3 convolution kernel for feature extraction, which is equivalent to a smaller receptive field and better ability to observe details compared to a 5*5 convolution kernel. Perform a convolution operation on a 96*27*27 image. According to the formula, a feature matrix of [(27-3+2*0) / 1+1]*[(27-3+2*0) / 1+1]=25*25 is finally obtained; this layer sets 256 convolution kernels, which will eventually generate a 256*25*25 tensor; extract more complex features from the upper convolution layer;

[0048] The Maxpool2 layer: uses a 3*3 convolution kernel for pooling operations, and finally obtains a feature matrix of [(25-3+2*0) / 2+1]*[(25-3+2*0) / 2+1]=12*12. Since it does not operate on the depth, it finally generates a 256*12*12 tensor; Maxpool2 is equivalent to compressing the features to prevent overfitting;

[0049] The Cov3 layer: sets a 2*2 convolution kernel for feature extraction, performs convolution on a 256*12*12 image, and finally obtains a [(12-2+2*0) / 1+1]*[(12-2+2*0) / 1+1]=7*7 feature matrix. This layer sets 256 convolution kernels, and finally generates a 256*7*7 tensor; extracts more complex features from the upper convolution layer;

[0050] The Cov4 layer: sets a 2*2 convolution kernel for feature extraction, performs a convolution operation on a 256*7*7 image, and finally obtains a [(11-2+2*0) / 1+1]*[(11-2+2*0) / 1+1]=10*10 feature matrix according to the formula. This layer sets 256 convolution kernels, and finally generates a 256*10*10 tensor; extracts more complex features from the upper convolution layer;

[0051] The Maxpool3 layer: uses a 3*3 convolution kernel for pooling operations, and finally obtains a feature matrix of [(10-3+2*0) / 1+1]*[(10-3+2*0) / 1+1]=8*8. Since it does not operate on the depth, it finally generates a 256*8*8 tensor;

[0052] The FC fully connected layer: connects the 256*8*8 feature map, that is, uses 4096 256*8*8 convolution kernels to get a value for the 256*8*8 tensor, which is a feature point, and then corresponds to a point in the 4096 neurons; each neuron in this layer is connected to all neurons in the previous layer. Integrate the local information with category distinction in the convolution layer or pooling layer;

[0053] The softmax layer: uses softmax for classification, thereby mapping the features to the corresponding classification space;

[0054] S5. CNN network parameter adjustment: Guided by the set accuracy, the network parameters are adjusted during the model training process, and the hyperparameters are continuously optimized; the hyperparameters (number of convolution kernels, number of network layers, etc.) cannot be obtained through the training process and must be set manually. After parameter adjustment, the accuracy of this model structure in the sample set can reach 93.4%; the software environment TensorFlow is used as the model training tool, and the hardware environment uses a workstation equipped with 2 GPU cards with 8G video memory. After multiple rounds of iterations, the hyperparameters are continuously optimized, and finally the hyperparameters described in this method are obtained; the final convolutional neural network structure parameters are shown in the following table:

[0055]

[0056]

[0057] S6, result verification: after the training is completed, the formed model is saved, and the accuracy of the basic data set is verified using the saved model;

[0058] S7, output model: when the accuracy reaches the requirement, the saved model is packaged into a persistent model file;

[0059] S8. Model porting: Use the tools provided by TensorFlow to compile the model file into a binary file (.so) that can be used on mobile devices.

[0060] Embodiment 2, based on Embodiment 1, taking into account that the amount of data in the basic data set is small and there is a difference of several levels between the basic data set and the incremental data set, before using the saved model to verify the accuracy of the basic data set, data is first selected from the incremental data set in a certain proportion for accuracy verification.

[0061] First, the accuracy of the incremental data set is verified. If it fails, retraining is required. After passing, the accuracy of the basic data set is verified. Since the basic data set is data that has not been generalized and expanded, overfitting can be prevented. The following three situations will occur: 1. The accuracy of both verifications is very low, and the data in the training data set should be reviewed and then retrained. 2. If the accuracy of the first accuracy verification meets the requirements, but the second is lower, it means that overfitting has occurred, and the amount of data in the training data set should be adjusted according to the situation. 3. If the accuracy of both accuracy verifications meets the requirements, the currently saved model can meet the requirements and subsequent operations can continue.

[0062] This method uses Python to automatically generate data sets to provide training data sets for neural networks, without the need to manually collect large amounts of data sets. The accuracy of the final model reached 93.4%, meeting the requirements for field use. By integrating with mobile devices, it can greatly reduce the cost of identifying epidemic prevention ear tags in the livestock breeding production process and promote the construction of livestock breeding informatization in my country.

[0063] In the description of the invention, the previous detailed description has been described various embodiments of the apparatus and / or process by using block diagrams, flow charts and / or examples. To the extent that such block diagrams, flow charts and / or examples contain one or more functions and / or operations, it will be understood by those skilled in the art that each function and / or operation within such block diagrams, flow charts or examples can be implemented individually and / or collectively by many various hardware, software, firmware or any combination thereof.

[0064] There is little difference between hardware and software implementations of various aspects of the system; the use of hardware or software is typically (but not always, as the choice between hardware and software may become important in certain scenarios) a design choice that represents a tradeoff between cost and efficiency. There are various means (e.g., hardware, software, and / or firmware) by which the processes and / or systems and / or other techniques described herein may be implemented, and the preferred means will vary depending on the scenario in which the processes and / or systems and / or other techniques are deployed. For example, if the implementer determines that speed and accuracy are extremely important, then the implementer may choose a primarily hardware and / or firmware means; if flexibility is extremely important, then the implementer may choose a primarily software implementation; or, but equally alternatively, the implementer may choose some combination of hardware, software, and / or firmware.

[0065] Technical features not described in the present invention can be achieved through or by adopting existing technologies and will not be described in detail here. Of course, the above description is not a limitation of the present invention, and the present invention is not limited to the above examples. Changes, modifications, additions or substitutions made by ordinary technicians in this technical field within the essential scope of the present invention should also fall within the scope of protection of the present invention.

Claims

1. A method for identifying ear tags for epidemic prevention based on neural networks, characterized in that: The method comprises the following steps: S1. Obtain basic data set: obtain a sample image of ear tags as the basic data set; S2. Generate incremental data set: Based on the basic data set, expand and generate incremental data set; S3, generating a training data set: performing enhancement processing on the incremental data set to generate a training data set; S4. CNN network design: construct a CNN convolutional neural network and perform model training on the training data set; S5. CNN network parameter adjustment: Based on the set accuracy, network parameters are adjusted during model training and hyperparameters are continuously optimized. S6, result verification: after the training is completed, the formed model is saved, and the accuracy of the basic data set is verified using the saved model; S7, output model: when the accuracy reaches the requirement, the saved model is packaged into a persistent model file; S8, model migration: compile the model file into a binary file that can be used on mobile devices; The CNN convolutional neural network includes an input layer, a Cov1 layer, a Maxpool1 layer, a Cov2 layer, a Maxpool2 layer, a Cov3 layer, a Cov4 layer, a Maxpool3 layer, a FC fully connected layer, and a softmax layer; The process of the CNN convolutional neural network is as follows: The input layer: grayscale the training data set image, and the input layer image size is set to 221*221 pixels; The Cov1 layer: sets 96 convolution kernels of size 5*5 for feature extraction, generating a tensor of size 96*55*55; The Maxpool1 layer: uses a 3*3 convolution kernel for pooling operation to generate a 96*27*27 tensor; The Cov2 layer: sets 256 3*3 convolution kernels for feature extraction, generating a 256*25*25 tensor; The Maxpool2 layer: uses a 3*3 convolution kernel for pooling operation to generate a 256*12*12 tensor; The Cov3 layer: sets 256 2*2 convolution kernels for feature extraction, generating a 256*7*7 tensor; The Cov4 layer: sets 256 2*2 convolution kernels for feature extraction, generating a 256*10*10 tensor; The Maxpool3 layer: uses a 3*3 convolution kernel for pooling operation to generate a 256*8*8 tensor; The FC fully connected layer: connects the 256*8*8 feature map, that is, uses 4096 256*8*8 convolution kernels to obtain a value for the 256*8*8 tensor, which is a feature point, and then corresponds to one point in the 4096 neurons; The softmax layer: uses softmax for classification, thereby mapping the features to the corresponding classification space.

2. The method for identifying ear tags for epidemic prevention based on neural networks according to claim 1, characterized in that: Specifically, S2 is as follows: based on the basic data set, using the relevant functions of the cv2 library of Python, using different fonts, different character spacings and angles, and finally generating an incremental data set, wherein the number of images in the incremental data set is b times that of the basic data set, and all images in the incremental data set remove redundant elements and only retain the ear tag numbers.

3. The method for identifying ear tags for epidemic prevention based on neural networks according to claim 2, characterized in that: Specifically, S3 is as follows: performing the following enhancement operations on each data in the incremental data set: random brightness (m pictures), random edge cutting (n pictures), random rotation (i pictures), and random noise addition (j pictures); after each picture is enhanced, k pictures are formed, where k=m+n+i+j, and the number of pictures included in the training data set is k times that of the incremental data set.

4. The method for identifying ear tags for epidemic prevention based on neural networks according to claim 1, characterized in that: The images in the training data set are all set to 256*256 pixels.

5. The method for identifying ear tags for epidemic prevention based on neural network according to claim 1, characterized in that: Before using the saved model to verify the accuracy of the basic data set, data is first selected from the incremental data set in a certain proportion to verify its accuracy.