Network model, construction method, and method and system for nondestructive gender identification of eggs

By constructing a network model containing a first and a second filtering layer, and utilizing channel attention mechanism and depthwise separable convolution, the problems of long time consumption and high cost in egg gender recognition are solved, achieving efficient and lossless egg gender recognition, which is suitable for mass industrial applications.

WO2026012223A1PCT designated stage Publication Date: 2026-01-15NANJING STARHELIX INTELLIGENT CO LTD

Patent Information

Application Number
PCT/CN2025/105973
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-07-09
Filing Date
2025-06-30
Publication Date
2026-01-15

AI Technical Summary

Technical Problem

Existing methods for identifying the sex of eggs suffer from problems such as long processing time, high cost, unsuitability for mass application, and high risk of invasive detection, making it difficult to achieve efficient and non-destructive egg sex identification.

Method used

A network model is adopted, including a first filter layer and a second filter layer of the input layer. Through channel attention mechanism and depthwise separable convolution, features of egg spectral images are filtered and extracted to build an efficient egg sex recognition system.

Benefits of technology

It achieves efficient and non-destructive egg sex identification, reducing detection time and cost, and is suitable for mass application in industry.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025105973_15012026_PF_FP_ABST
    Figure CN2025105973_15012026_PF_FP_ABST
Patent Text Reader

Abstract

A network model, a construction method, and a method and system for non-destructive gender identification of eggs. The network model for identifying the gender of eggs, comprising a first filter layer (100) capable of screening spectral image bands of features of fertilized eggs; and a second filter layer (200) capable of further extracting image features and channel features of the fertilized eggs. Original image spectrums can be directly used as an output, thus overcoming the disadvantage of waste of potential useful information in average spectrum methods, ameliorating the problems of slow convergence, many parameters and insufficient accuracy of deep learning during processing of large-dimensional hyperspectral images, and achieving gender identification on the tenth day of egg incubation.
Need to check novelty before this filing date? Find Prior Art

Description

A network model, construction method, and a non-destructive method and system for identifying the sex of eggs. Technical Field

[0001] This invention relates to the field of egg sex identification technology, and in particular to a method and system for non-destructive identification of egg sex using neural network algorithms. Background Technology

[0002] Currently, the main methods for determining the sex of early egg embryos, both domestically and internationally, include the following:

[0003] I. Identification methods based on volatile organic compounds (VOCs): This method determines VOCs by analyzing the gases emitted from eggshells, but it requires a long time to collect gas samples and is not suitable for batch applications. Although techniques such as chemical ionization have recently been proposed for rapid detection of gas components, the accuracy and repeatability of these models are still poorly understood, and their repeatability remains unknown.

[0004] II. Polymerase Chain Reaction (PCR)-based identification method: PCR is a commonly used technique for sex identification in avian research. It amplifies sex-specific genes located on the Z and W sex chromosomes. This method mainly involves three steps: DNA isolation, PCR, and gel electrophoresis. After screening the PCR products by agarose gel electrophoresis, males and females show clear differences, which can be used to classify embryos. However, this method is not only uneconomical, requiring specialized equipment and precise experiments, but also quite time-consuming, making it unsuitable for large-scale application in practical scenarios.

[0005] III. Raman Spectroscopy-Based Identification Method: This method analyzes the spectrum of blood in extraembryonic vessels using Raman spectroscopy by opening a window in the eggshell. The identification accuracy can reach 90% on day 3.5 of incubation. However, invasive testing carries the risk of infection, and opening and sealing the eggshell increases identification costs, making it unsuitable for parallel application in large-scale hatcheries. Summary of the Invention

[0006] In view of the problems existing in the above-mentioned methods for detecting the sex of eggs, the present invention is proposed.

[0007] Therefore, one of the problems to be solved by this invention is how to provide a network model that can efficiently filter noise.

[0008] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a network model, including an input layer, a first filter layer capable of filtering feature bands added to the input layer; and a second filter layer capable of further extracting image features and channel features and filtering channel features.

[0009] As a preferred embodiment of the network model described in this invention, the first filtering layer captures information about the correlation between potential channels in the average spectrum through a channel attention mechanism, and assigns greater weight to important channels.

[0010] As a preferred embodiment of the network model described in this invention, the first filtering layer is capable of performing the following processing: downsampling each channel of the spectral image to a mean; performing first and second derivative operations to obtain a vector with multiple dimensions; summing the obtained vectors to obtain the weight of each channel; and multiplying the weights by each channel of the original image to include the importance features of the channels in the output data.

[0011] In a preferred embodiment of the network model described in this invention, the first filtering layer is an SE layer.

[0012] As a preferred embodiment of the network model described in this invention, the SE layer is modified.

[0013] As a preferred embodiment of the network model described in this invention, the improved operation involves performing first-order and second-order derivative operations, specifically,

[0014] Among them, AvgP i Let D1 be the mean of the i-th channel image, and n be the number of channels in the spectral image. i Let D2 be the first derivative corresponding to the i-th channel. i Let be the second derivative of the i-th channel.

[0015] As a preferred embodiment of the network model described in this invention, the second filtering layer can further extract image texture information and channel information, and reduce the channel features.

[0016] As a preferred embodiment of the network model described in this invention, the second filtering layer can perform the following processing: reducing the channel dimension through pointwise convolution; performing depthwise convolution on the reduced channels to extract features within each channel; and performing pointwise convolution again to fuse information between channels to obtain the output image of the reduced channels.

[0017] In a preferred embodiment of the network model described in this invention, the second filtering layer is a depth-separable convolutional layer.

[0018] Another problem that this invention aims to solve is how to provide a method for constructing network models that can efficiently filter noise.

[0019] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a method for constructing a network model for identifying the sex of eggs, comprising: screening image feature bands of fertilized eggs; and further extracting image features and channel features of fertilized eggs.

[0020] As a preferred embodiment of the network model described in this invention, the process of screening the image feature bands of fertilized eggs includes: downsampling each channel of the spectral image to a mean; performing an improvement operation to obtain a vector with multiple dimensions; summing the obtained vectors to obtain the weight of each channel; and multiplying the weights by each channel of the original spectral image to include the importance features of the channels in the output data.

[0021] In a preferred embodiment of the network model described in this invention, the image feature bands for screening fertilized eggs are implemented through an SE layer.

[0022] As a preferred embodiment of the network model described in this invention, the SE layer is modified.

[0023] As a preferred embodiment of the network model described in this invention, the improved operation involves performing first-order and second-order derivative operations, specifically,

[0024] Among them, AvgP i Let D1 be the mean of the i-th channel image, and n be the number of channels in the spectral image. i Let D2 be the first derivative corresponding to the i-th channel. i Let be the second derivative of the i-th channel.

[0025] As a preferred embodiment of the network model described in this invention, the further extraction of image features and channel features, and the filtering of channel features, includes: reducing the channel dimension through pointwise convolution; performing depthwise convolution on the reduced channels to extract features within each channel; and performing pointwise convolution again to fuse information between channels to obtain the output image of the reduced channels.

[0026] As a preferred embodiment of the network model described in this invention, the further extraction of image features and channel features of fertilized eggs is achieved through depthwise separable convolutional layers.

[0027] As a preferred embodiment of the network model described in this invention, the training and evaluation of the network model are described.

[0028] As a preferred embodiment of the network model described in this invention, the training includes fitting and optimizing the model using a loss function: criterion = W1CrossEntropyLoss() + W2Waste_Ratio + W3Kappa + W4F1 WasteRatio=(P f *FP) / (P mn *TP)

[0029] Where CrossEntropyLoss is the cross-entropy loss, WasteRatio is the average cost of wasting a female egg when identifying a male egg, Kappa and F1 are the evaluation metrics used, and W is the average cost of identifying a male egg. i (i = 1...4) refers to the weight of the corresponding parameter; N is the number of samples, C is the number of varieties in the current category, and y ij It is the value of category j in the true label of sample i. FP is the predicted probability of category j in the probability distribution output by the model corresponding to sample i; FP is the number of female eggs identified as male eggs, TP is the number of male eggs identified as a pair, and P is the predicted probability of category j in the probability distribution output by the model corresponding to sample i. f P is the price coefficient for hatching hens. mn The price coefficient of the male eggs selected in advance on day n;

[0030] After the classification result is obtained through the judgment of the optimization model, the true label is compared with the classification result, the result is calculated using the loss function, and the gradient is calculated using backpropagation.

[0031] In a preferred embodiment of the network model described in this invention, the evaluation is performed using the following formula.

[0032] Where OA represents overall accuracy, AA represents average accuracy, TP is the number of samples correctly predicted as positive, TN is the number of samples correctly predicted as negative, FN is the number of samples incorrectly predicted as negative, and FP is the number of samples incorrectly predicted as positive.

[0033] Where PE is the expected random consistency probability;

[0034] Recall and Precision are respectively the recall rate and precision rate.

[0035] Another problem that this invention aims to solve is how to provide a method for non-destructive identification of the sex of eggs.

[0036] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a method for non-destructive identification of egg sex, comprising: acquiring spectral images of fertilized eggs; segmenting regions of interest from the acquired images; constructing a network model; interpreting and inferring key feature wavelengths based on the network model; and detecting egg sex based on wavelength combinations.

[0037] As a preferred embodiment of the non-destructive identification method for egg sex according to the present invention, the step of segmenting the region of interest from the acquired image includes: merging the R, G, and B bands of the image, selecting the egg range and obtaining a grayscale image; and further processing the grayscale image to segment the spectral image of the egg region from the original spectral image.

[0038] Another problem that this invention aims to solve is how to provide a system capable of non-destructive identification of the sex of eggs.

[0039] To address the aforementioned technical problems, the present invention provides the following technical solution: a system configured for non-destructive identification of egg sex, comprising: a memory storing computer-readable instructions; and a processor configured, when executing the computer-readable instructions, to: segment a region of interest from an acquired image; employ the network model; interpret and infer key feature wavelengths based on the network model; and detect egg sex based on wavelength combinations.

[0040] As a preferred embodiment of the non-destructive egg sex identification system of the present invention, the step of segmenting the region of interest from the acquired image includes: merging the R, G, and B bands of the image, selecting the egg range and obtaining a grayscale image; and further processing the grayscale image to segment the spectral image of the egg region from the original spectral image.

[0041] The beneficial effects of this invention are as follows: This invention designs a novel network architecture, EggFormer, which innovatively incorporates SE layers and depthwise separable convolutions as the head of the new model. Compared with traditional dimensionality reduction methods, it has higher accuracy and fewer bands, which is beneficial for reducing costs and detection time in industrial applications and is conducive to batch parallel processing. Attached Figure Description

[0042] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein:

[0043] Figure 1 is a schematic diagram of the architecture of the network model for identifying the sex of eggs according to the present invention.

[0044] Figure 2 is a schematic diagram of assigning greater weight to important channels through a channel attention mechanism in one embodiment of the present invention.

[0045] Figure 3 is a comparison of recall data using different methods for average spectral preprocessing in this invention.

[0046] Figure 4 is a comparison of the accuracy of average spectral preprocessing using different methods in this invention.

[0047] Figure 5 is a comparison of the accuracy of average spectral preprocessing using different methods in this invention.

[0048] Figure 6 shows the 24th to 31st channels of the 32-channel image obtained by depth-separable convolution according to the present invention.

[0049] Figure 7 is a schematic diagram of the region of interest extraction process described in this invention.

[0050] Figure 8 is a visualization of the wavelength contribution of the random forest described in this invention.

[0051] Figure 9 shows the principal component diagram extracted by the principal component analysis method of the present invention, from left to right: PC1, PC2, and PC3.

[0052] Figure 10 shows the characteristic wavelengths selected by analyzing the SE layer of the EggFormer model in this invention.

[0053] Figure 11 is a schematic diagram of the visualization result of a female egg in one embodiment of the present invention, wherein the left side is the image of the three RGB channels, and the right side is the heat map of the network model that identifies the sex of the egg.

[0054] Figure 12 is a schematic diagram of the visualization results of another female egg in another embodiment of the present invention, wherein the left side is the image of the three RGB channels, and the right side is the heat map of the network model that identifies the sex of the egg.

[0055] Figure 13 is a schematic diagram of the visualization result of a male egg in one embodiment of the present invention, wherein the left side is the image of the three RGB channels, and the right side is the heat map of the network model that identifies the sex of the egg.

[0056] Figure 14 is a schematic diagram of the visualization results of another male egg in another embodiment of the present invention, wherein the left side is the image of the three RGB channels, and the right side is the heat map of the network model that identifies the sex of the egg. Detailed Implementation

[0057] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

[0058] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of the invention. Therefore, the invention is not limited to the specific embodiments disclosed below.

[0059] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in different places in this specification does not necessarily refer to the same embodiment, nor is it a single or selective embodiment that is mutually exclusive with other embodiments.

[0060] Example 1: The first embodiment of the present invention provides a neural network model for non-destructive identification of the sex of eggs. This network model necessarily includes an input layer, a hidden layer, and an output layer.

[0061] Referring to Figure 1, in one embodiment, two filtering layers are added to the input layer: a first filtering layer 100 and a second filtering layer 200. The first filtering layer 100 can filter the spectral image bands of fertilized eggs, while the second filtering layer 200 can further extract the image features and channel features of fertilized eggs.

[0062] The “spectral images” mentioned herein include hyperspectral images of fertilized eggs captured using hyperspectral imaging technology or multispectral images of fertilized eggs captured using a special camera.

[0063] The first filter layer 100, which can screen the image feature bands of fertilized eggs, can be implemented using machine learning algorithms such as RF (Random Forest Simplified), CARS (Competitive Adapative Reweighted Sampling), SPA (Successive Projections Algorithm), and PCA (Principal Component Analysis) to identify the average spectral curve, as shown in Table 1 below.

[0064] Table 1 Performance Comparison of Different Algorithms

[0065] The second filtering layer, which can further extract image and channel features of fertilized eggs, can be implemented using conventional deep learning methods, such as depthwise separable convolution, full convolution, or dilated convolution, as shown in Table 2 below.

[0066] Table 2 Performance Comparison of Different Convolution Methods

[0067] Analysis revealed that the original hyperspectral or multispectral image contains images with multiple channels, which contain too much redundant information. It is difficult to extract effective information by using all channels as model input. Therefore, in this implementation, the multi-channel image is downsampled into an average spectral curve, that is, the average value of the image of each channel is taken, and the hyperspectral image is converted into a feature vector with the same dimension as the number of channels. If the original hyperspectral image contains 300 channels, the corresponding average spectral curve is a 300-dimensional vector.

[0068] In one implementation, referring to Figure 1, the input spectral image of a fertilized egg is a 440-channel image composed of 440 wavelengths. Each channel image is a grayscale image with a width and length of 224, i.e., the input dimension is (440, 224, 224), and the value of each pixel is between 0 and 255. After passing through the first filtering layer 100, the output dimension remains unchanged at (440, 224, 224), but each channel image contains channel weight information, where each color represents a different channel image. The darker the color, the higher the importance and weight of that channel. Subsequently, depthwise separable convolution is used to further extract image features and channel information. The number of channels is adjusted from 440 to 32, and the output dimension is (32, 224, 224). Similarly, the darker the color of each channel, the higher its importance. The function of depthwise separable convolution is to remove redundant and unimportant channel images. As shown in Figure 1, the output channel images are mostly dark.

[0069] Of course, those skilled in the art should also recognize that a third, fourth, or even more filter layers can be used, as shown in Table 3 below:

[0070] Table 3. Performance Comparison of Different Filter Layer Combinations

[0071] As shown in the comparison results in the table above, the two-layer filtering layer has the best performance, with an accuracy of 0.954. The metrics for measuring the overall performance of the model, F1 and Kappa, are the best, at 0.958 and 0.908 respectively. Moreover, the model requires the fewest parameters and has the fewest training parameters.

[0072] Meanwhile, the inventors' comparative experiments proved that the network model can be applied to identify the sex of chicken and quail eggs, but it is not necessarily applicable to duck eggs, goose eggs and other poultry eggs. Its identification effect is not as good as the combination of the first filter layer 100 and the second filter layer 200 in this embodiment.

[0073] Different filter layers can also be added to the hidden layer, or a first filter layer 100 can be added to the input layer, while a second filter layer 200 can be added to the hidden layer.

[0074] In Example 2, compared to Example 1, the first filter layer 100 of this embodiment captures information about the correlation between potential channels in the average spectrum through a channel attention mechanism, and assigns greater weight to important channels.

[0075] Channel attention mechanisms adaptively rescale the features of each channel by modeling the interdependencies between feature channels. This allows the network to focus on more useful channels and enhances its discriminative learning capabilities. Channel attention enables neural networks to automatically determine which channels are important or unimportant and then assign appropriate weights. Each channel of the feature map is treated as a feature detector, so channel features focus on "what" is useful information in the image.

[0076] The phrase "capturing information about the correlations between potential channels in the average spectrum" specifically refers to the average spectrum, which is the result of averaging spectral data from multiple samples within a given region. Spectra typically describe the properties or composition of an object by measuring the intensity of light at different wavelengths. When analyzing spectra, the focus is usually on the intensity variations between different wavelengths and the correlations between them. This correlation helps in understanding how signals at different wavelengths change over time, conditions, or other factors, thereby revealing the properties or state of an object.

[0077] Understanding the correlations in average spectra helps in data analysis and pattern identification. When the spectral data of different samples show consistent trends at certain wavelengths, a correlation can be considered to exist between these wavelengths. This correlation indicates that these wavelengths are important for distinguishing different categories of samples or features.

[0078] The reason the model can classify based on average spectral curves is that these curves represent typical spectral features of different categories or characteristics. When these features are fed into the machine learning model for training, the model can learn the differences between different categories, and when it receives new spectral data, it can make classification predictions based on these learned features.

[0079] In this implementation, the channel attention mechanism can be implemented using ECANet (Efficient Channel Attention for Deep Convolutional Neural Networks), SE layer attention mechanism (Squeeze-and-Excitation Networks), CBAM network architecture (Convolutional Block Attention Module), STN network (Spatial Transformer Networks), or STL network structure (Spatial Transformer Layer), etc.

[0080] The concept of "important channels" can be understood as follows: Taking the improved attention mechanism of the SE layer as an example, see Figure 2. Here, AvgPool2d is the average spectrum of the input spectral image, D1 and D2 are the first and second derivatives of AvgPool2d, respectively, all three being 440-dimensional vectors. The Sigmoid function scales the input to 0-1, the Linear function performs a non-linear transformation, and the ReLU function sets inputs less than 0 to 0. After another Linear transformation, the three 440-dimensional vectors are directly added. Finally, after a Sigmoid transformation projecting to the 0-1 interval, a pointwise multiplication operation is performed with the original spectral image, i.e., the i-th value is directly multiplied by the i-th input channel (i∈[0, 440]). The output dimension remains 440 channels, but after the improved attention mechanism of the SE layer, it includes channel importance information.

[0081] In Example 3, the first filtering layer 100, compared to Example 1 or Example 2, can perform the following processing: Each channel of the acquired spectral image is downsampled to an average value. For example, a two-dimensional average pooling operation (AvgPool2d) can be used to downsample each channel of the spectral image to an average value, and the downsampled image of all channels becomes the average spectrum. Then, after passing through two fully connected layers or a nonlinear transformation and improvement operation, a multi-dimensional vector is obtained. For example, if the original spectral image has 440 channels, after passing through two fully connected layers or a nonlinear transformation and improvement operation, three 440-dimensional vectors are obtained. The obtained vectors are then summed to obtain the weight of each channel. Finally, the weight is multiplied by each channel of the original image, and the output data includes the importance features of the channels. For example, the i-th value is directly multiplied by the i-th input channel (i∈[0, 440]), and the output dimension remains 440 channels.

[0082] The mathematical formula for the "nonlinear transformation" mentioned here is as follows: Output = input × weight T +bias

[0083] Where: input is the input tensor of size (N, in_features), where N is the size of the input and in_features is the number of input features; weight is the weight matrix of size (out_features, in_features), where out_features is the number of output features; bias is the bias vector of size (out_features), specifically, it can be represented as:

[0084] Where x is the input tensor, x ij Let w be the tensor in the i-th row and j-th column of the input matrix. j Let w be the j-th column tensor. From the expression, we know that the output tensor y... i That is, the sum of the dot product of all data in the i-th row of x and all data in the j-th column of w, plus the constant b.

[0085] In this embodiment, the "improved operation" can be, for example, the SG (Savitzjy Golay) smoothing algorithm, the MSC (Multiplicative Scatter Correction) multivariate scattering correction, the SNV (Standard Normalized Variate) variable standardization, the D1 (1st Derivatives) first derivative, the D2 (2nd Derivatives) second derivative, or a combination of first and second derivative operations.

[0086] For example, the method for combining first and second derivatives is as follows:

[0087] Among them, AvgP i Let D1 be the mean of the i-th channel image, and n be the number of channels in the spectral image. i Let D2 be the first derivative corresponding to the i-th channel. i Let be the second derivative of the i-th channel.

[0088] Example 4: In this embodiment, the first filter layer 100 is directly an SE layer.

[0089] In another implementation, the SE layer was modified.

[0090] Specifically, this improved operation preferably combines the operations of first and second derivatives, specifically,

[0091] Among them, AvgP i Let D1 be the mean of the i-th channel image, and n be the number of channels in the spectral image. i Let D2 be the first derivative corresponding to the i-th channel. i Let be the second derivative of the i-th channel.

[0092] To verify the inventiveness of the network model for identifying egg sex in this embodiment, hyperspectral images were collected every two days during the 0-14 day incubation period (days 0, 2, ..., 14). The spectral images of each day were converted into average spectral curves, and six preprocessing methods were applied. The results are shown in Figures 3 to 5. ORI (Original) indicates no preprocessing. SG (Savitzjjy Golag) smoothing algorithm, proposed by Savitzkg and Golag, is a polynomial smoothing algorithm based on the least squares principle, also known as convolutional smoothing. MSC (Multiplicative Scatter Correction) effectively eliminates spectral differences caused by varying scattering levels, thereby enhancing the correlation between the spectrum and the data. SNV (Standard Normalized Variate) standardization is used to correct spectral errors caused by scattering between samples. D1 (1st Derivatives) and D2 (2nd Derivatives) are also used.

[0093] After preprocessing the average spectrum, the RandomForest algorithm was used for gender prediction. The results showed that all six preprocessing methods reached their maximum accuracy on day ten. The original average spectrum, as well as the first and second derivatives, all achieved accuracies exceeding 0.9 on day ten, specifically 0.939, 0.923, and 0.931, respectively. The original spectrum showed the highest accuracy, a similar trend observed in the precision plots: the precision of the original, D1, and D2 methods were 0.931, 0.905, and 0.918, respectively, while the recall rate was the same for all three at 0.957. Therefore, based on the best results, the original spectral data was used for subsequent analysis of the day ten data.

[0094] In this embodiment, a comparison was made between using only the SE layer, using only the first derivative, using only the second derivative, and the SE layer after the improved operation. The results are shown in Table 4 below:

[0095] Table 4 Comparison of Results

[0096] The results show that the improved SE layer, with its channel attention mechanism considering the mean of the spectral image, achieves the best results when combining the first and second derivatives, with the highest accuracy (0.954), F1 score (0.958), and Kappa score (0.908). The first and second derivatives are more effective than the mean factor incorporated by traditional SE channel attention, indicating that the differences between channels contain more information about gender identification.

[0097] Example 5: The second filter layer can further extract image features and channel features of fertilized eggs and filter channel features. In this embodiment, the second filter layer 200 can further extract image texture information and channel information and reduce the channel features.

[0098] The second filter layer 200 in this embodiment, relative to embodiment 1 or embodiment 2, can perform the following processing: reduce the channel dimension by pointwise convolution; perform depthwise convolution on the reduced channels to extract the features inside each channel; perform pointwise convolution again to fuse the information between channels and obtain the output image of the reduced channels.

[0099] The second filtering layer can be implemented using conventional convolution methods. Taking classic full convolution and dilated convolution as examples, comparative experiments show that depthwise separable convolution not only achieves the best accuracy of 0.954, but also requires fewer parameters and fewer training parameters than full convolution and dilated convolution. This helps reduce the model's inference time and accelerates the prediction efficiency of eggs, as shown in Table 5 below.

[0100] Table 5. Comparison of performance and parameters of different convolution methods

[0101] As shown in Figure 6, it displays the 24th to 31st channels of the 32-channel image obtained by depthwise separable convolution. The image texture information extracted by the network model for identifying egg sex is different for each channel, containing potential information for identifying the sex of fertilized eggs. The network model for identifying egg sex can distinguish between male and female eggs through these textures, and can ultimately predict the sex of fertilized eggs.

[0102] Preferably, the second filter layer 200 is a depth-separable convolutional layer for optimal effect.

[0103] Example 6: This embodiment of the present invention provides a method for constructing a network model for identifying the sex of eggs, which includes at least two steps: screening feature bands and further extracting image features and channel features.

[0104] The operation of selecting image feature bands for fertilized eggs can be implemented using machine learning algorithms such as RF (Random Forest Simplified), CARS (Competitive Adapative Reweighted Sampling), SPA (Successive Projection Algorithm), and PCA (Principal Component Analysis) to identify average spectral curves.

[0105] Further extraction of image features and channel features of fertilized eggs can be achieved using conventional deep learning methods, such as depthwise separable convolution, full convolution, or dilated convolution.

[0106] Analysis revealed that the original hyperspectral or multispectral image contains images with multiple channels, which contain too much redundant information. It is difficult to extract effective information by using all channels as model input. Therefore, in this implementation, the multi-channel image is downsampled into an average spectral curve, that is, the average value of the image of each channel is taken, and the hyperspectral image is converted into a feature vector with the same dimension as the number of channels. If the original hyperspectral image contains 300 channels, the corresponding average spectral curve is a 300-dimensional vector.

[0107] A two-dimensional average pooling operation (AvgPool2d) can be used to downsample each channel of the spectral image to a mean value, and the downsampled image of all channels becomes the average spectrum. Then, after passing through two fully connected layers or a nonlinear transformation and improvement operation, a multi-dimensional vector is obtained. For example, if the original spectral image has 440 channels, after passing through two fully connected layers or a nonlinear transformation and improvement operation, three 440-dimensional vectors are obtained. These vectors are then summed to obtain the weight of each channel; finally, the weights are multiplied by each channel of the original image, and the output data includes the channel importance features.

[0108] In this embodiment, the image feature bands of fertilized eggs are selected using an SE layer. Preferably, in another embodiment, the SE layer is modified.

[0109] Specifically, this improved operation preferably combines the operations of first and second derivatives, specifically,

[0110] Among them, AvgP i Let D1 be the mean of the i-th channel image, and n be the number of channels in the spectral image. i Let D2 be the first derivative corresponding to the i-th channel.i Let be the second derivative of the i-th channel.

[0111] To verify the inventiveness of the network model for identifying egg sex in this embodiment, hyperspectral images were collected every two days during the 0-14 days of egg incubation (days 0, 2, ..., 14). The spectral images of each day were converted into average spectral curves and preprocessed using six methods. The results are shown in Figures 3 to 5.

[0112] Experimental comparisons revealed that the improved SE layer, which considers the mean of the spectral image through an attention mechanism, achieved the best results when combining the first and second derivatives, with all indicators being the best.

[0113] Further image and channel features are extracted, and channel features are filtered. This includes reducing the channel dimension through pointwise convolution; performing depthwise convolution on the reduced channels to extract features within each channel; and performing pointwise convolution again to fuse information between channels, resulting in an output image with reduced channels. For example, first, the channel dimension is changed to 32 through pointwise convolution; depthwise convolution is performed on the 32 channels to extract features within each channel; and pointwise convolution is performed again to fuse information between channels, resulting in a 32-channel output image. This step can be implemented using conventional convolution methods. Taking classic full convolution and dilated convolution as examples, comparative experiments show that depthwise separable convolution not only achieves the best accuracy of 0.954, but also requires fewer parameters and training parameters than full convolution and dilated convolution, which helps reduce the model's inference time and accelerates the prediction efficiency of eggs.

[0114] Example 7: After completing the network model construction process, the next key steps are to train, evaluate and optimize the network model.

[0115] The training process is an indispensable part of building a network model for identifying the sex of eggs. Effective training and adjustments are needed to ensure that the network model can better adapt to specific needs.

[0116] In one implementation, this can be accomplished through the following steps:

[0117] First, the preprocessed hyperspectral images are randomly assigned to the training and testing sets in a 2:1 ratio, while ensuring that the sex ratio of fertilized eggs in the two datasets is not too large to avoid bias in model classification. Then, appropriate training hyperparameters such as loss function, optimizer, learning rate, and batch size are selected to complete the initialization process.

[0118] The optimizer used during model training is the AdamW optimizer. Given the industrial needs of the egg-laying hen industry, and to minimize the error rate in identifying hens, a new loss function was designed, the calculation formula of which is as follows:

[0119] The loss function is used to fit and optimize the model: criterion = W1CrossEntropyLoss() + W2Waste_Ratio + W3Kappa + W4F1 WasteRatio=(P f *FP) / (P mn *TP)

[0120] Where CrossEntropyLoss is the cross-entropy loss, WasteRatio is the average cost of wasting a female egg when identifying a male egg, Kappa and F1 are the evaluation metrics used, and W is the average cost of identifying a male egg. i (i = 1...4) refers to the weight of the corresponding parameter; N is the number of samples, C is the number of varieties in the current category, and y ij It is the value of category j in the true label of sample i. FP is the predicted probability of category j in the probability distribution output by the model corresponding to sample i; FP is the number of female eggs identified as male eggs, TP is the number of male eggs identified as a pair, and P is the predicted probability of category j in the probability distribution output by the model corresponding to sample i. f P is the price coefficient for hatching hens. mn Let be the price coefficient of the male eggs selected in advance on day n.

[0121] After configuring the network model parameters, the next step is to train the network model. After the model makes a classification decision, the classification result is compared with the real label. The result is calculated using the loss function mentioned above, and the gradient is calculated using backpropagation. The AdamW optimizer is selected to update the network model parameters based on the gradient. The above process is repeated continuously to update and iterate the network parameters. Finally, the network gradually converges to the optimal performance.

[0122] Furthermore, research has revealed that compared to Convolutional Neural Networks (CNNs), the transformer attention mechanism in ViT lacks inductive bias, meaning it lacks prior knowledge. Therefore, its performance may be negatively impacted by smaller datasets. To compensate for this missing prior knowledge, this implementation employs transfer learning, specifically:

[0123] The weights of the model trained on the ImageNet-21k dataset are frozen, and fine-tuning is performed for downstream tasks to improve model performance.

[0124] During model training, we also tried some existing techniques, and the results showed that adding these techniques was beneficial to the final model performance, such as DropPath and Cosine Learning Rate Decay.

[0125] In addition to the techniques mentioned above, this invention also uses data augmentation during the model training phase to compensate for the lack of sample data. At the same time, data augmentation can also help the network model adapt to different data changes and noise to a certain extent, thereby improving the model's generalization ability. Compared with traditional RGB images, hyperspectral images have more channels, so the same operation is performed on images of all channels.

[0126] This process primarily uses five traditional data augmentation methods, including: Random Horizontal Flip, Random Rotation, Random Erasing, Random Gaussian Noise, and Random Brightness.

[0127] Random horizontal flip: The image is flipped horizontally. By specifying the probability parameter of the flip, the likelihood of the flip occurring can be controlled. This helps the model learn different orientations of symmetrical objects and increases data diversity.

[0128] Random Angle Rotation: Rotating the image at random angles simulates shooting from different angles, helping the model learn target features from different angles and improving the model's robustness to changes in target pose. After specifying the rotation angle, the pixel positions are subjected to the corresponding affine transformation according to the following formula: x rotate =x origin ×cos(θ rotate )-y origin ×sin(θ rotate ) y rotate =x origin ×sin(θ rotate )+y origin ×cos(θ rotate )

[0129] Among them, (x origin ,y origin ) and (x rotate ,y rotate ), where θ represents the pixel coordinates before and after the transformation by the formula. rotate The rotation angle is the clockwise rotation relative to the original image. This transformation is performed on all pixels to complete the rotation operation of the entire image.

[0130] Random erasure: Its main purpose is to introduce noise by randomly occluding a portion of the image, thereby enhancing the model's focus on local areas and improving generalization ability. Specifically, after specifying the erasure area ratio and the aspect ratio of the erased region, a rectangular area is randomly selected from the image, and the pixel values ​​within this area are set to predefined pixel values ​​(such as the mean or random noise). By introducing this lack of local information, the model is forced to rely on other available information for classification or regression tasks, thus enhancing the model's robustness and generalization ability. The parameter configurations for random horizontal flipping, random angle rotation, random erasure, random Gaussian noise, and random brightness are as follows: p turn =0.8,θ rotate =180°,scale=(0.02,0.05),ratio=(0.3-3.3)

[0131] Where, p turn Let θ be the probability parameter for all operations. rotate The range of random rotation angles is ±180°, scale is the proportion of the area to be erased, i.e., the erasure ratio is between 2% and 5% of the original image, and ratio represents the aspect ratio of the erased area, so the aspect ratio of the erased area can be set to any value between 0.3 and 3.3.

[0132] In addition, many other hyperparameters were specified for training the network model, including: epoch (number of training epochs), batchsize (batch size), learning rate (lr), optimizer (type of optimizer used during training), and patience (number of epochs required to control early stopping). These parameters were obtained by randomly searching for optimal parameters within a defined search space using the Hyperopt library: epoch = 120, batchsize = 64, optimizer = Adam, lr = 5e-4, patience = 30.

[0133] The loss function is defined as a combination of CrossEntropyLoss, WasteRatio, Kappa, and F1 as described above. The loss is calculated in each round according to the formula, and it is minimized during the continuous training process. This process is repeated until the network model gradually converges during gradient descent, and the performance and classification accuracy are gradually improved, resulting in the final network model for identifying the sex of eggs.

[0134] Example 8: To ensure the robustness of the network model for identifying the sex of eggs, three-fold cross-validation was used, with the mean of the three results serving as the final evaluation metric.

[0135] In this embodiment, the comprehensive evaluation indicators used are overall accuracy (OA), F1 score, kappa coefficient, etc., and their calculation formulas are as follows:

[0136] Where OA represents overall accuracy, AA represents average accuracy, TP (True Positive) is the number of samples correctly predicted as positive, TN is the number of samples correctly predicted as negative, FN (False Negative) is the number of samples incorrectly predicted as negative, and FP (False Positive) is the number of samples incorrectly predicted as positive.

[0137] Here, PE is the expected random consistency probability, which is the proportion of classification consistency achieved under random conditions; the Kappa coefficient takes into account the difference between expected accuracy and actual accuracy and is used to measure the consistency of the network model's classification.

[0138] Recall and Precision are the two metrics, respectively, while F1 takes into account both Recall and Precision and is the harmonic mean of the two.

[0139] To clearly identify the internal operating mechanism of the network model for identifying egg sex and to understand which image regions play a key role in sex classification, gradient-weighted class activation mapping (Grad-CAM) was used to visualize the process in a gradient manner, which helped in the evaluation process of the network model for identifying egg sex.

[0140] These gradient information represent the model's sensitivity to the target gender classification and can track the contribution of each pixel in the image to this category. Based on this gradient information, a heatmap is generated, in which each pixel is assigned a weight, reflecting its importance to the network model's classification decision.

[0141] Example 9 provides a non-destructive method for identifying the sex of eggs using spectral images, comprising the following steps:

[0142] S1: Collect sufficient fertilized egg samples and preprocess the fertilized egg samples.

[0143] Since this invention mainly addresses the sex classification problem of early chicken embryos, it is necessary to collect sufficient fertilized egg samples for subsequent experimental requirements.

[0144] To ensure the authenticity and persuasiveness of experimental data, interference from other environmental factors should be eliminated to avoid broken or rotten eggs. Secondly, ensure that experimental samples are incubated under suitable and identical environmental conditions, keep the egg surface dry, and place them in an incubator to complete the incubation process. In addition, after data collection, samples need to be quickly returned to the incubator to prevent affecting the survival rate and subsequent data collection.

[0145] Preferably, the present invention requires the use of hyperspectral technology to extract multi-band information, and then on this basis, the sex of the extracted eggs is identified and classified.

[0146] S2: Use hyperspectral technology to acquire hyperspectral images of fertilized eggs, ensuring a stable environment and continuous image acquisition.

[0147] The image acquisition process must be carried out using a high-precision hyperspectral camera, and it must be ensured that all conditions remain unchanged except for the sample.

[0148] In addition, due to the requirements of subsequent experiments, the data collection process needs to be carried out continuously, that is, from day 0 of incubation to day 14, hyperspectral images of fertilized eggs are collected every even-numbered day (i.e., day 0, day 2, day 4, etc.).

[0149] During image acquisition, environmental factors should be avoided as much as possible. If light leaks or low clarity occur, the image should be retaken immediately to ensure image quality.

[0150] During the acquisition process, a linear scanning method was used to obtain hyperspectral projection images of fertilized eggs. The preferred imaging scheme was to acquire large-head images using the transmission method. Specifically, the fertilized egg was positioned with the slender end facing upwards and the pointed end downwards. The light source was located directly below the egg. The distance between the egg and the spectral camera was adjusted according to the camera's focal length, so that the camera was positioned more than 30 centimeters above the egg. The acquisition was completed by transmitting light through the egg. The transmission method allows light to pass through the inside of the egg, undergoing sufficient absorption and reflection, to acquire information that is more relevant to the physicochemical properties.

[0151] Those skilled in the art will recognize that, in this embodiment, the placement of the fertilized egg with the fertilized end facing upwards and the tip downwards, with the light source directly below the egg, is not the only option. In other embodiments, a front view of the fertilized egg can be directly photographed, regardless of whether the fertilized egg is facing upwards or downwards.

[0152] In addition, the quality of hyperspectral images also depends on the configuration of various related parameters, so it is necessary to adjust and optimize parameters such as exposure time, platform movement speed, and light intensity before testing.

[0153] In addition, if the intensity distribution of the light source in the CCD camera used in the experiment is unstable, the black and white correction method can be used to correct the acquired hyperspectral image.

[0154] S3: Segment the region of interest from the background of the spectral image and filter the feature bands.

[0155] The segmentation of the region of interest includes: After color correction, it can be clearly seen that although multi-band spectral information was extracted from the spectral image, the large blank areas in the image were just sampled from the same black background, which hindered the subsequent recognition of the image.

[0156] Therefore, in order to remove the noise information interference around a large number of eggs in the original image, the experiment needs to first segment the region of interest from the background before proceeding with subsequent operations.

[0157] In this process, the R, G, and B bands of the RGB image are first merged. Then, computer image processing technology is used to further process the grayscale image. Finally, the HoughCircle detection method is used to obtain the region of interest in the image, thereby segmenting the spectral image of the region of interest from the original spectral image.

[0158] Observing the collected images, it can be seen that not the entire image contains the identification information of the egg. Therefore, the region of interest should be segmented from the background information first. The process of extracting the region of interest is shown in Figure 7 below.

[0159] As can be seen from Figure 7, the original spectral image contains a large amount of noise information. The RGB image is merged into bands of 638.82nm (R), 548.83nm (G) and 459.64nm (B). Then, the grayscale image is processed using computer vision technology and the range of the region of interest is directly obtained through the HoughCircle detection method.

[0160] Feature bands to be selected include:

[0161] In S2, raw spectral images were acquired using a spectral camera, but these spectral images were difficult to use as the raw input for subsequent network models that identify the sex of eggs.

[0162] Therefore, most research methods, such as Random Forest, choose to use the average spectrum instead of the overly large original multi-band image input. That is, by averaging all pixels in each channel image, a representative average spectrum can be calculated, thereby converting each original hyperspectral image into a 440-dimensional vector.

[0163] While the average spectrum method greatly facilitates the input of network models for identifying egg sex and saves computational resources for training such models, averaging all pixel values ​​in a single channel obviously results in unnecessary information waste.

[0164] To prevent information loss caused by averaging the spectrum, the proposed network model for identifying the sex of eggs (named EggFormer by the inventors in the experiment) can directly use the original multi-band spectral image as input for subsequent training.

[0165] The original spectral image contains 440 bands; however, a spectral image containing too many bands may make subsequent network model training difficult.

[0166] Therefore, various existing research methods attempt to analyze the characteristic importance of each band in order to extract the bands with greater contribution values, thereby achieving the dimensionality reduction effect of multi-band images.

[0167] The EggFormer model proposed in this invention adds an improved SE layer, which also achieves the effect of filtering important feature bands and thus reducing dimensionality. Compared with existing methods, the feature bands extracted by EggFormer not only have an accuracy equal to or surpass existing methods, but also extract fewer feature bands and achieve better results.

[0168] S4: Build the EggFormer model and train and evaluate it.

[0169] After completing data collection and processing, this embodiment builds and proposes an EggFormer model based on Vision Transformer Base / 16 to implement migration.

[0170] To better adapt to full image input, modifications were made to the network model. Specifically, an improved Squeeze-and-Excitation Layer and a depthwise separable convolution were added to the head of the network model.

[0171] The SE layer can utilize the channel attention mechanism to capture information about the correlation between potential channels in the average spectrum and assign greater weight to important channels; depthwise separable convolution can further extract image and channel features and reduce the number of image channels while maintaining a low number of parameters and computational cost.

[0172] Specifically, the network model for identifying egg sex employs an improved SE layer and depthwise separable convolution, enabling it to adapt to full image input rather than just average spectral input. This innovation allows the network model to directly predict the sex of early embryos using the original spectral image. Specifically, the SE layer captures the advantages of using average spectral data, focusing on the relationships between channels and combining the first and second derivatives of the average spectrum. Meanwhile, the depthwise separable convolution, based on the channel importance extracted by the SE layer, further extracts image texture information and channel information and filters channels, solving the problems of traditional deep learning being unable to be directly applied to spectral images, having slow convergence, and having many parameters.

[0173] The channel attention mechanism of the SE layer first downsamples each channel of the spectral image input to a mean Spectrum using the AvgPool2d layer. avg Then, the first-order derivative D1 and the second-order derivative D2 are calculated. After being passed through two fully connected layers (Linear and sigmoid) for appropriate adjustment and scaling, three 440-dimensional vectors are obtained, representing Output and Output respectively. avg Output d1 Output d2 These vectors are summed to obtain the weight of each channel. Then, the weights are multiplied by each channel of the original image to include channel importance features in the output data. The final output is called Output, calculated using the following formula: Spectrum avg =AvgPool2d(Input) Output d1 =Linear(Relu(Linear(sigmoid(D1(Spectrum avg Output avg =Linear(Relu(Linear(sigmoid(Spectrum avg Output d2 =Linear(Relu(Linear(sigmoid(D2(Spectrum avg Output = Sigmoid(Output) d1 +Output avg +Output d2 *Input

[0174] Where Input is the input spectral image, and AvgPool2d is the average of all pixels in the image for each channel. If the input has n channels, i.e., Spectrum... avgD1 is an n-dimensional vector; avg ) for Spectrum avg Taking the first derivative, i.e., subtracting the preceding digit from the following digit, yields an n-1 dimensional vector, which is then filled with zeros to form an n-dimensional vector; similarly, D2(Spectrum) avg To find the second derivative, i.e., D1(Spectrum) avg Subtracting the preceding digit from the following digit gives an n-2 dimensional vector, which is filled with zeros to make it n-dimensional.

[0175] In addition, Sigmoid is 1 / (1+ex), which scales the data to 0-1; Linear is wX+b, which performs a non-linear transformation on the input, where w is the multiplication coefficient and b is the bias; ReLU is the activation function, which aims to set numbers less than 0 in the input to 0.

[0176] The above refers to Spectrum avg D1 (Spectrum) avg D2 (Spectrum) avg The inputs are respectively used to obtain the output. avg Output d1 Output d2 The final Output is the product of the sum of the three vectors, scaled by a sigmoid function, and the original spectral image Input.

[0177] During training, the parameters of the fully connected layers are continuously updated along with the network model for identifying the sex of eggs to ensure that the importance weights of the channels are extracted correctly.

[0178] After the SE layer, the output data of the network model for identifying egg sex maintains the same dimensionality as the input data. However, some less important channels contain redundant information, and the data volume is too large to continue further processing. Therefore, this invention uses depthwise separable convolution (DWConv) to reduce image channels. Depthwise separable convolution combines depthwise (DW) and pointwise (PW) components to extract features, resulting in a lower number of parameters and computational cost compared to conventional convolution.

[0179] In depthwise separable convolution, one implementation first changes the channel dimension to 32 through pointwise convolution; then performs depthwise convolution on the 32 channels to extract features within each channel; finally, performs pointwise convolution again to fuse information between channels, resulting in a 32-channel output image.

[0180] The backbone network of the EggFormer model adopts the transferred Vision Transformer Base / 16 (ViT-Base / 16), which mainly consists of four parts: Patch Embedding, Position and Class Embedding, Encoder Layers, and MLP head.

[0181] The Patch Embedding layer segments the input image into 14x14 patches using convolutions with a kernel size and stride of 16. After convolution, the number of channels increases from 32 to 768, resulting in an output image with dimensions of 768x14x14. Subsequently, the width and length dimensions are flattened to 768x196, resulting in 196 patches of 768 dimensions. A class token is added before each patch, and a position embedding is applied to the entire image to incorporate positional information. This information is then fed into Encoder Layers containing 12 encoder layers to extract the data. Finally, the class tokens of all patches are extracted, projected directly onto the Linear class in the MLP head for binary classification, and then predicted using softmax.

[0182] S5: Based on the EggFormer model, key feature wavelengths are inferred and applied to the detection platform to detect the sex of eggs based on wavelength combinations.

[0183] Specifically, by explaining the internal mechanism of the model, namely the importance features of the input wavelength extracted by the channel attention mechanism of the SE layer, the key feature wavelengths are inferred. Based on the selected wavelengths, a reasonable combination is made to reduce the number of wavelengths while ensuring recognition accuracy, thereby reducing application costs and shortening the detection time. Subsequently, it is applied to the detection platform to identify fertilized eggs in batches.

[0184] The mainstream machine learning methods currently used for dimensionality reduction are as follows:

[0185] (1) Random Forest (RF), where each tree is a decision maker, and the final prediction is achieved through voting by multiple decision makers.

[0186] (2) Principal Component Analysis (PCA) maps the original data to a new coordinate system through linear transformation. The choice of the new coordinate system is based on maximizing the variance of the data or eigenvalue decomposition of the covariance matrix of the data.

[0187] (3) Successive Projections Algorithm (SPA) calculates correlation by projecting a vector representing a wavelength onto other wavelengths and comparing the projection sizes, and selects the combination of wavelength variables with the least redundant information and the least collinearity.

[0188] (4) Competitive Adaptive Reweighted Sampling (CARS) is based on adaptive reweighted sampling technology. Through iterative looping, it identifies the wavelength combination with the best prediction score.

[0189] The data after dimensionality reduction using the four methods described above were classified using least squares discriminant analysis (PLS-DA). The model employed 3-fold cross-validation to calculate the mean, and the optimal model was selected for interpretation and feature wavelength selection. As shown in Table 6 below (titled: Model Comparison Table), RF achieved the highest accuracy of 93.9%, while CARS performed the worst at 80.8%.

[0190] Table 6 Comparison of Multiple Models

[0191] By interpreting the four models, the top 10 wavelengths in terms of contribution value are listed in Table 7 below:

[0192] Table 7. List of the top 10 wavelengths ranked by contribution value of the four models.

[0193] Random Forest reduces the dimensionality of the input 440 wavelengths to 219 dimensions (with the sum of the contribution values ​​of the extracted wavelengths set to >0.98), meaning the total feature importance of the 219 wavelengths accounts for 98%. Among them, 9 wavelengths account for more than 2.5%, with 712.76nm being the wavelength with the largest contribution value of 4.42%. The top ten wavelengths with the highest proportions are distributed between 698nm and 765nm. Furthermore, as shown in Figure 8, the visualization of the wavelength contribution of RF, wavelengths with contribution values ​​greater than 0.05 are distributed between 600-900nm, which are in the visible and near-infrared regions.

[0194] Regarding principal component analysis, the sum of the contributions of the first three principal components (PC1–PC3) exceeds 99%, at 95.6%, 3%, and 1.1%, respectively. Based on the absolute values ​​of the eigenvalues ​​of the wavelengths in each principal component, the values ​​of the corresponding channels are multiplied by the eigenvalues ​​to plot the principal component maps PC1, PC2, and PC3 (see Figure 9). Analysis shows that PC1 displays the spectral image of the egg. Because the radius of the egg's ROI was expanded by 10 pixels during ROI segmentation to retain more information, PC1 in Figure 9 clearly shows only a small ring of noise around its perimeter. The noise in PC2 is already quite noticeable, while the noise particles in PC3 are mixed with the egg area; this noise is mainly generated during camera scanning. The top-10 wavelengths of PC1 are distributed between 702nm and 714nm, and their eigenvectors are not significantly different.

[0195] The Continuous Projection Algorithm (SPA) provides 11 candidate wavelengths and selects 10 as the final wavelengths, while the Competitive Adaptive Reweighted Sampling (CARS) algorithm selects 25 feature wavelengths. The wavelength ranges selected by the two algorithms are similar, with most falling between 400-600 nm and a few between 800-1000 nm.

[0196] Because machine learning analyzes the average spectrum and does not include the image texture information of the egg, it inevitably loses a lot of useful information. To verify the superiority of the EggFormer model and the effectiveness of machine learning in selecting feature bands, images from all channels and images reconstructed from the selected feature wavelengths were used as inputs. The publicly available ViT-Base model, the ViT-Base model based on Img21K transfer, and the EggFormer model were compared. The experimental results are shown in the "Model Comparison Table".

[0197] When using the ViT-Base model, the accuracy was lowest (0.924) when inputting all bands, indicating that the ViT model is deficient in handling large-dimensional data. Although the number of remaining bands (10) after SPA filtering was less than that of CARS (10), the accuracy was lower, possibly because some effective information was lost during dimensionality reduction. CARS has advantages in both the number of feature wavelengths selected and the accuracy, with the highest accuracy of 0.939. PCA-PC1 filters out 267 wavelengths with a feature vector ratio of 0.98 from the principal component 1 extracted by PCA, and its recognition effect is on par with RF, with the number of feature bands also on the same order of magnitude. The above phenomena can also be observed when using the models ViT-Img21K and EggForme.

[0198] First, without pre-trained weights, Vit's accuracy is only on par with RF. However, it's clear that after loading pre-trained weights, Vit's overall accuracy improves, increasing from 0.924 to 0.939 for full-band input. However, the model's parameters also become excessively large with the increase in the number of bands, and the training parameters increase exponentially. In contrast, the EggFormer model, using a combination of channel attention in the SE layer and PDConv, effectively solves the problem of excessive channel count. It achieves an accuracy of 0.954 for full-band input, and its F1 and kappa scores are the best among all models.

[0199] In addition, EggFormer has an advantage in the number of parameters compared to ViT-Base and ViT-Base-21K, with training parameters around 6.5M and total parameters around 91.5M.

[0200] Interestingly, after filtering by RF, PCA, and CARS bands, the EggFormer model performed better, indicating that EggFormer did indeed uncover more potential information, and that spectral images could obtain more effective information than average spectra.

[0201] Meanwhile, when the number of bands is small, EggFormer's results are lower than ViT-Base-21K's when SPA is used as input. This may be related to the fact that the number of bands is reduced by 3 / 4 when channel attention is applied to the SE layer, which limits the accuracy.

[0202] In order to extract the high-weight feature bands from the EggFormer model, the attention channel mechanism of the SE layer of EggFormer was further analyzed, the output of the out layer was extracted and normalized, and the result is shown in Figure 10.

[0203] The wavelength contribution values ​​shown in Figure 10 are distributed across the entire wavelength band. To filter out a few effective bands, a certain sampling interval is set, and the wavelengths within each interval are uniquely selected from the largest to the smallest contribution value. When the sampling interval is set to a factor of 440 (1, 2, 4, 5, 10, 20, 22), the accuracy of 0.946 is maintained for the four-band inputs of 945.354nm, 762.407nm, 409.377nm, and 644.587nm. Meanwhile, with 22-band input, the EggFormer model maintained an accuracy of 0.954, corresponding to the following bands: 945.354, 762.407, 409.377, 644.587, 888.39, 399.991, 618.669, 578.621, 728.801, 954.091, 562.989, 470.638, 1004.87, 904.482, 520.684, 779.97, 718.592, 441.857, 840.049, 494.166, 670.619, and 829.789 (in nm).

[0204] To clarify the internal operating mechanism of the model, we used GradCam (gradient-weighted class activation map) to visualize it in terms of gradients, as shown in Figures 11 to 14. We used heatmaps to understand the model's areas of interest, with redder colors indicating higher levels of interest.

[0205] When we select the last normalization layer of the encoder layer, we can see from the predicted heatmaps of the two example female and male eggs that the EggFomer model focuses primarily on the inside or edge of the egg.

[0206] Taking the prediction of female eggs in Figures 11 and 12 as examples, the left side shows the RGB three-channel image, which is the result directly observed by the naked eye. The right side is the heatmap that the model focuses on; the redder the color, the higher the attention, and the greater the influence of that area on the model's prediction result. It can be seen that when a hyperspectral image of an egg is input, when the EggFormer model identifies and classifies it as a female egg, the EggFormer model focuses on the brighter areas of the egg. For example, in Figure 12, the central part of the female egg is significantly brighter.

[0207] Taking the prediction of male eggs in Figures 13 and 14 as an example, when the EggFormer model identifies male eggs, it focuses on the darker areas at the edges or inside the egg. In fact, the average spectral curve of the eggs also shows that the peak value of the average spectral curve of male eggs is indeed lower than that of female eggs.

[0208] The EggFormer model can extract potential information from spectral images, enabling sex determination of early egg embryos using fewer wavelengths and facilitating applications in production. The reduction in the number of wavelengths helps improve identification efficiency and lower costs in industrial applications, thereby increasing economic returns.

[0209] This embodiment also provides a system configured for non-destructive identification of the sex of eggs, which necessarily includes a memory capable of storing computer-readable instructions and a processor capable of executing computer-readable instructions.

[0210] The processor, when executing computer-readable instructions, is configured to: (1) segment the region of interest from the acquired spectral image. Segmenting the region of interest here includes merging the R, G, and B bands of the spectral image, selecting the egg range and obtaining a grayscale image, and further processing the grayscale image to segment the spectral image of the region of interest from the original spectral image. (2) Use the EggFormer model for identification, as described in Examples 1-5, which will not be repeated here. (3) Infer key feature wavelengths based on the EggFormer model, and detect the sex of the egg based on wavelength combinations.

[0211] In summary, this invention designs a novel network architecture, the EggFormer model, which can directly use the original image spectrum as output, overcoming the drawbacks of the average spectrum method and improving upon the shortcomings of deep learning methods. Compared with existing methods, it has smaller errors and higher accuracy. Using hyperspectral imaging for non-destructive testing is cost-effective and fast. Furthermore, the EggFormer model can effectively handle the high dimensionality of hyperspectral data, extracting image texture information not included in the average spectrum. Image classification can quickly and accurately determine the gender of a target, meeting the needs of production personnel. Automated recognition is achieved using computer equipment; only the necessary hardware is needed to capture the spectral image of the target, and accurate classification results are provided after uploading, resulting in low human intervention and a high degree of automation. Visualizing the classification process using heatmaps, which match the characteristics of the extracted spectral images of different genders, demonstrates the robustness of the model method.

[0212] Compared with existing technologies, this invention can accurately determine the sex of early chicken embryos based on uploaded hyperspectral images. It outperforms existing algorithms in terms of accuracy, recall, and Kappa value, effectively utilizing deep neural networks to accomplish this task. Furthermore, the identification process is primarily automated by the device, significantly reducing labor and time costs.

[0213] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A network model for identifying the sex of eggs, characterized in that: include, The first filter layer (100) capable of screening spectral image bands for characteristics of fertilized eggs: and, A second filter layer (200) is capable of further extracting image features and channel features of fertilized eggs.

2. The network model for identifying the sex of eggs as described in claim 1, characterized in that: The first filter layer (100) captures information about the correlation between potential channels in the average spectrum of the spectral image through a channel attention mechanism, and assigns greater weight to important channels.

3. The network model for identifying the sex of eggs as described in claim 2, characterized in that: The first filter layer (100) is capable of performing the following processes: Each channel of the spectral image is downsampled to a mean: By performing improvements, a multi-dimensional vector is obtained; The resulting vectors are summed to obtain the weight of each channel; The weights are multiplied by each channel of the original spectral image to include channel importance features in the output data.

4. The network model for identifying the sex of eggs as described in any one of claims 1 to 3, characterized in that: The first filter layer (100) is an SE layer.

5. The network model for identifying the sex of eggs as described in claim 4, characterized in that: Improvement operations are performed on the SE layer.

6. The network model for identifying the sex of eggs as described in claim 3 or 5, characterized in that: The improved operation is the operation of performing first and second derivatives, specifically... Among them, AvgP i Let D1 be the mean of the i-th channel image, and n be the number of channels in the spectral image. i Let D2 be the first derivative corresponding to the i-th channel. i Let be the second derivative of the i-th channel.

7. The network model for identifying the sex of eggs as described in claim 1, 2, 3 or 5. The second filtering layer (200) is capable of further extracting image texture information and channel information, and reducing the channel features.

8. The network model for identifying the sex of eggs as described in claim 7, characterized in that: The second filter layer (200) is capable of performing the following processes: The channel dimension is reduced by using pointwise convolution: Perform depthwise convolution on the reduced channels to extract the image features within each channel: Then, perform pointwise convolution again to fuse the information between channels, resulting in an output image with fewer channels.

9. The network model for identifying the sex of eggs as described in claim 1, 2, 3, 5, or 8, characterized in that: The second filter layer (200) is a depth-separable convolutional layer.

10. A method for constructing a network model to identify the sex of eggs, characterized in that: include, Screening for image feature bands of fertilized eggs; and, Further extract image features and channel features of fertilized eggs.

11. The method for constructing a network model for identifying the sex of eggs as described in claim 10, characterized in that: The image feature bands for screening fertilized eggs include, Each channel of the spectral image is downsampled to a mean; By performing improvements, a multi-dimensional vector is obtained; The resulting vectors are summed to obtain the weight of each channel; The weights are multiplied by each channel of the original spectral image to include channel importance features in the output data.

12. The method for constructing a network model for identifying the sex of eggs as described in claim 10 or 11, characterized in that: The image feature bands for screening fertilized eggs are implemented through the SE layer.

13. The method for constructing a network model for identifying the sex of eggs as described in claim 12, characterized in that: Improvement operations are performed on the SE layer.

14. The method for constructing a network model for identifying the sex of eggs as described in claim 11 or 13, characterized in that: The improved operation is the operation of performing first and second derivatives, specifically... Among them, AvgP i Let D1 be the mean of the i-th channel image, and n be the number of channels in the spectral image. i Let D2 be the first derivative corresponding to the i-th channel. i Let be the second derivative of the i-th channel.

15. The method for constructing a network model for identifying the sex of eggs as described in claim 10, 11, or 13, characterized in that: The further extraction of image features and channel features, and the filtering of channel features, includes, The channel dimension is reduced by using pointwise convolution: Perform depthwise convolution on the reduced channels to extract features within each channel; Then, perform pointwise convolution again to fuse the information between channels, resulting in an output image with fewer channels.

16. The method for constructing a network model for identifying the sex of eggs as described in claim 10, 11, or 13, characterized in that: The further extraction of image features and channel features of fertilized eggs is achieved through depthwise separable convolutional layers.

17. The method for constructing a network model for identifying the sex of eggs as described in claim 10, 11, or 13, characterized in that: Training and evaluation of the network model.

18. The method for constructing a network model for identifying the sex of eggs as described in claim 17, characterized in that: The training, This includes using a loss function to fit and optimize the model, criterion = W1CrossEntropyLoss() + W2Waste_Ratio + W3Kappa + W4F1 WasteRatio=(P f *FP) / (P mn *TP) Where CrossEntropyLoss is the cross-entropy loss, WasteRatio is the average cost of wasting a female egg when identifying a male egg, Kappa and F1 are the evaluation metrics used, and W is the average cost of identifying a male egg. i (i = 1...4) refers to the weight of the corresponding parameter; N is the number of samples, C is the number of varieties in the current category, and y ij It is the value of category j in the true label of sample i. FP is the predicted probability of category j in the probability distribution output by the model corresponding to sample i; FP is the number of female eggs identified as male eggs, TP is the number of male eggs identified as a pair, and P is the predicted probability of category j in the probability distribution output by the model corresponding to sample i. f P is the price coefficient for hatching hens. mn The price coefficient of the male eggs selected in advance on day n; After the classification result is obtained through the judgment of the optimization model, the true label is compared with the classification result, the result is calculated using the loss function, and the gradient is calculated using backpropagation.

19. The method for constructing a network model for identifying the sex of eggs as described in claim 18, characterized in that: The assessment is performed using the following formula. Where OA represents overall accuracy, AA represents average accuracy, TP is the number of samples correctly predicted as positive, TN is the number of samples correctly predicted as negative, FN is the number of samples incorrectly predicted as negative, and FP is the number of samples incorrectly predicted as positive. Where PE is the expected random consistency probability; Recall and Precision are respectively the recall rate and precision rate.

20. A method for non-destructive identification of the sex of eggs, characterized in that: include, Acquire spectral images of fertilized eggs; Segment the region of interest from the acquired image; Construct the network model as described in any one of claims 1 to 9; The key feature wavelengths are inferred based on the network model, and the sex of the egg is detected based on the wavelength combination.

21. The method for non-destructive identification of egg sex as described in claim 20, characterized in that: The process of segmenting the region of interest from the acquired image includes: The image is merged using R, G, and B bands, and the range of the egg is selected to obtain a grayscale image; The grayscale image is further processed to segment the spectral image of the egg region from the original spectral image.

22. A system configured for non-destructive identification of the sex of eggs, characterized in that: include, Memory, which stores computer-readable instructions; and, A processor, configured to execute computer-readable instructions, is configured to: Segment the region of interest from the acquired image; The network model described in any one of claims 1 to 9 is adopted: The key feature wavelengths are inferred based on the network model, and the sex of the egg is detected based on the wavelength combination.

23. The system for non-destructive identification of egg sex as described in claim 22, characterized in that: The process of segmenting the region of interest from the acquired image includes: The image is merged using R, G, and B bands, and the range of the egg is selected to obtain a grayscale image; The grayscale image is further processed to segment the spectral image of the egg region from the original spectral image.

Citation Information

Patent Citations

  • Attention mechanism CNN-based 5-day and 9-day incubated egg embryo image classification method

    CN110309880A

  • Egg freshness detection method based on Inception module and Attention mechanism

    CN113012244A

  • Network model, construction method, and egg gender lossless identification method and system

    CN118470540A

  • Hatching egg non-destructive inspection device and hatching egg inspection program used for the same

    JP2023125036A

Cited By

  • Method and system for rapidly determining key nutritional ingredients of raw materials of feed for laying hens

    CN121811263A