1. Introduction
The routine culling of day-old male chicks represents a major ethical challenge in modern poultry production, affecting millions of animals annually [
1]. This has motivated the development of early-stage, non-invasive sex identification methods that can be applied before hatching.
Several approaches have been proposed, including spectroscopic techniques, molecular analysis, and hormone-based methods, many of which achieve high accuracy but are invasive, costly, or limited to later stages of incubation [
2,
3,
4]. More recently, machine vision has emerged as a promising non-invasive alternative, capable of identifying sex at early stages based on embryonic blood vessel patterns [
5,
6,
7]. Embryonic blood vessels become clearly visible around days 4–6 of incubation, making this stage suitable for image-based analysis.
Previous studies have demonstrated encouraging results using deep learning models, with reported accuracies approaching 90% under controlled conditions [
5]. However, these studies typically rely on homogeneous datasets collected in laboratory or industrial hatchery environments, where variability in eggshell characteristics, lighting conditions, and image quality is limited. As a result, the generalizability of such models to more realistic settings remains largely untested under more variable, real-world conditions.
In addition, while embryonic development is inherently a temporal process, the potential benefit of incorporating temporal information into machine vision-based sex identification has received limited attention in previous work.
In this study, we address these limitations by investigating early-stage sex identification under more realistic conditions. Specifically, this work (i) uses a heterogeneous dataset collected from multiple chicken breeds under real farm conditions, (ii) evaluates the impact of temporal information using a hybrid convolutional neural network–recurrent neural network (CNN–RNN) approach, and (iii) assesses the generalizability of machine vision models beyond controlled experimental environments.
2. Materials and Methods
This section is organized into four subsections: Data Collection, Built System for Data Collection, Preprocessing, and Machine Learning (ML) Models. Together, these describe the acquisition of the dataset, the technical setup used for imaging, the data preparation steps, and the modeling strategies applied in this study.
2.1. Data Collection
The study was conducted at the Ekebo Fjäderfä farm [
8] over an eight-week period in 2024. Three breeds were included: Welsumer, Cream Legbar, and a crossbreed between Smålandshönan and Cream Legbar. These breeds were selected because their sex-specific plumage patterns facilitate post-hatch sex identification, as illustrated in
Figure 1.
Welsumer chickens, originating from the Netherlands, produce dark brown eggs, often with speckled shells (
Figure 2, right). They lay approximately 230 eggs per year, with an average egg weight of around 60 g. Female chicks can typically be identified by a more pronounced stripe near the eye and a clearer head pattern. Cream Legbar chickens, developed in Great Britain as a crossbreed, produce eggs with a characteristic blue tint (
Figure 2, left). On average, they lay about 250 eggs per year, with each egg weighing 55–60 g. Sex differentiation in this breed is possible based on plumage, as males display much lighter coloring compared to females.
The crossbreed used in this study, developed at Ekebo Fjäderfä farm, incorporates the Swedish Smålandshöna breed, which originates from the Leghorn and Rhode Island Red. The eggs of this crossbreed resemble those of the Cream Legbar, and male chicks can be identified by the same plumage characteristics as in the Cream Legbar.
For the experiments, the eggs were incubated using a Brinsea OvaEasy 190 Advance incubator (Brinsea Products Ltd., Weston-super-Mare, UK) [
9] in batches of 25–50, each marked with a batch number and egg ID on the blunt end. To preserve natural conditions, the eggs were not cleaned prior to incubation. The incubator was set to 37.7 °C with 40% relative humidity and rotated every 60 min. The temperature settings were selected based on recommendations from previous studies. In total, eight batches were incubated for this investigation.
Images were captured on days 4, 5, and 6 of incubation, which is one day later than in most comparable studies, where day 3 is typically used as the first observation point [
5,
6,
10]. This adjustment was necessary because, in the Welsumer eggs, neither the embryo nor the vascular structures were clearly visible on day 3. Since the analysis also considered temporal aspects using recurrent neural networks (RNNs), the eggs were photographed at 24 h intervals with a precision of ±60 min.
During image acquisition, approximately one-third of each batch was temporarily removed from the incubator. This procedure reflects the natural behavior of brooding hens, which leave their nests intermittently during incubation [
11]. To minimize the risk of cooling and maintain appropriate thermal conditions, the eggs were placed on a heating mat while being imaged.
Figure 3 illustrates representative images from days 4, 5, and 6, highlighting the progressive development of the embryos and their vascular structures.
The eggs used in this study varied in quality, as they were obtained from a small-scale farm rather than an industrial breeding facility. Some eggs displayed noticeable light and dark shell spots. Approaching the expected hatching day (day 21 of incubation), approximately one third of the eggs from each batch were removed from the incubator for imaging. To maintain appropriate thermal conditions during this process, the eggs were placed on a heating mat. For accurate labeling, all eggs were transferred to nylon mesh bags on day 21 and marked with their respective batch number and egg ID. The sex of the chicks was determined at hatching (day 21) by trained personnel at Ekebo Fjäderfä farm and subsequently documented by the authors.
In total, 271 eggs were incubated across eight batches. Eggs that showed no signs of development were excluded from further observation, and 43 eggs were not assigned a definitive sex due to incomplete development. Eggs without verified sex labels or without complete image series across all three days were omitted from the final dataset. After this filtering, 208 eggs with 624 images (from an initial 790 captured images) remained for analysis. The distribution of incubated eggs across the three breeds is presented in
Table 1.
2.2. Built Camera Equipment
To capture images during incubation, a prototype imaging system was developed. The system consisted of three main components: a camera, an egg mount, and an LED array for illumination (
Figure 4). The camera was connected to a Raspberry Pi, which transmitted the images to a computer for storage in a database. The database included information on breed, timestamp, and batch. In addition, the Raspberry Pi was used to receive control commands and forward the acquired images to the computer for subsequent analysis.
The plastic components of the imaging device were fabricated using 3D printing with polylactic acid (PLA). The external dimensions of the device were 86 × 172 mm. The distance from the egg holder to the light source was 56 mm, and the distance between the egg holder and the camera lens was 86 mm. The egg holder was designed with an egg-shaped opening to ensure consistent placement of the eggs during image acquisition. Egg positioning was partially standardized using this holder, which helped maintain a similar placement between images. However, egg orientation, including rotation and horizontal alignment, was not strictly controlled across all samples. While images within the same acquisition session were generally consistent, variations occurred between sessions, introducing additional variability in the dataset. For image acquisition, a Raspberry Pi High Quality Camera was connected to a Raspberry Pi Zero 2W (Raspberry Pi Ltd., Cambridge, UK) together with an LED array. The array consisted of a current-dimmable circuit with 12 green LEDs (GT PSLR31.13, OSRAM Opto Semiconductors GmbH, Regensburg, Germany) providing a total luminous flux of 2112 lumens and emitting light at a wavelength of 540 nm. As noted in previous studies, exposure to green light during incubation can promote favorable embryonic development [
12,
13,
14].
2.3. Preprocessing
Several challenges needed to be addressed during preprocessing, particularly the issue of unbalanced lighting resulting from variations in eggshell characteristics. Image preprocessing was carried out using OpenCV (version 4.9.0) and Scikit-image (version 0.23.2).
The main preprocessing workflow, illustrated in
Figure 5, comprised four steps:
Resizing and padding;
Background removal;
Histogram matching;
Noise reduction and contrast-limited adaptive histogram equalization (CLAHE) [
15].
The first step was to resize and pad the images to match the input dimensions of the pretrained models described later in this study. Background removal was then performed using a segmentation model specifically trained for this task.
To account for variations in eggshell appearance, histogram matching was applied. Some eggs exhibited an orange hue, while others appeared dark green; in addition, certain images were slightly overexposed, whereas others were underexposed. To address these differences, the CIELAB color space was employed, which separates the image into L* (luminance), a* (green–red), and b* (blue–yellow) components. Histogram matching was then used to standardize image color and lighting conditions.
Many eggs displayed significant noise in the form of small dark spots or areas where light penetrated the shell unevenly. To mitigate this effect, morphological opening and closing operations were applied, followed by a median blur filter. After noise reduction, CLAHE was applied at a smaller scale to enhance vessel visibility while limiting the amplification of residual noise [
15]. Because of the high noise levels in some images, CLAHE could not be applied directly, as it would otherwise amplify noise to the same degree as meaningful features.
Since parts of the dataset contained severe noise in the form of light and dark spots that obscured the embryo, a cleaning step was performed (
Figure 6). Images in the top row of the figure illustrate examples that were excluded, while the bottom row shows representative images that were retained in the cleaned dataset.
As shown in
Table 2, a total of 21 image series (corresponding to 72 images) were removed because the embryos were obscured by dark or light spots. This filtering was conducted through manual visual inspection. Only eggs with complete image series were included in the machine learning analysis. Although some images in the dataset still contained noise, several were sufficiently clear for use, as illustrated in
Figure 6. Notably, data collected from the Welsumer breed showed a particularly high level of noise.
2.4. ML Models
The ML models were implemented in TensorFlow (version 2.13.0) [
16] with the Keras API [
17]. Image preprocessing was carried out using OpenCV (version 4.9.0) [
18] and Scikit-image (version 0.23.2) [
19]. To analyze both the spatial and temporal features of the image sequences, a combination of convolutional neural network (CNN) backbone models and a recurrent neural network (RNN) was employed. Given the relatively small dataset, pretrained models with fewer parameters were selected to reduce the risk of overfitting and to leverage transfer learning from large-scale image datasets. The CNN backbones were initialized pretrained on ImageNet [
20] and subsequently fine-tuned to the dataset. The models evaluated were ResNet50V2 [
21], InceptionV3 [
22], and DenseNet121 [
23], containing approximately 25.6, 23.9, and 8.1 million parameters, respectively, as illustrated in
Figure 7. Multiple CNN architectures were evaluated to assess the impact of model choice on performance, rather than to combine them into a single model. Multiple CNN architectures were used to evaluate model performance across different backbone designs rather than combining them into a single predictive model.
Data augmentation was applied during training to improve model robustness. The augmentation pipeline included random horizontal and vertical flips, rotations, zooming, and translations, introducing variability in image orientation and scale. This was particularly relevant given the variability in egg orientation.
Eggs from the different breeds varied in shell color and surface characteristics. In particular, the sex of the Welsumer breed was more difficult to determine accurately based on plumage. To address this, two datasets were created: one including all three breeds and another excluding the Welsumer eggs. All three baseline models were evaluated on both datasets.
Following the evaluation of the baseline CNNs, each model was extended with an RNN in a cascaded architecture, similar to previously proposed CNN–RNN frameworks. This approach was motivated by earlier studies that highlighted the temporal dimension of embryonic development as a promising avenue for future research. The final feature map output from the backbone CNNs was processed using a GlobalAveragePooling2D layer. For InceptionV3 and ResNet50, an additional bottleneck 1 × 1 Conv2D layer was applied to ensure dimensional consistency.
In this design, the CNN extracted feature maps consisting of 1024 features, which were then provided to the RNN as a sequence of three feature maps, yielding a total of 3072 features.
To evaluate the effectiveness of the different backbone models in combination with the RNN, identical parameters were applied to the CNN backbones, while the RNN hyperparameters were tuned empirically during preliminary experiments. The dataset was divided into 70% for training, 15% for validation, and 15% for testing. The split was performed at the egg level to ensure that images from the same egg were not present in multiple subsets.
Model performance was evaluated using accuracy, confusion matrix analysis, F1-score, and the Matthews Correlation Coefficient (MCC).
4. Discussion
This study explored the feasibility of early-stage chicken egg sex classification using convolutional neural networks (CNNs) and a hybrid CNN-RNN architecture. While several models achieved accuracies around 60%, the positive MCC value (≈0.31) further supports that the best-performing model captures meaningful patterns in the data, although overall performance remains modest compared to prior literature. This outcome necessitates a deeper examination of the dataset, methodology, and implications. The results should be interpreted as exploratory and reflect the difficulty of the task under realistic conditions.
The best-performing model was the InceptionV3 CNN trained on Day 6 images, reaching an accuracy of 71.4% and an F1 score of 67.9%. However, incorporating temporal information via RNNs did not improve performance—in fact, the CNN-RNN models performed worse on average. This suggests that for early-stage imaging (days 4–6), static spatial features may be more informative than temporal progression. The limited size and quality of the dataset, including noise from natural egg variability and inconsistent lighting conditions, likely constrained model performance. Although a controlled light source with a fixed wavelength was used during image acquisition, variations in eggshell color and structure affect how light is transmitted through the egg. Darker or more heterogeneous shells absorb and scatter more light, reducing the visibility of embryonic structures and increasing image variability. This effect was particularly noticeable for the Welsumer breed, which exhibited higher noise levels due to its darker and more variable shell appearance. Given these constraints, the results should be interpreted as exploratory, reflecting the feasibility of the approach under realistic and heterogeneous conditions rather than optimized performance. Collecting larger, more balanced datasets and performing external validation remain important directions for future work.
Despite the inclusion of multiple breeds, removing Welsumer from the dataset did not significantly alter accuracy, suggesting the classification task may be generalizable across breeds. However, conclusions remain tentative due to the relatively small sample sizes and limited number of complete image series. A more detailed analysis of potential breed-related differences, for example using principal component analysis (PCA), was not feasible due to the limited sample size per breed and is left for future work. The dataset is slightly imbalanced, with more male than female samples, which may influence model performance. However, the confusion matrix indicates a relatively balanced classification performance between the two classes for the best-performing model.
Compared to existing studies on in ovo sex determination [
2,
5,
6,
10,
24], this study introduces a unique dataset that broadens the scope of previous research. Most prior work has focused on commercial breeds and single-day imaging; in contrast, our dataset includes heritage and crossbred chickens—specifically Welsumer, Cream Legbar, and a Cream Legbar/Smålandshöna cross—adding valuable genetic and eggshell variability. Additionally, images were collected on three consecutive days (days 4, 5, and 6), enabling temporal analysis via CNN-RNN architectures. While this temporal modeling did not improve performance over baseline CNNs, the dataset structure offers a rare opportunity to study embryonic development over time.
The imaging setup, based on a Raspberry Pi camera and green LED array, was low-cost and highly replicable, making the approach feasible for decentralized or small-scale hatcheries. Importantly, data were collected under near-commercial incubation conditions, and chick sex was determined post-hatch through plumage characteristics, ensuring both ethical compliance and labeling accuracy. These features position the dataset as a useful resource for future research aiming to generalize sex classification methods across breeds, imaging conditions, and temporal scales.
Our results are comparable to those of a recent Turkish study that used ResNet and Inception models on a similarly sized dataset, achieving 67.6% accuracy with ResNet and 75.5% with Inception [
6]. In contrast, our hybrid CNN-RNN model achieved a best-case accuracy of 66.7%, with an average of 62.7% on the breed-excluded subset. These differences may stem from variations in preprocessing, image clarity, and network tuning. Other studies reporting higher accuracies (up to 89.0%) often employed larger, more controlled datasets or advanced image processing, such as hyperspectral imaging or morphological analysis of blood vessels [
5,
10,
14,
24,
25,
26,
27].
The early, non-invasive nature of this approach remains promising despite its current limitations. The ability to classify sex as early as day 4, without opening the egg or affecting viability, aligns well with emerging EU regulations banning chick culling [
1,
2]. While accuracy must improve to meet commercial standards, our findings reinforce machine vision as a viable and humane alternative worth further development. Previous studies suggest that embryonic blood vessel development may differ between sexes due to variations in metabolic activity and growth dynamics during early incubation. These differences may manifest as variations in vessel density, branching patterns, and spatial organization, which can be captured through image-based analysis. While the precise biological mechanisms remain incompletely understood, this provides a plausible basis for using vascular patterns as input features for sex classification [
5].
Future research should focus on improving image quality and dataset size. This could include automated image acquisition systems to ensure consistent lighting, as well as multispectral or hyperspectral imaging to enhance vessel contrast. Additionally, exploring real-time object detection algorithms, such as YOLOv7 variants [
28], could enable practical deployment in hatchery environments. Finally, narrower sampling intervals between imaging days may allow more effective use of temporal data, potentially enhancing RNN-based performance.
In summary, while the temporal aspect did not yield performance improvements in this study, the baseline CNN model showed encouraging results. With a cleaner and larger dataset, and continued refinement of model architectures, early-stage non-invasive sex identification via machine vision remains a compelling avenue of research.
5. Conclusions
This study investigated whether incorporating temporal information—via multi-day image series and a CNN-RNN hybrid architecture—could improve early-stage, non-invasive sex identification in chicken eggs. Despite the novelty of this approach, results showed that the baseline CNN model outperformed the hybrid model, achieving up to 71.43% accuracy compared to 67.85% for the CNN-RNN. The modest performance is likely due to the small dataset size and considerable noise in the image data.
A distinctive contribution of this work lies in its use of heritage and crossbred chicken lines, rather than industrial broilers, and the collection of longitudinal image data across three incubation days. These choices introduce natural variability and more closely reflect conditions outside controlled industrial settings, offering a valuable test case for generalizability.
Future work should focus on building a larger, higher-quality dataset, with more consistent lighting and fewer artifacts. Additionally, narrower imaging intervals and real-time object detection models may better exploit temporal changes in vascular patterns. While the CNN-RNN approach did not yield performance gains in this study, the overall findings reinforce the potential of machine vision as a non-invasive, scalable, and ethically sound method for early chick sexing. Future work should also include the use of explainability methods, such as Grad-CAM or SHAP, to better understand which image features contribute to the model’s predictions.