Organizations: Department of Artificial Intelligence, Sardar Vallabhbhai National Institute of Technology, Surat, Gujarat, India. · Electrical and Computer Engineering Department, State University of New York Polytechnic Institute, Utica, New York, USA. · Department of Information Security and Communication Technology, Norwegian University of Science and Technology, Gjovik, Norway.
In recent years, automated fruit classification systems have become a more critical component in precision agriculture for efficient yield estimation, quality control, and supply chain optimization. However, they still face significant challenges under varying quality, fruit maturity, illumination, texture degradation, morphological attributes, domain shift, and post-harvest handling conditions. In this study, we address the challenging issue of cross-grade banana variety classification. This is a real-world setting where models that have been trained on specific quality grades must generalize to unseen grades to handle significant domain shift. Under a rigorous Leave-One-Grade-Out evaluation protocol, we present a thorough comparative analysis of CNNs, ViTs, and dual-stream hybrid architectures using a large-scale dataset of 31,678 banana images with three varieties and three quality grades. Specifically, to address the drawbacks of single-paradigm frameworks, we present a dual-stream Swin ResNet hybrid framework enhanced with KL-divergence-based self-distillation to align probabilistic feature representations across the CNN and Transformer streams. Comprehensive experimental analyzes show that the presented hybrid framework with KL-divergence based self-distillation achieves better overall performance, i.e., it attains a mean accuracy of 81.25% and significantly surpasses CNN and Transformer baseline models. Qualitative analysis further confirms that the hybrid framework in this study improves discriminative feature transferability, improves attention localization, and stabilizes optimization.
Figures & tables
Variety
Count
Percentage
Pachbale
11,512
36.34%
Rasbale
10,112
31.92%
Elakki-bale
10,054
31.74%
Total
31,678
100.00%
Table 1: Overall Dataset Statistics.
Grade
Variety
Count
Percentage
Grade Total
Grade 1 (Heavily blemished)
Pachbale
3,807
36.56%
10,412
Rasbale
3,589
34.47%
Elakki-bale
3,016
28.97%
Grade 2 (Moderate defects)
Pachbale
3,944
36.42%
10,830
Elakki-bale
3,571
32.97%
Rasbale
3,315
30.61%
Table 2: Variety Distribution Across Quality Grades
Figure 1: Illustration of the KL Divergence-based distillation mechanism used to align feature distributions.
Experiment
Training Grades
Test Grade
Train Size
Test Size
1
Grade 2 + Grade 3
Grade 1
19,139
10,412
2
Grade 1 + Grade 3
Grade 2
18,763
10,830
3
Grade 1 + Grade 2
Grade 3
19,117
10,436
Table 3: Experimental Configuration for Leave-One-Grade-Out (LOGO) Cross-Validation
Model
Mean Acc.
Std Acc.
Mean F1
Best
Worst
Baselines
ResNet50
0.6945
± 0.0710
0.6597
0.7760
0.6465
EfficientNet-B1
0.7151
± 0.0390
0.6837
0.7602
0.6922
ConvNeXt-Tiny
0.7413
± 0.1155
0.6999
0.8711
0.6498
DenseNet-121
0.7858
± 0.0536
0.7752
0.8362
0.7295
ViT-B/16
0.7581
± 0.0940
0.7457
0.8338
0.6528
Table 4: Comprehensive Performance Evaluation of CNN-Based Backbones and Hybrid Architectures under KL Divergence Settings (No Augmentation)
Model
Test Grade
Accuracy
Precision
Recall
F1-Score
ResNet50
Grade1
0.6465
0.6511
0.6465
0.5907
Grade2
0.6609
0.6581
0.6609
0.6143
Grade3
0.7760
0.7893
0.7760
0.7741
EfficientNet-B1
Grade1
0.6930
0.7332
0.6930
0.6432
Grade2
0.6922
0.7112
0.6922
0.6539
Grade3
0.7602
0.7682
0.7602
0.7540
Table 5: Performance Comparison Across Test Grades
Model
Train Grade
Test Grade
Accuracy
Precision
Recall
F1-Score
Swin-ResNet (KL)
Grade1
Grade2
0.6044
0.4968
0.6044
0.5120
Grade1
Grade3
0.7756
0.7972
0.7756
0.7643
Grade2
Grade1
0.6177
0.4236
0.6177
0.4981
Grade2
Grade3
0.7220
0.8047
0.7220
0.6834
Grade3
Grade1
0.7108
0.7560
0.7108
0.6884
Grade3
Grade2
0.9148
0.9307
0.9148
0.9163
Table 6: Cross-Grade Generalization Results under Train-on-One-Grade (T1G) Protocol
Ablation Study
G1 Acc.
G2 Acc.
G3 Acc.
Mean Acc. ± Std
Mean F1
Best Acc.
Worst Acc.
Reference Baselines (Independent Training)
Swin-Tiny (Teacher only)
0.6654
0.7980
0.7249
0.7294 ± 0.0664
0.7118
0.7980
0.6654
ResNet50 (Student only)
0.6465
0.6609
0.7760
0.6945 ± 0.0710
0.6597
0.7760
0.6465
Ablation Variants (Isolating Components)
w/o Adaptor (Dual CE)
0.6370
0.8111
0.8719
0.7733 ± 0.1219
0.7577
0.8719
0.6370
Adaptor only (Single CE)
0.6274
0.7507
0.8621
0.7467 ± 0.1174
0.7222
0.8621
0.6274
Table 7: Ablation Study: Grade-wise and Component-wise Performance Analysis
Figure 2: Confusion Matrices for Swin-ResNet (KL) across all test grades. The strong diagonal even in Grade 1 demonstrates superior feature robustness compared to baseline CNNs.
Figure 3: Training Dynamics Matrix. The left column shows the cross-entropy loss profiles, where the close alignment of training (blue) and validation (red) curves indicates minimal overfitting. The right column illustrates the rate of loss change, where the rapid settling near zero ( ΔL≈0 ) confirms stable convergence without significant oscillations, even in the challenging Grade 1 scenario.
Model
Grade1 Test
Grade2 Test
Grade3 Test
ResNet50
25
19
12
EfficientNet-B1
19
18
17
Swin-Tiny
21
24
16
Swin-ResNet(Standard)
10
24
9
Swin-ResNet(KL)
8
8
10
Swin-EfficientNet(KL)
9
12
16
Table 8: Training Epochs Until Early Stopping
Figure 4: Grade 1 Success vs. Failure Case Study.
Figure 5: Qualitative comparison of correct and incorrect predictions for Grade 2 samples, highlighting differences in model attention and feature localization.
Figure 6: Qualitative comparison of correct and incorrect predictions for Grade 3 samples, illustrating the model?s localization capability and challenges in fine-grained discrimination.
Figure 7: Student vs. Teacher Attention Matrix. A 2 × 3 comparison across all quality grades. In each stacked image, the middle strip represents the Student’s (ResNet50) attention. The strong overlap between the Student’s focus and the relevant fruit regions indicates effective feature learning from the Teacher, even though the target layer is strictly from the ResNet50 backbone.
Grade
True Class
Sample ID
Grad-CAM IoU
Score-CAM IoU
Grade 1
Rasbale
9480
0.268
0.114
Grade 1
Elakki-bale
1623
0.313
0.202
Grade 2
Rasbale
10169
0.362
0.221
Grade 2
Elakki-bale
1905
0.375
0.017
Grade 3
Elakki-bale
2972
0.307
0.217
Grade 3
Rasbale
9392
0.176
0.337
Table 9: Teacher-Student Attention Alignment (IoU Scores) for Correct Predictions
Artificial Intelligence Lab, Department of Computer Systems Engineering, University of Engineering and Applied Sciences · Artificial Intelligence Lab, Department of Computer Systems Engineering, University of Engineering and Applied Sciences (UEAS), Swat 19060, Pakistan · Interdisciplinary Research Center for Smart Mobility and Logistics +1