Data set preparation
The data set used in this study is basically a primary data set. Images were taken of the pupae’s ventral surface and pupae of the mulberry silk worm (Bombyx mori) were obtained from a sericulture unit. Bivoltine silk worm races (P1) SH6 and NB4D2 were collected from the SSPC at Palampur, in the Department of Industries, Government of Himachal Pradesh, India. Images in the data set were taken with ordinary daylight conditions for further research at central University of Himachal Pradesh, India during year 2025-2026. The finished data set contained 726 ventral images of pupae of Bombyx mori, half of which were male and half female. All images were resized to 224×224×3 pixels to be in line with dimensions required for CNN backbones. For binary encoding the images were:
Class imbalance was not present in this dataset; however, class weights were still computed as:
Deterministic data pipeline and preprocessing
To ensure reproducibility and deployment readiness, all experiments are implemented using a deterministic tf.data input pipeline with fixed seeds for Python, NumPy and Tensor Flow: “seed” =42, tf.data. Options (). experimental deterministic=True Each image is processed as follows: Read and decode:
x∈RH×w×3, H, W∈N ...(3)
Resize to a fixed spatial resolution:
x′ = Resize (x,224×224) ...(4)
Convert to float and apply architecture-specific preprocessing:
The tf.data pipeline uses: Map () for decoding and augmentation, shuffle () with fixed seed for training, cache () to avoid repeated I/O, batch(B)with B=32, prefetch (AUTOTUNE)for pipeline throughput. This design yields a reusable, deterministic and deployment-friendly pipeline.
Preprocessing and augmentation
Image preprocessing was adapted per backbone to align with ImageNet normalization standards. Augmentation was applied on-the-fly during training to prevent overfitting:
• Random horizontal flipping (p=0.5).
• Random brightness variation: ∆b∈ [-0.1,0.1].
• Random contrast scaling: 0.9≤γc≤1.1.
• Random saturation scaling:0.9≤γs≤1.1.
Formally, if I is the input image, augmentation can be expressed as:
I′=γc·(I+∆b), I′′=Sat(I′,γs) ...(6)
Where,
I”= The final augmented image after applying bright ness, contrast and saturation perturbations.
The augmented dataset was then normalized through the backbone-specific preprocessing function:
Model architectures and training
Three CNN backbones were benchmarked: Efficient NetV2B0, ResNet50V2 and MobileNetV3-Large, each initialized with ImageNet weights. The backbone was followed by:
Global average pooling (GAP)
Where,
fj = The activation map of channel j.
H, W= The spatial dimensions.
Batch normalization (BN)
Dropout (p=0.3) to reduce overfitting. Sigmoid output layer for binary prediction:
Two-stage fine-tuning strategy
Stage 1 (Frozen training): The backbone was frozen and only the classifier layers were trained for E1=5 epochs.
Stage 2 (Partial unfreezing): The top 35% of backbone layers were unfrozen for fine-tuning for E2 =6 epochs using a reduced learning rate.
θ← θ - η∇θL ..(11)
Where,
η= The learning rate.
L= The binary cross-entropy loss.
To handle potential class imbalance in a general setting (even though here the dataset is balanced), class weights are computed as:
Here,
• N= Total number of samples.
• K= 2 represents number of classes (male and female).
• Nc= Indicates the number of samples belonging to class c. The weighted loss becomes:
Models are optimized with the Adam optimizer, using different learning rates across training stages.
Two-stage fine-tuning strategy
Each architecture is trained using a two-stage transfer learning scheme:
Stage 1-Frozen backbone
• All backbone layers are frozen (trainable=0).
• Only the classifier head is trained.
• Learning rate: η1=10-3.
• Number of epochs: E1=5.
Stage 2-Partial unfreezing
• The top ρ=0.35 fraction of backbone layers is unfrozen.
• For a backbone with L total layers, the last ρL layers are made trainable.
• Number of epochs: E2= 6.
• Reduced learning rate: η2 = 5×10-4, with adaptive adjustment by ReduceLROnPlateau. Early stopping monitors validation AUC and the best weights are restored to avoid overfitting.
Evaluation metrics
For a decision threshold τ, predictions are binarized as:
Accuracy
Precision
Recall
F1-score
The receiver operating characteristic (ROC) curve is constructed by varying the decision threshold τ and plotting:
The ROC-AUC is the area under this curve:
Average precision (PR-AUC) is computed as:
PR-AUC = ∑n (Rn - Rn-1)Pn ...(24)
Where,
Pn and Rn= The precision and recall at the nth operating point.
Threshold optimization for model selection
Instead of fixing τ=0.5, the optimal decision threshold is selected by maximizing the F1-score on the validation set:
τ* = arg max F1 (τ)
τ∈ [0,1] ...(25)
In practice, the decision threshold t is scanned over a dense grid:
τ∈ {0.0, 0.001, 0.002,...,1.0} ...(26)
and the threshold τ* that yields the highest F1-score is selected. The hold-out comparison of the architectures uses F1(τ*) as the primary model selection criterion.
Train-validation splitting and cross-validation
The dataset is partitioned into K=5 folds, at each fold k, a different subset serves as validation, while the remaining K-1 folds are used for training, This yields per-fold performance metrics:
Acck, F1k,ROC-AUCk, PR-AUCk,k=1,...,5 ...(27)
The mean and standard deviation across folds is reported as:
For each metric M∈ {Accuracy, F1, ROC-AUC, PR-AUC}.
Statistical significance testing
To demonstrate that the observed differences between architectures are not due to chance, paired t-tests are conducted on fold-wise accuracies (or F1-scores). Let MK(A) and MK(B) denote the performance metric values for models A and B on fold k and define:
dk = MK(A) - MK(B) , k=1,...,K ...(29)
The paired t-test statistic is:
The corresponding p-value is computed under the t distribution with (K-1) degrees of freedom. A result such that p<0.001 is interpreted as highly statistically significant, indicating that one architecture (e.g., EfficientNetV2-B0) outperforms another (e.g.,ResNet50V2orMobileNetV3-Large) with strong confidence.
Hardware and software used
12th Gen Intel® Core™ i5-12450H processor running at 2.00 GHz, 16.0 GB of installed RAM and a 64-bit Windows operating system on an x64-based processor. Python version 3.12.4 for implementing and executing the proposed model. Image acquisition of silkworm pupae was performed using the digital camera under ordinary day lighting conditions.