Rice Variety Classification

AI/ML
Rice Variety Classification

Tech Stack

Python
PyTorch
Computer Vision
timm
Scikit-learn
ONNX
Explainable AI
NumPy
Pandas

Description

A computer-vision research project (CSE 465, North South University) on fine-grained rice variety classification for low-cost agricultural deployment, written up as a manuscript with co-author Sumaya Shimu Rima: "A Leakage-Safe Benchmark for Deployable Rice Variety Classification: Ensemble Learning, INT8 Quantization, and the Limits of Knowledge Distillation."

I unified three heterogeneous public datasets (phone field photos, microscope images and lab-camera images) into a 63-class benchmark of 98,730 original grain images. Two of the sources ship offline-augmented copies of each grain as separate files, which a normal stratified split scatters across train, validation and test. I removed these duplicates before an originals-only, group-aware split, and showed that the leak inflates macro-F1 by about 1.1 points on average across 22 models, and by up to 4.8 points for weaker ones.

On the leakage-safe split I benchmarked 22 pretrained CNN and Vision Transformer models, built a four-model ensemble teacher, and tested knowledge distillation into a 1.36M-parameter ShuffleNetV2 student. Distillation lowered accuracy, which I report as a negative result, so the deployed model is the tuned non-distilled student, quantized to INT8 with ONNX Runtime for edge devices.

  • Built a unified 63-class, 98,730-image benchmark, identifying and correcting data leakage that inflated macro-F1 by up to 4.8 points.
  • Benchmarked 22 CNN/ViT architectures: Xception led at 99.49% accuracy / 98.23% macro-F1.
  • Searched 420 ensemble configurations (selected on validation only); the best four-model weighted ensemble reached 99.66% accuracy / 98.76% macro-F1 with an expected calibration error of 0.0027.
  • Ran a 12-point temperature/alpha distillation grid and found that distillation lowered the student by 1.33 points of macro-F1, contradicting the published methodology the project set out to reproduce.
  • Deployed a static per-channel INT8 ONNX model: 1.69 MB (3x smaller) at ~348 images/sec and 96.6% macro-F1.
  • Diagnosed why ONNX dynamic INT8 silently collapses the depthwise-convolutional student to 2.9% macro-F1 (per-tensor weight scales), and why static per-channel calibration fixes it.
  • Profiled robustness across 5 corruptions x 5 severities, and explained predictions with Grad-CAM and LIME.

Page Info

End-to-End Pipeline

Five phases: leakage-safe data preparation, a 22-architecture benchmark, an exhaustive ensemble search, student optimization and distillation, and INT8 compression with robustness, statistical and explainability analysis.

Rice Variety Classification: End-to-End Pipeline screenshot

Knowledge Distillation: A Negative Result

Distilling the ensemble into ShuffleNetV2 converged cleanly but lowered test macro-F1 from 98.04% to 96.71% (-1.33 pp), so the tuned non-distilled student was deployed instead.

Rice Variety Classification: Knowledge Distillation: A Negative Result screenshot

Robustness Profiling

Five corruption types at five severities: the model tolerates rotation, blur and occlusion, but degrades sharply under darkening and collapses under Gaussian noise.

Rice Variety Classification: Robustness Profiling screenshot

Explainability

Grad-CAM maps across all three source datasets show the model attending to the grain itself rather than the background.

Rice Variety Classification: Explainability screenshot