Hybrid CNN and KNN Approach for Coffee Bean Quality Identification - Army, Widya Lelisa; Anita, Sri; Ramadhina, Retno (Politeknik Ganesha Medan, 2025)
This study discusses the integration of Convolutional Neural Network (CNN) and K-Nearest Neighbors (KNN) for the identification of coffee bean quality as an effort to increase the competitiveness of local commodities. CNN is used as a feature extractor to produce an information-rich representation of coffee bean images, while KNN acts as a classifier to classify quality into two classes, namely Good and Defective. The dataset is divided into training, validation, and test data, with a total of 1,190 images obtained from the manual annotation process. The research stages include (1) pre-processing of data in the form of cropping based on bounding boxes, resize to 224×224 pixels, normalization, and data augmentation; (2) feature extraction using pretrained CNN (ResNet18) by eliminating the final classification layer to obtain a 512-dimensional feature vector; and (3) classification using KNN with variations in k values (3, 5, and 7) as well as Euclidean distance metrics. The results of the experiment showed that the CNN+Softmax baseline resulted in an accuracy of 86%, while the CNN+KNN method provided better performance. The k=5 configuration was proven to be optimal with an accuracy of 93.4%, precision, recall, and a balanced F1-score in both classes. The confusion matrix shows that most samples can be classified correctly with a low error rate. These findings are in line with previous research that emphasized the effectiveness of CNN in the extraction of visual features and the advantages of KNN on limited datasets. Thus, this approach can be a practical solution to support an automatic, accurate, and consistent coffee bean quality identification system to increase the competitiveness of local coffee commodities in the global market.