Peaberry Coffee Bean Sorting System
Peaberry Coffee Bean Sorting System
I
increased because of their powerful performances and
N the world markets, every day more than two billion cups
availabilities for wide applications. Deep neural networks
of coffee are consumed, which makes coffee one of the
allow computational models that are composed of multiple
most popular beverages and over the years, coffee
processing layers to learn representations of data with multiple
consumption and the demand for high-quality coffee beans
levels of abstraction [15]. These methods have significantly
have been increasing [1], [2]. The coffee grows in the tropics
improved the performance of speech recognition, object
and is one of the most important crops to earn foreign
detection, visual object recognition and many other domains,
currency for several under developing countries. Evaluating
including drug discovery and genomics [34].
H.L.G. is with the Faculty of Engineering, Gifu University, Japan and
In general, the main inspiration behind the application of
Faculty of Agricultural Engineering and Technology, Sylhet Agricultural image analysis or computer vision systems to agricultural
University, Bangladesh (corresponding author, e-mail: hlgope@[Link]). products is due to the drawbacks of manual classification and
H.F. is with the Faculty of Engineering, Gifu University, Japan (e-mail:
fukai@[Link]).
grading systems such as subjectivity, tediousness, labor
International Scholarly and Scientific Research & Innovation 14(6) 2020 189 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Computer and Information Engineering
Vol:14, No:6, 2020
requirements, cost, and inconsistency, as many researchers 3. When we applied classification algorithms on normal and
have reported [16]-[27]. The peaberry beans of special type peaberry coffee bean image datasets, the accuracy of the
roast more slowly than other normal beans. Coffee beans were individual algorithm emerged.
detected and selected using various techniques [6]. Therefore,
neither technique provides a good option to select the
peaberries, meaning a more modern approach is needed [4].
The identification and selection of the peaberries need a robust
and easy process.
The novelty of this study is to develop an automatic normal
and peaberry coffee bean identification and selection system, (a)
which can estimate the accuracy of normal and peaberry
coffee beans using deep CNN, a state-of-art technique of the
image processing field [10]. We developed a computer
program as the first step, whose input is a color image of a
green coffee bean and the output is the probability of each
bean category. (b)
Open Science Index, Computer and Information Engineering Vol:14, No:6, 2020 [Link]/10011255/pdf
In this research, we also applied the conventional SVM with Fig. 1 Coffee bean types: (a) normal and (b) peaberry
a linear kernel for the classification and compared the
performances of CNN and SVM in terms of classification
accuracy [9]. We will install Raspberry Pi on desktop PC with
a tiny affordable single-board computing module. On
Raspberry Pi, we will be implementing the coffee bean
classifier for training the CNN models. Python (a programing
language), Chainer (an open source library of neural networks
for deep learning), and OpenCV (an open source library for
computer vision) will be installed on Raspberry Pi. We will Fig. 2 Block diagram of coffee bean image processing
develop a python program that uses a camera module to take a
photo of a green coffee bean, converts the photo image with C. Image Acquisition
OpenCV to fit the image as a CNN input, and then classify the The neural network inputs were digital images of green
coffee bean images using CNN with network pre-trained coffee beans. The coffee bean samples were from Timor-
parameters. We will estimate the classifier’s performance on Leste. The green coffee beans were placed onto white paper
two types of normal and the peaberry binary classification before taking photographs using a Nikon digital camera. The
from green coffee bean images [9]. camera was set with F/16 f-number, exposure time 1/60 s, ISO
200, exposure compensation 1.3, and autofocus mode set to
II. MATERIALS AND METHODS automatic mode. The camera was placed at 1 m above from
the bean’s surface. Both the front and back sides of the beans
A. Normal and the Peaberry Coffee
were photographed. To ensure the brightness around the
1. Normal Coffee Bean: Normal coffee beans have no subject was uniform, three lighting devices were placed
defects, and it is not a defect type. From a coffee cherry, around the beans [9]. The shooting environment is shown in
this type of bean contains two beans with their flat sides Figs. 3 and 4. Image preprocessing techniques were applied to
together like the two halves of a peanut (Fig. 1 (a)) [6], the photographs to isolate each bean (Fig. 5). About 3,338
[11]. samples of the normal and the peaberry were prepared. The
2. Peaberry Coffee Bean: The special type of the peaberry size of each image was set to 32×32 pixels, 64×64 pixels,
coffee seed is born in only one of the two seeds, a 128×128 pixels and 256×256 pixels. The images were
relatively round seed from a coffee cherry instead of the manually labeled as normal and peaberry. Note that one image
normal flat-sided seed pair (Fig. 1 (b)). may have multiple labels [9], [10].
B. Process of Normal and the Peaberry Coffee Bean Images To apply the machine learning techniques, all the sample
images were divided into three groups: training data,
The important features in the selection process are physical
validation data and test data. The training data were used for
appearance including color, morphology, shape, and size [3].
training the machine learning models. The validation data
Fig. 2 shows the sequence of coffee bean image classification
were used to confirm the transition of classification
and its analysis. The research aim is to develop an automatic
performance during the neural networks training phase. The
sorting system with good accuracy. The procedure of our
test data were used to evaluate the ability of the trained models
image classification algorithms is:
to sort with final parameters. The number of images for each
1. Digital image finding from image dataset.
group is shown in Table I.
2. Principle Component Analysis (PCA) for feature
extraction.
International Scholarly and Scientific Research & Innovation 14(6) 2020 190 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Computer and Information Engineering
Vol:14, No:6, 2020
Fig. 5 Coffee bean images (1:1) obtained by applying image pre-processing technique [9], [10]
TABLE I The output shape changes depending on the filter stride. For
THE NUMBER OF IMAGES FOR EACH TASK
instance, if the stride value s is 2, the output of the width and
Task Training Validation Test
height will be half of the input. A convolution schematics
Normal 1140 570 190
diagram is shown in Fig. 7 [9].
Peaberry 863 431 144
Usually, the pooling layer is positioned just after the
D. CNN convolution layer. The role of the pooling layer is to decrease
The CNN is a form of artificial neural network that is the sensitivity of the feature to the position, which extracted
mainly applied for the recognition of images [14]. CNNs by the convolution layer, so even if the position of the target
apply to image processing, natural language processing, and feature in the image shifts slightly, the output of the pooling
other cognitive tasks. ConvNet also is known as a CNN [29]. layer does not differ. There are several types of methods for
CNN is consisting of three types of layers (Fig. 6). The pooling. In this study, max pooling is used. Max pooling is a
convolution layer has the purpose of extracting features of an method that sets the maximum value contained in 𝑃 as an
image using spatial filters. Assume that, input from 𝑙 1 output value 𝑢 , described as (3) [9].
layer proceeds with a convolutional connection to the 𝑙
max 𝑧
layer. Let the input take the form of 𝑊 𝑊 𝐾 and the layer 𝑢 𝑝, 𝑞 ∈ 𝑃 𝑝𝑞𝑘 (3)
of convolution has M spatial filter types in the form of 𝐻
𝐻 𝐾. Then, calculate the output 𝑢 by convolving this For every channel k, the max pooling is applied
spatial filter on the input as in (1) [9]. independently. The size of output depends on the stride as
same as the convolution layer.
𝑢 ∑ ∑ ∑ 𝑧 , , 𝑝𝑞𝑘𝑚 𝑏 (1) The fully connected layer has a role of converging features
that are obtained by repeating convolution and pooling to the
Here, the 𝑏 parameter is a bias of the layer. The number of classes we want to classify. This same type of
activation function f (ꞏ) is then applied to the 𝑢 as in (2) architecture was used in classical artificial neural networks.
and thus, we get 𝑧 as the output of the convolution layer The fully connected output layer 𝑧 is given by (4) and (5) [9].
[9].
𝑢 ∑ 𝑤 𝑥 𝑏 (4)
𝑧 𝑓 𝑢 (2)
International Scholarly and Scientific Research & Innovation 14(6) 2020 191 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Computer and Information Engineering
Vol:14, No:6, 2020
International Scholarly and Scientific Research & Innovation 14(6) 2020 192 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Computer and Information Engineering
Vol:14, No:6, 2020
numbers of the false positive and false negative for the classification indicates that the SVM classification is good.
considered class. The overall 97% accuracy of the coffee bean
TABLE II
PARAMETERS OF THE CNN FOR FOUR KINDS OF THE IMAGE DATASET
A. 32×32 IMAGE SIZE
Layer Name Filter shape 𝑯 𝑯 𝑲 Stride 𝒔 Output map shape 𝑾 𝑾 𝑴 𝐀𝐜𝐭𝐢𝐯𝐚𝐭𝐢𝐧 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝒇 ∙
Input 32 32 3
Convolution1 3 3 3 1 30 30 32 𝑅𝑒𝐿𝑈
Pooling1 2 2 32 2 15 15 32
Convolution2 3 3 32 1 15 15 64 𝑅𝑒𝐿𝑈
Pooling2 2 2 64 2 7 7 64
Convolution3 3 3 64 1 7 7 128 𝑅𝑒𝐿𝑈
Pooling3 2 2 128 2 3 3 128
Convolution4 3 3 128 1 3 3 256 𝑅𝑒𝐿𝑈
Pooling4 2 2 256 2 1 1 256
FullConnected1 512 𝑅𝑒𝐿𝑈
Open Science Index, Computer and Information Engineering Vol:14, No:6, 2020 [Link]/10011255/pdf
FullConnected2 1 𝑆𝑖𝑔𝑚𝑜𝑖𝑑
International Scholarly and Scientific Research & Innovation 14(6) 2020 193 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Computer and Information Engineering
Vol:14, No:6, 2020
III. EXPERIMENT types of classification, as shown in Table III and Fig. 8. The
image size did not significantly affect the classification
A. Classification of Normal and the Peaberry Coffee Beans
Using CNN and Conventional Linear SVM accuracies for the CNN and conventional linear SVM. We
obtained high accuracies (over 97%) from CNN as the
Normal and peaberry types of coffee beans are labeled as classification of the conventional linear SVM.
green coffee beans. However, we performed two binary
classifications for each type of bean in the case of coffee TABLE III
beans. The number of coffee bean images used for each CNN AND SVM ACCURACIES FOR NORMAL AND PEABERRY COFFEE BEAN
(FOUR IMAGE SIZES)
classification task is shown in Table I. The parameters of CNN
Accuracy
are shown in Table II. The layer was added after the Image Size
CNN SVM with Linear Kernel
’FullConnected1’ layer and set a dropout rate to 0.5 [31]. The
32×32 0.9736 0.9671
deep learning library, Chainer, was used to implement the 64×64 0.9726 0.9671
CNN [32]. 128×128 0.9850 0.9671
Instead of CNN, we also applied conventional linear SVM 256×256 0.9853 0.9641
to compare the performance in classification accuracy.
Parameter C was set to 1 and parameter gamma was set to V. DISCUSSION AND CONCLUSION
Open Science Index, Computer and Information Engineering Vol:14, No:6, 2020 [Link]/10011255/pdf
(a)
International Scholarly and Scientific Research & Innovation 14(6) 2020 194 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Computer and Information Engineering
Vol:14, No:6, 2020
(b)
Fig. 8 CNN and conventional linear SVM classification accuracies for four kinds of image sizes: (a) flow chart and (b) graphical representation
Open Science Index, Computer and Information Engineering Vol:14, No:6, 2020 [Link]/10011255/pdf
of image data
International Scholarly and Scientific Research & Innovation 14(6) 2020 195 ISNI:0000000091950263
World Academy of Science, Engineering and Technology
International Journal of Computer and Information Engineering
Vol:14, No:6, 2020
Hira Lal Gope received the [Link]. (Honors) and M.S. Engineering (Thesis) in
Computer Science and Engineering from the University of Chittagong,
Chittagong-4331, Bangladesh in 2012 and 2017 respectively. He started his
carrier in the teaching and research profession as a faculty member at the
Sylhet Agricultural University, Bangladesh since 01 January 2013. His main
area of research interest is neural networks, machine learning, deep learning,
and image processing. Mr. Gope is an associate member of the Bangladesh
Computer Society (BCS).
Open Science Index, Computer and Information Engineering Vol:14, No:6, 2020 [Link]/10011255/pdf
International Scholarly and Scientific Research & Innovation 14(6) 2020 196 ISNI:0000000091950263
The use of Raspberry Pi enhances the classification system for coffee beans by providing a low-cost, accessible computing platform ideal for developing countries. It supports the installation of CNN models using Python and tools like Chainer and OpenCV. This setup allows for the real-time processing of coffee bean images captured by a camera module and classification with minimal hardware requirements, facilitating wider adoption .
Deep learning libraries like Chainer play a crucial role in developing the coffee bean sorting system by providing pre-built tools for designing and training CNN models. Chainer allows easy experimentation with network architectures, supports implementation of real-time image processing, and simplifies the computation required for classification tasks. It aids in establishing a robust system that can efficiently distinguish peaberry from normal beans .
The classification accuracy of CNN is preferred over SVM for sorting coffee beans due to CNN's ability to handle complex image recognition tasks by capturing spatial hierarchies in data through convolutional layers. CNNs achieved higher accuracies (>97%) across different image sizes compared to SVM, which had slightly lower accuracy scores. This makes CNN better suited for discriminating the subtle differences between peaberry and normal beans .
Separating peaberry beans before roasting is important because their round shape causes them to roast differently than the flat-sided normal beans, leading to inconsistencies in overall coffee quality. Peaberries have different roasting times, which means they could be over or under-roasted if mixed with other beans, affecting the final taste profile. This separation ensures uniform roasting and better flavor preservation .
Image processing and machine learning techniques, specifically Deep Convolutional Neural Networks (CNN) and Support Vector Machine (SVM), are used for discriminating between peaberry and normal coffee beans by analyzing color, morphology, shape, and size. These techniques automate classification that would otherwise require manual effort. CNNs have shown better performance in classification accuracy compared with SVM, allowing for effective automatic sorting systems .
Conventional SVM and deep CNN differ in their approach to image classification primarily through their handling of data and feature extraction. SVM uses a linear or non-linear kernel to classify data transformed into a high-dimensional feature space, typically requiring pre-defined features and often less effective with large-scale visual data. In contrast, CNN automatically extracts hierarchical features from raw image data through its convolutional layers, reducing the need for manual feature engineering and improving accuracy for complex image tasks such as differentiating coffee beans .
The developed coffee bean sorting technology has potential applications in agricultural processing beyond coffee beans, such as sorting other types of seeds and grains based on size, shape, color, or defect characteristics. The integration of image processing and machine learning offers prospects for enhanced quality control, automation of sorting processes, and reduced reliance on manual labor, which can improve efficiency and consistency across various agricultural products .
Sorting peaberry coffee beans is challenging because they have a similar shape and color to normal beans, making manual selection difficult even for trained specialists. Peaberries, being born as a single round seed in a coffee cherry, have a different shape from the usual flat-sided pair of beans, which affects roasting time. To prevent the taste from being mixed, it is essential to separate them from normal beans before roasting .
Artificial data augmentation can enhance the training of CNN models for coffee bean classification by creating a larger, more varied dataset without the need for additional authentic samples. Techniques such as random rotation, shifts, and flips introduce variability that helps the model become more robust to different orientations and scales of the beans, improving generalization and accuracy in real-world scenarios .
To improve classification performance, proposed solutions include increasing the number of samples to enhance model training, utilizing advanced SVM kernels for finer classification, restructuring CNN frameworks, and implementing data augmentation techniques such as random rotation and shifts to create more diverse training datasets. These solutions aim to enhance both the precision and robustness of the sorting system .