Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2025 May 14;20(5):e0322198.
doi: 10.1371/journal.pone.0322198. eCollection 2025.

Swin-HSSAM: A green coffee bean grading method by Swin transformer

Affiliations

Swin-HSSAM: A green coffee bean grading method by Swin transformer

Yujie Jiao et al. PLoS One. .

Abstract

A novel shifted window (Swin) Transformer coffee bean grading model called Swin-HSSAM has been proposed to address the challenges of accurately classifying green coffee beans and low identification accuracy. This model integrated the Swin Transformer as the backbone network; fused features from the second, third, and fourth stages using the high-level screening-feature pyramid networks module; and incorporated the selective attention module (SAM) for discriminative power enhancement to enhance the feature outputs before classification. Fusion Loss was employed as the loss function. Experimental results on a proprietary coffee bean dataset demonstrate that the Swin-HSSAM model achieved an average grading accuracy of 96.34% for the three grading as well as the nine defect subdivision levels, outperforming the AlexNet, VGG16, ResNet50, MobileNet-v2, Vision Transformer (ViT), and CrossViT models by 3.86%, 2.56%, 0.44%, 4.05%, 5.36%, and 5.40% percentage points, respectively. Evaluations on a public coffee bean dataset revealed that, compared with the aforementioned models, the Swin-HSSAM model improved the average grading accuracy by 1.01%, 0.13%, 4.75%, 0.85%, 0.73%, and 0.27% percentage points, respectively. These results indicate that the Swin-HSSAM model not only achieved high grading accuracy but also exhibited broad applicability, providing a novel solution for the automated grading and identification of green coffee beans.

PubMed Disclaimer

Conflict of interest statement

The authors have declared that no competing interests exist.

Figures

Fig 1
Fig 1. Different types of defective coffee beans.
Fig 2
Fig 2. Different grades of green coffee beans.
Fig 3
Fig 3. Image data preprocessing of Arabica green coffee beans.
Fig 4
Fig 4. Feature maps structure.
a The feature maps of previous ViT; b the hierarchical feature maps approach; c the shifted window approach for computing self-attention.
Fig 5
Fig 5. Shifted window Transformer architecture.
Fig 6
Fig 6. Swin Transformer block.
LN, layer norm layer; W-MSA, window-based multi-head self-attention module; MLP, multilayer perceptron. Z l, outputs of the lth W-MSA module; l+1, shifted window-based MSA module; Z l output of the lth MLP module.
Fig 7
Fig 7. Architecture of the hierarchical scale-based feature pyramid network.
Fig 8
Fig 8. SAM discriminability enhancement module structure diagram.
Fig 9
Fig 9. Detailed structure diagram of the control depthwise separable convolution module.
Fig 10
Fig 10. Swin-HSSAM architecture.
Fig 11
Fig 11. Loss change curve of the Swin-HSSAM and Swin-T models(Train).
Fig 12
Fig 12. Loss change curve of the Swin-HSSAM and Swin-T models(Validation).
Fig 13
Fig 13. Loss change curve of different hierarchical scale-based feature pyramid network structure.
Fig 14
Fig 14. Loss change curve of different model.
Fig 15
Fig 15. Accuracy change curve of different mode.

Similar articles

References

    1. Huang J, Li W, Xia B, Hu F. Strategies on how to promote the development of coffee industry with high quality in Yunnan Province [in Chinese]. Trop Agric Sci Technol. 2022;45(03):21-29. https://10.16005/j.cnki.tast.2022.03.005 - DOI
    1. Specialty Coffee Association of America. Specialty Coffee Association of America [Internet]. 2016 May [cited 2024 Nov 4] http://www.scaa.org
    1. Yunnan Provincial Administration for Market Regulation. Small-Berry Coffee Part VII: Green Bean Grading. Yunnan Provincial Administration for Market Regulation. DB53/T 149.7—2023 [Standard, in Chinese]. 2023. Jul 10.
    1. Caporaso N, Whitworth MB, Cui C, Fisk ID. Variability of single bean coffee volatile compounds of Arabica and robusta roasted coffees analysed by SPME-GC-MS. Food Res Int. 2018;108:628–40. doi: 10.1016/j.foodres.2018.03.077 - DOI - PMC - PubMed
    1. Chang S-J, Huang C-Y. Deep Learning Model for the Inspection of Coffee Bean Defects. Applied Sciences. 2021;11(17):8226. doi: 10.3390/app11178226 - DOI

LinkOut - more resources