A chicken sex recognition method based on improved ResNet model
By combining the improved ResNet model with the Swish activation function, residual module importance evaluation, and Ranger optimizer, the problems of low efficiency and high computational requirements in chicken sex recognition were solved, achieving efficient and accurate sex recognition and lightweight deployment.
Patent Information
- Application Number
- CN202210873428.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-22
- Publication Date
- 2025-09-23
- Estimated Expiration
- 2042-07-22
AI Technical Summary
Existing technologies are inefficient, labor-intensive, and have high labor costs in chicken sex identification. Traditional algorithms are not robust to environmental changes, and deep learning models have large number of parameters and size, making them difficult to deploy on mobile devices.
An improved ResNet model was adopted, combined with the Swish activation function, residual module importance evaluation and Ranger optimizer. Through image enhancement and dataset amplification, a chicken sex recognition model was established, and the model parameters and volume were reduced by streamlining the modules.
It improves the accuracy and training speed of chicken sex recognition, making it suitable for sex distribution assessment and inspection robot identification in smart chicken farms, while reducing computing requirements.
Smart Images

Figure CN115331255B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of chicken sex recognition methods, and in particular to a chicken sex recognition method based on an improved ResNet model. Background Art
[0002] Chickens, as the primary producer of poultry products, are a crucial source of animal protein for humans and represent a significant portion of poultry farming. A balanced sex ratio within a flock not only contributes to efficient reproduction and healthy growth but is also a key factor influencing egg production. Despite differences in appearance and size between roosters and hens, chickens are naturally active. Current sex identification methods, which rely on manual observation, require significant experience and expertise, are inefficient, labor-intensive, and costly, making them inadequate for modern large-scale farming. Computer vision, as a non-destructive, cost-effective, and efficient detection technology, holds great promise for poultry sex identification. Chicken sex identification involves classification using common algorithms, such as K-Means and support vector machines. However, these traditional algorithms require manual feature selection and parameter design for feature extraction, are susceptible to interference from external environmental variations, and suffer from poor robustness. Deep learning algorithms, which rely on deep convolutional neural networks, are highly robust to environmental and dataset variations and have been widely used in real-world image recognition tasks.
[0003] ResNet (Residual Network) is a deep convolutional neural network proposed by He Kaiming and others in 2015 based on the concept of residual learning. It won first place in the classification and object detection tasks of the ImageNet competition that year, and also won first place in object detection and image segmentation in the COCO dataset. This network innovatively introduces a residual module, which adds skip connections between convolutional layers, allowing feature information to propagate across multiple hidden neural layers. This effectively alleviates the vanishing gradient and network degradation problems of traditional deep neural networks, allowing network structures to have dozens or even hundreds of layers.
[0004] However, whether it's the shallow AlexNet or the increasingly deeper models like GoogleNet, VGG, and ResNet, they all fail to consider the importance of different channel features during feature extraction, treating all channels as equally important. This results in some important feature channels being underappreciated during recognition, inevitably hindering model performance. Furthermore, as network model depth increases, the number of model parameters and size also surges, making training more difficult. This severely limits its deployment on mobile devices like robots (which have less computing power). Summary of the Invention
[0005] In view of the shortcomings of the existing technology, the present invention proposes a chicken sex recognition method based on an improved ResNet model.
[0006] A chicken sex recognition method based on an improved ResNet model mainly includes the following steps:
[0007] Step 1: A device with image acquisition capabilities acquires chicken images, extracts the rectangular bounding box area where the chicken is located, and labels the gender to form a chicken image dataset with gender labels. The chicken image dataset with gender labels is divided into a training set and a test set.
[0008] In step 1, the device with image acquisition function is a digital camera, a webcam or a smart phone;
[0009] The chicken images can be transformed by adding noise, image enhancement and other different transformation methods to enhance the diversity of the data set, thereby ensuring the robustness of the algorithm to environmental changes;
[0010] Step 2: Build an improved ResNet chicken sex recognition model:
[0011] The improved ResNet chicken sex recognition model structure includes:
[0012] The first layer is the convolution layer Conv1, which includes the Batch Normalization layer BN1, the activation function layer A1 and the maximum pooling layer MP1. Since the original ResNet uses the ReLu activation function, the gradient will be set to 0 when the value is negative, causing neuron necrosis, which in turn affects the feature mapping ability of the model. To this end, the present invention mainly improves the ReLU activation function layer in the original ResNet to a Swish smoothing function layer A1 between the linear function and the ReLU, which has the characteristics of lower bound, smoothness, and non-monotonicity, and is more suitable for the nonlinear mapping of features in deep models. Therefore, in addition to the first layer, other ReLUs in the model are also improved to Swish
[0013] Because the original residual module does not consider the contribution of different feature channels to the model's recognition ability, it inevitably introduces too many useless and negative channels, which restricts the model's performance. To address this, this paper improves the residual module in the original ResNet by evaluating the importance of each channel, further enhancing the effective feature channels and suppressing the invalid and negative feature channels.
[0014] The second layer is a improved residual module 1;
[0015] An improved residual module 1 includes: global pooling layer Global pooling1, fully connected layer FC1, activation function layer Swish, fully connected layer FC2, Sigmoid layer and Scale1 layer;
[0016] The third layer consists of b improved residual modules 2;
[0017] b improved residual module 2 includes: global pooling layer Global pooling2, fully connected layer FC3, activation function layer Swish, fully connected layer FC4, Sigmoid layer and Scale2 layer;
[0018] The fourth layer consists of c improved residual modules 3;
[0019] c. The improved residual module 3 includes: global pooling layer Global pooling3, fully connected layer FC5, activation function layer Swish, fully connected layer FC6, Sigmoid layer and Scale3 layer;
[0020] The fifth layer consists of d improved residual modules 4;
[0021] The improved residual module 4 includes: global pooling layer Global pooling4, fully connected layer FC7, activation function layer Swish, fully connected layer FC8, Sigmoid layer and Scale4 layer;
[0022] The sixth layer is the average pooling layer AP1;
[0023] The average pooling layer AP1 is AvgPool;
[0024] The seventh layer is the fully connected layer F1;
[0025] The fully connected layer F1 is the fully connected layer FC9;
[0026] The eighth layer is the Softmax classification layer.
[0027] Step 3: Use the optimizer to optimize the improved ResNet chicken sex recognition model;
[0028] In order to improve the accuracy and training speed of the model based on the above network structure, the Ranger optimizer can adjust the learning rate in real time according to the training situation of each round, so that the model can achieve a higher convergence speed. In this invention, the new Ranger optimizer is used as the optimizer for training the improved ResNet model;
[0029] Step 4: Input the training set into the chicken sex recognition model optimized in step 3 (i.e., the improved ResNet chicken sex recognition model), complete the training of each parameter in the model, and obtain the chicken sex recognition model based on the improved ResNet.
[0030] Step 5: In a neural network, the connections between neurons contain a large number of parameters. As the network depth increases, the model parameters and volume increase dramatically, placing extremely high demands on the computing power of the device running the model. This is not conducive to deploying the model on terminal devices with weak computing power, such as microcontrollers and robots. In this invention, the trained model is input into a streamlined module, and unimportant neurons in the model are deleted to reduce the model parameters and volume, resulting in the final chicken sex recognition model based on the improved ResNet.
[0031] Step 6: Input new chicken images from the test set or other image collection into the chicken sex recognition model based on the improved ResNet to obtain the sex recognition results of the chickens in the input images.
[0032] Compared with the prior art, the present invention has the following advantages:
[0033] This paper proposes a chicken sex recognition method based on an improved ResNet chicken sex model. This method combines the residual blocks in ResNet with a feature channel importance evaluation structure, the new Swish activation function, and the Ranger optimizer to design a new network structure model. By streamlining the modules, the model's parameters and size are reduced. This method can predict the sex of chickens based on images, providing technical support for assessing the sex distribution of chicken flocks on chicken farms and promoting the development of sex recognition capabilities for inspection robots in smart chicken farms. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 The figure is a flowchart of a chicken sex recognition method based on an improved ResNet model in a specific embodiment of the present invention.
[0035] Figure 2 This is a schematic diagram of the overall structure of the chicken sex recognition model based on the improved ResNet model in a specific embodiment of the present invention.
[0036] Figure 3 Schematic diagram of the structure of the improved residual module 1 in a specific embodiment of the present invention.
[0037] Figure 4 Schematic diagram of the structure of the improved residual module 2 in a specific embodiment of the present invention.
[0038] Figure 5 Schematic diagram of the structure of the improved residual module 3 in a specific embodiment of the present invention.
[0039] Figure 6 Schematic diagram of the structure of the improved residual module 4 in a specific embodiment of the present invention.
[0040] Figure 7 This is a working principle diagram of the model simplification module in a specific embodiment of the present invention.
[0041] Figure 8 This is a heat map of the chicken sex identification results in a specific embodiment of the present invention.
[0042] Figure 9 This is an example diagram of the chicken sex identification results in a specific embodiment of the present invention. DETAILED DESCRIPTION
[0043] The specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0044] A chicken sex recognition method based on an improved ResNet model, such as Figure 1 Therefore, the main steps include:
[0045] Step 1: Use a device with image acquisition capabilities, such as a digital camera, webcam, or smartphone, to acquire images of chickens, extract the rectangular area where the chickens are located, and label their genders to form a sex-labeled chicken image dataset.
[0046] In this implementation, based on the chicken images captured, the EfficientDet object detector is used to extract the rectangular region containing the chickens. Veterinary experts then label the gender of each chicken image to form a chicken sex recognition image dataset. Extracting the chicken region from the images can be done using algorithms that include, but are not limited to, the EfficientDet object detector. Algorithms capable of object region / pixel extraction are also feasible, such as SSD, YOLO object detector, MaskRCNN, and Deeplab v3+ object segmentation.
[0047] Step 1.1: Divide it into training set and test set according to a certain ratio;
[0048] In this embodiment, the data set is divided into a training set and a test set in a ratio of 7:3. The ratio can also be fine-tuned or a validation set can be added according to the actual data scale and the performance of the training model.
[0049] Step 1.2: Transform the image by adding noise, image enhancement, and other methods to increase the diversity of the dataset.
[0050] In this embodiment, the dataset is enhanced and amplified by adding random Gaussian noise, random contrast enhancement, random rotation, random translation, etc., so as to improve the robustness of the model to environmental changes and complex environments.
[0051] Step 2: Establish a chicken sex recognition model based on the improved ResNet model.
[0052] In this embodiment, a chicken sex model based on the improved ResNet model is established, such as Figure 2 As shown,
[0053] The first layer consists of the convolution layer Conv, the Batch Normalization layer BN1, the activation function Swish, and the maximum pooling layer Maxpool1.
[0054] In this implementation, the convolution layer Conv has a kernel size of 7×7, a stride of 2, and 64 kernels. This is followed by a Batch Normalization layer, a Swish activation function, and a maximum pooling layer Maxpool1, where Maxpool1 has a size of 3×3 and a stride of 2. The size and number of convolution kernels are not limited to the above and can be adjusted based on the actual image and target size.
[0055] The second layer is a modified residual block 1, such as Figure 2 、 Figure 3 shown.
[0056] In this embodiment, a branch consisting of a global pooling layer Globalpooling1, a fully connected layer FC1, an activation function layer Swish, a fully connected layer FC2, a Sigmoid layer, and a Scale1 layer is added after the three layers of convolution of the original residual unit. The Globalpooling1 layer is used to compress the feature space dimension, the FC1 layer is used to fit the nonlinear relationship between features after feature compression, the Swish layer is used to enhance the ability of this nonlinear mapping, the FC2 layer is used to adjust the feature output dimension so that its number of channels is the same as the input, the Sigmoid layer is used to generate the importance of each feature channel, and the Scale1 layer is used to perform weighted operations on the features extracted by the three layers of convolution of the original residual unit.
[0057] The third layer consists of b improved residual blocks 2, such as Figure 2 、 Figure 4 shown.
[0058] In this embodiment, a branch consisting of a global pooling layer Globalpooling2, a fully connected layer FC3, an activation function layer Swish, a fully connected layer FC4, a Sigmoid layer, and a Scale2 layer is added after the three layers of convolution of the original residual unit. The Globalpooling2 layer is used to compress the input feature space dimension, the FC3 layer is used to fit the nonlinear relationship between features after feature compression, the Swish layer is used to enhance the ability of this nonlinear mapping, the FC4 layer is used to adjust the feature output dimension so that its number of channels is the same as the input, the Sigmoid layer is used to generate the importance of each feature channel, and the Scale2 layer is used to perform weighted operations on the features extracted by the three layers of convolution of the original residual unit.
[0059] The fourth layer consists of c improved residual blocks 3, such as Figure 2 、 Figure 5 shown.
[0060] In this embodiment, a branch consisting of a global pooling layer Globalpooling3, a fully connected layer FC5, an activation function layer Swish, a fully connected layer FC6, a Sigmoid layer, and a Scale3 layer is added after the three layers of convolution of the original residual unit. The Globalpooling2 layer is used to compress the input feature space dimension, the FC5 layer is used to fit the nonlinear relationship between features after feature compression, the Swish layer is used to enhance the ability of this nonlinear mapping, the FC6 layer is used to adjust the feature output dimension so that its number of channels is the same as the input, the Sigmoid layer is used to generate the importance of each feature channel, and the Scale3 layer is used to perform weighted operations on the features extracted by the three layers of convolution of the original residual unit.
[0061] The fifth layer consists of d improved residual blocks 4, such as Figure 2 、 Figure 6 shown.
[0062] In this embodiment, a branch consisting of a global pooling layer Globalpooling4, a fully connected layer FC7, an activation function layer Swish, a fully connected layer FC8, a Sigmoid layer, and a Scale4 layer is added after the three layers of convolution of the original residual unit. The Globalpooling2 layer is used to compress the input feature space dimension, the FC7 layer is used to fit the nonlinear relationship between features after feature compression, the Swish layer is used to enhance the ability of this nonlinear mapping, the FC8 layer is used to adjust the feature output dimension so that its number of channels is the same as the input, the Sigmoid layer is used to generate the importance of each feature channel, and the Scale4 layer is used to perform weighted operations on the features extracted by the three layers of convolution of the original residual unit.
[0063] In this embodiment, the values of a, b, c, and d are 3, 4, 6, and 3, respectively. Their values include but are not limited to the above cases and can be flexibly set according to the input image and detection target size, while meeting the output size matching requirements of each layer of the network.
[0064] The sixth layer is the average pooling layer AvgPool.
[0065] In this embodiment, the size of the sixth layer, the average pooling layer AvgPool, is 7×7.
[0066] The 7th layer is the fully connected layer FC9.
[0067] In this embodiment, the output size of the 7th layer, the fully connected layer FC9, corresponds to the number of chicken sexes, which is 2.
[0068] The 8th layer is the classification layer Softmax.
[0069] In this embodiment, the output size of the Softmax of the eighth classification layer is 2, corresponding to the confidence level of different genders.
[0070] Step 3: Use the new Swish function as the activation function in the model;
[0071] Step 4: Use the new Ranger optimizer as the optimizer for model training;
[0072] Step 5: Input the training set into the improved ResNet chicken sex recognition model to complete the training of each parameter in the model, and obtain a well-trained chicken sex recognition model based on the improved ResNet.
[0073] Step 6: Streamline the chicken sex recognition model based on the improved ResNet, such as Figure 7 shown.
[0074] The trained model is input into the streamlining module, and unimportant neurons in the model are deleted to reduce the model parameters and volume, thereby obtaining the final chicken sex recognition model based on the improved ResNet. The working principle of the streamlining module of the present invention includes but is not limited to deleting unimportant neurons.
[0075] Step 7: Input new chicken images from the test set or other image collection into the chicken sex recognition model based on the improved ResNet to obtain the sex recognition results of the chickens in the input images.
[0076] Get the recognition result, draw the confidence heat map of the recognition result and the recognition result, such as Figure 8 and Figure 9 shown.
Claims
1. A chicken sex recognition method based on an improved ResNet model, characterized in that: The following steps are involved: Step 1: A device with image acquisition capabilities acquires chicken images, extracts the rectangular bounding box area where the chicken is located, and labels the gender to form a chicken image dataset with gender labels. The chicken image dataset with gender labels is divided into a training set and a test set. Step 2: Build an improved ResNet chicken sex recognition model: The improved ResNet chicken sex recognition model structure includes: The first layer is the convolution layer Conv1, which includes the Batch Normalization layer BN1, the activation function layer A1 and the maximum pooling layer MP1; The second layer is an improved residual module; The third layer consists of b improved residual modules; The fourth layer consists of c improved residual modules; The fifth layer consists of d improved residual modules; The sixth layer is the average pooling layer; The seventh layer is the fully connected layer; The eighth layer is the Softmax classification layer; The improved residual module of the second layer includes: The first global pooling layer, the first fully connected layer, the activation function layer Swish, the second fully connected layer, the Sigmoid layer and the first Scale layer are set in sequence; The b improved residual modules in the third layer include: The second global pooling layer, the third fully connected layer, the activation function layer Swish, the fourth fully connected layer, the Sigmoid layer, and the second Scale layer; The c improved residual modules in the fourth layer include: The third global pooling layer, the fifth fully connected layer, the activation function layer Swish, the sixth fully connected layer, the Sigmoid layer and the third Scale layer; The d improved residual modules in the fifth layer include: The fourth global pooling layer, the seventh fully connected layer, the activation function layer Swish, the eighth fully connected layer, the Sigmoid layer and the fourth Scale layer; Step 3: Use the optimizer to optimize the improved ResNet chicken sex recognition model; Step 4: Input the training set into the chicken sex recognition model optimized in step 3 to complete the training of each parameter in the model and obtain the chicken sex recognition model based on the improved ResNet; Step 5: After streamlining, the final chicken sex recognition model based on the improved ResNet is obtained; Step 6: Input the new chicken images from the test set or other image collection into the chicken sex recognition model based on the improved ResNet obtained in step 5 to obtain the sex recognition results of the chickens in the input images.
2. The chicken sex identification method based on the improved ResNet model according to claim 1, characterized in that: In step 1, the device with image acquisition function is a digital camera, a webcam or a smart phone.
3. The chicken sex identification method based on the improved ResNet model according to claim 1, characterized in that In step 2, the average pooling layer of the sixth layer is AvgPool.
4. The chicken sex identification method based on the improved ResNet model according to claim 1, characterized in that In step 2, the seventh fully connected layer is the ninth fully connected layer.
5. The chicken sex identification method based on the improved ResNet model according to claim 1, characterized in that: In step 3, the optimizer is the Ranger optimizer.
6. The chicken sex identification method based on the improved ResNet model according to claim 1, characterized in that: In step 5, the final chicken sex recognition model based on the improved ResNet is obtained after simplification, which specifically includes: The model trained in step 4 is input into the streamlining module, and unimportant neurons in the model are deleted to obtain the final chicken sex recognition model based on the improved ResNet.
Citation Information
Patent Citations
A Text Line Recognition Method in Chinese Scenes Based on Residual Convolutional and Recurrent Neural Networks
AU2020101229A4
Improved residual network pig face recognition method
CN111666838A