Real-Time Fine-Grained Tangerine Classification via Knowledge Distillation of an Optimized YOLOv7 Model on STM32H743 Microcontroller

Document Type : Research Article

Authors

Computer Engineering Department, Ferdowsi University of Mashhad, Mashhad, Iran.

Abstract

Traditional citrus fruit classification relied on weight-based sorting and manual inspection, often leading to inconsistencies in quality assessment. This research presents an optimized deep learning approach for classifying ripe, semi-ripe, and unripe tangerines using an enhanced YOLOv7-tiny convolutional object detection model. We integrate a custom-designed convolutional block attention module (CBAM) to improve feature extraction and classification performance. This proposed CBAM-enhanced model serves as the teacher in a knowledge distillation framework, guiding a compact student model to achieve high accuracy with significantly reduced computational demands.
The distillation process employs a composite loss function that includes Kullback–Leibler (KL) divergence to align soft probability distributions, mean squared error (MSE) to match intermediate feature maps, and cross-entropy for hard-label supervision. To further optimize the model, structured pruning removes redundant filters, and post-training quantization (PTQ) converts weights and activations from 32-bit floating-point to 8-bit integers, enabling deployment on resource-limited microcontrollers.
The final student model (with CBAM) achieves a classification accuracy of 95.97%, with only a 0.93% drop in accuracy compared to the original YOLOv7- tiny model with accuracy (96.9%). Moreover, the model size is reduced by 31 (from 11,945 KB to 385 KB), and inference latency decreases by 5.25 (from 27.3 ms to 5.2 ms), making it well-suitable for real-time embedded inference. The resulting student model (without CBAM) is trained on a tangerine orchard dataset and deployed on an STM32H743 ARM Cortex-M7 microcontroller, equipped with 2 MB flash memory, a 480 MHz processor, and a DCMI interface for real-time image processing.

Keywords

Main Subjects



Articles in Press, Accepted Manuscript
Available Online from 30 May 2026
  • Receive Date: 12 July 2025
  • Revise Date: 01 November 2025
  • Accept Date: 10 February 2026