An Attention-Augmented CNN Model for Robust Cocoa Bean Defect Classification
Abstract
Noise is an inevitable challenge in real-world image datasets and can substantially degrade the performance of computer vision models. Many image classification models are trained on clean or heavily preprocessed datasets without mechanisms for handling corrupted images, which may limit their performance in practical deployment. This study investigates whether incorporating an attention block into a convolutional neural network (CNN) improves cocoa bean defect classification under noisy imaging conditions. A balanced dataset of 4,200 cocoa bean images spanning six defect categories was collected under two illumination conditions: even illumination using an LED light source and uneven illumination under daylight. To simulate real-world image degradation, Gaussian and impulse noise were introduced into 10% of the images in each category at two severity levels. Gaussian noise was generated with zero mean and standard deviations of 25 and 40, while impulse noise was applied with pixel-corruption probabilities of 0.02 and 0.04. The resulting noisy images increased the dataset size by 40% before augmentation. A Six-layer CNN was developed, consisting of four feature-extraction layers and two fully connected classification layers. A Squeeze-and-Excitation (SE) attention block [1] was integrated into the convolutional layers to enhance informative cocoa bean features while suppressing irrelevant, noise-corrupted ones. This attention block is computationally lightweight, adding only a moderate increase in model complexity. Adam optimizer and a dropout rate of 0.5 were incorporated to improve network performance. The proposed model achieved a validation accuracy of 97.54% and a test accuracy of 98.17% after 100 training epochs. It outperformed the corresponding CNN without an attention mechanism as well as other machine learning and CNN-based cocoa bean classification approaches reported in previous studies [2, 3]. The proposed model required slightly more computational time than the baseline CNN, attributable to the additional attention layer. These findings demonstrate that exposure to noisy training data alone does not guarantee a noise-robust model. Incorporating an appropriate attention mechanism can improve extraction of salient features from corrupted cocoa bean images and enhance performance. The proposed approach provides an effective deep learning framework for cocoa bean defect classification under varying illumination and noisy imaging conditions. Future work will involve expanding the dataset to investigate performance on larger and imbalanced datasets. The transferability of the approach to defect classification in other agricultural products could also be considered. References [1] Hu, J., Shen, L., and Sun, G. (2018). Squeeze-and-excitation networks. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pp. 7132–7141. [2] Hortinela, C. C. and Tupas, K. J. R. (2022). Classification of cacao beans based on their external physical features using convolutional neural network. IIEEE Region 10 Symposium (TENSyMP), pp. 1–5. IEEE. [3] Zhinin-Vera, L., Zhiminaicela-Cabrera, J., Pretel, E., Suárez, P., Chang, O., Castro, F. A., and de la Rosa, F. L. (2023). Artificial vision technique to detect and classify cocoa beans. In International Work-Conference on Artificial Neural Networks, pp. 217–228. Springer.