A cross-domain fruit classification method based on lightweight attention networks and unsupervised domain adaptation

Jin Wang, Cheng Zhang, Ting Yan, Jingru Yang, Xiaohui Lu, Guodong Lu, Bincheng HuangComplex 2022

Abstract

Image-based fruit classification offers many useful applications in industrial production and daily life, such as self-checkout in the supermarket, automatic fruit sorting and dietary guidance. However, fruit classification task will have different data distributions due to different application scenarios. One feasible solution to solve this problem is to use domain adaptation that adapts knowledge from the original training data (source domain) to the new testing data (target domain). In this paper, we propose a novel deep learning-based unsupervised domain adaptation method for cross-domain fruit classification. A hybrid attention module is proposed and added to MobileNet V3 to construct the HAM-MobileNet that can suppress the impact of complex backgrounds and extract more discriminative features. A hybrid loss function combining subdomain alignment and implicit distribution metrics is used to reduce domain discrepancy during model training and improve model classification performance. Two fruit classification datasets covering several domains are established to simulate common industrial and daily life application scenarios. We validate the proposed method on our constructed grape classification dataset and general fruit classification dataset. The experimental results show that the proposed method achieves an average accuracy of 95.0% and 93.2% on the two datasets, respectively. The classification model after domain adaptation can well overcome the domain discrepancy brought by different fruit classification scenarios. Meanwhile, the proposed datasets and method can serve as a benchmark for future cross-domain fruit classification research.

Introduction: The Challenge of Domain Shift

Computer vision models for fruit classification often suffer from domain shift. A model trained on high-quality, perfectly lit laboratory images (the "source domain") typically performs poorly when deployed in a supermarket or a sorting facility (the "target domain") where backgrounds are cluttered, lighting varies, and camera angles are inconsistent.

Figure 1: Examples of grape images across different domains: (a) Controlled Environment, (b) Illumination Variation, (c) Background Variation, and (d) Internet images.

The traditional fix is to collect and manually label thousands of new images for every new scenario—a process that is expensive and time-consuming. This paper addresses this by using Unsupervised Domain Adaptation (UDA), which allows a model to "bridge the gap" between a labeled source domain and an unlabeled target domain, ensuring the AI remains robust even when the visual environment changes.

Proposed Methodology

The authors propose two major innovations to the standard MobileNet V3 architecture to enhance its cross-domain performance.

1. HAM-MobileNet (Hybrid Attention Module)

Standard MobileNet V3 uses Squeeze-and-Excitation (SE) blocks to focus on important "channels" (colors/features). The authors added a Parameter-free Attention Module (PAM) to create a hybrid module. PAM adds spatial awareness—helping the model focus on the fruit's shape and texture while ignoring complex backgrounds—without adding any additional parameters or significant computational overhead.

Figure 4: Architecture of the MobileNet V3 block integrated with the proposed attention mechanisms.

2. Hybrid Loss Function

To align the source and target domains during training, the authors used a combination of two metrics:

  • Local Maximum Mean Discrepancy (LMMD): Unlike global alignment, LMMD ensures that specific classes are aligned (e.g., making sure the "Gala Apple" features in the lab match "Gala Apple" features in the store).
  • Correlation Alignment (CORAL): This aligns the second-order statistics (covariance) of the distributions, acting as an "implicit" way to minimize domain discrepancy.

Datasets and Benchmarks

The study introduces two new benchmarks to simulate real-world shifts:

  • Grape Classification Dataset: Contains 2,810 images of seven grape varieties across four domains: Controlled Environment (CE), Illumination Variation (IV), Background Variation (BV), and Internet images (IN).
  • General Fruit Classification Dataset: A larger set of 17,402 images covering 11 fruit types, merging data from the public VegFru and Supermarket Produce datasets to create a "VegFru-to-Supermarket" transfer task.

Key Results and Insights

  • High Accuracy: The proposed method achieved an average accuracy of 95.0% on the grape dataset and 93.2% on the general fruit dataset.
  • Efficiency: HAM-MobileNet achieved results comparable to much larger models like ResNet-50, but with only 12.6% of the parameters and 5.8% of the computational cost (MAdds).
  • Domain Gap Reduction: Using "A-distance" (a metric for domain similarity), the authors proved their method significantly reduced the measurable gap between lab images and internet/supermarket images compared to standard training.
  • Spatial Matters: While channel attention (SE) is common, fruit classification relies heavily on fine-grained spatial details (texture of a peel, shape of a stem). Adding spatial attention (PAM) specifically helps suppress "noise" from messy supermarket backgrounds.

Conclusion and Future Work

The classification model after domain adaptation can well overcome the domain discrepancy brought by different fruit classification scenarios. While the results are promising, the authors note a few areas for growth, including exploring Domain Generalization (where the model is robust to any unseen environment without prior exposure) and further compressing the UDA model for direct deployment on ultra-low-power smart devices and mobile phones.

Summary updated

BibTeX
@inproceedings{wang2022cross,
  author = {Jin Wang and Cheng Zhang and Ting Yan and Jingru Yang and Xiaohui Lu and Guodong Lu and Bincheng Huang},
  title = {{A cross-domain fruit classification method based on lightweight attention networks and unsupervised domain adaptation}},
  booktitle = {Complex},
  year = {2022},
  doi = {10.1007/s40747-022-00955-8},
}
Figure