Use of classifier to determine coffee harvest time by detachment force

Coffee quality is an essential aspect to increase its commercial value and for the Brazilian coffee business to remain prominent in the world market. Fruit maturity stage at harvest is an important factor that affects the quality and commercial value of the product. Therefore, the objective of this study was to develop a classifier using neural networks to distinguish green coffee fruits from mature coffee fruits, based on the detachment force. Fruit detachment force and the percentage value of the maturity stage were measured during a 75-day harvest window. Collections were carried out biweekly, resulting in five different moments within the harvest period. A classifier was developed using neural networks to distinguish green fruits from mature fruits in the harvest period analyzed. The results show that, in the first half of June, the supervised classified had the highest success percentage in differentiating green fruits from mature fruits, and this period was considered as ideal for a selective harvest under these experimental conditions. um classificador para determinação do momento de colheita do café pela força de desprendimento. A força de desprendimento dos frutos e o valor percentual do estádio de maturação foram mensurados durante a janela de colheita de 75 dias. As coletas foram realizadas quinzenalmente, resultando em cinco momentos distintos no período de colheita. Um classificador foi desenvolvido a partir de redes neurais para distinguir frutos verdes e cerejas nos momentos de colheita analisados. Os resultados demostraram que a primeira quinzena de junho foi o momento em que o classificador supervisionado apresentou a maior porcentagem de acerto na distinção de frutos verdes e cerejas, sendo este, o momento adequado para realização de uma colheita seletiva para as condições deste experimento.


Introduction
Agribusiness is one of the most important sectors of the Brazilian economy, representing about 20% of the Gross Domestic Product (GDP) in the last twenty years (CEPEA, 2015). According to CONAB (2016), the Brazilian coffee production in 2016 was the highest one in its history, reaching a volume of 51.37 million 60 kg sacks of the processed product.
For this sector to continue being competitive and in economic growth, it is necessary to always use new strategies. According to Monteiro et al. (2010), coffee is one of the few agricultural products valued based on qualitative parameters, and the better the quality, the higher the price. Coffee grains at cherry stage aggregate the most important chemical precursors to generate quality drinks after roasting (Arruda et al., 2011). Silva et al. (2010) observed that coffee detachment force differs according to grain maturity stage, obtaining lower values for the cherry stage compared with the green stage. Such variation can be an important factor to perform a selective mechanical harvest. Silva et al. (2013) concluded that fruit detachment force proved to be an objective parameter to indicate the starting moment of coffee selective harvest and also a possible parameter for mechanical harvest management.
In this context, the present study aimed to develop a classifier using neural networks to distinguish green coffee fruits from cherry coffee fruits based on the detachment force, in order to determine the ideal moment to begin the mechanical harvest aiming at grain selectivity.

Material and Methods
The experiment was carried out at the Experimental Farm of the Campus of the Federal University of Lavras, Lavras-MG, Brazil (21º 14' S; 45º 00' W; 918 m), using the cultivar 'Catuaí Amarelo' transplanted in 2001, at density of 2500 plants ha -1 , with spacing of 4.0 m between rows and 1.0 m between plants.
According to Köppen's classification, the local climate is Cwa with annual means of temperature, rainfall and relative air humidity of 19.40 ºC, 1529.7 mm and 76.2%, respectively. The soil in the experimental area is classified as dystroferric Dark Red Latosol with clayey to very clayey texture.
Fruit detachment force and the percentage value of the maturity stage were measured during a 75 day harvest window, biweekly, starting in the second half of April and ending in the second half of June, totaling five moments of harvest.
The percentage value of the maturity stage was determined by counting the fruits corresponding to a 0.5 L sample in the same plants used to determine the detachment force.
Fruit detachment force was measured considering the green and cherry stages in five plants randomly selected. The plants were divided into two sides (East and West) and into three parts (lower, middle and upper thirds). For each side, in each third, four values of detachment force were obtained. Thus, for each plant and at each moment of harvest, a total of 24 readings of detachment force were obtained for each maturity stage (Table 1).
The detachment force was measured using a dynamometer. Dynamometer construction and calibration was based on the Hooke's Law, which correlates the deformation of objects, within plastic regime, with the exerted force. The force is proportional to the displacement from its equilibrium point. A spring was used, and its elastic constant was determined based on the deformation.
The dynamometer was calibrated based on the spring's elastic deformation, caused by objects with known weights, determined on precision scale. After this procedure, the elastic constant of the spring was determined, 0.85 N cm -1 , allowing measurements of up to 18.7 N.
The average response and the respective standard deviations of the detachment force of green and cherry fruits were analyzed at the five moments of harvest.
Based on the detachment force, an acyclic neural network was trained by the error backpropagation algorithm using the Levenberg-Marquadt variation to accelerate the training time and improve pattern classification performance (Demuth et al., 2008).
To develop the classifier, two classes were defined based on fruit maturation. The class of green fruits was composed of detachment forces determined in the 2 nd half of April (HA). This period was chosen to represent the class of Green Fruits because it is the first moment of harvest within the window, having only green fruits. The class of cherry fruits was composed of detachment forces determined in the 2 nd half of June (HJ), a period chosen for representing the last moment of harvest within the window, having only cherry fruits.
Neural network architecture was composed of one input layer, two intermediate layers and one output layer with one neuron. Detachment force was used as the input descriptor. The intermediate and output layers used the hyperbolic tangent as activation function. A binary system was used in the output layer, in which 0 referred to fruits classified as green and 1 referred to fruits classified as cherry.
Thirty three percent of the total number of fruits analyzed in the 2 nd HA and 2 nd HJ were used to train the networks (40 detachment force readings for the Class Green and 40 detachment force readings for the Class Cherry), 33% were used for validation and 33% were used to test the trained networks. Thus, for neural network training, validation and test, 120 fruits classified as green and 120 fruits classified as cherry were used. Training was interrupted by the early stopping technique, when the error in the validation sample increased in six consecutive cycles. The neural network (NN) of each architecture with highest success percentage in the classification of test samples was selected. NN architecture was trained ten times because, in the beginning of the training, the parameters of the networks are randomly generated and these values influence the training. The performance of each NN was measured by the confusion matrix obtained in the classification of the test samples (Congalton, 1991). Producer's accuracy (PAC%), user's accuracy (UAC%), overall efficiency (OE%) and Kappa coefficient were analyzed according to Eqs. 1, 2, 3 and 4.
Based on the average detachment force at the moments of harvest (Figure 1), cherry beans showed lower values than green beans. The response for green beans had a stable trend of approximately 9.0 N between the 2 nd HA and 1 st HJ. On the other hand, cherry beans were detected from the 2 nd HM, showing a decreasing trend in the detachment force, with a total reduction of 2.62 N until the 2 nd HJ. According to the standard deviation at each moment of maturation, the use of a supervised classifier can be adequate to distinguish green beans from cherry beans.
Detachment force variations between green and cherry beans are consistent with the results found by Silva et al. (2010), who observed lower values for the cherry stage ( Figure 1). However, in the 2 nd HM, the standard deviations overlap between both maturity stages, rendering it impossible to distinguish between beans with similar values from 6 to 8 N. This points to a moment in which the classifier accuracy may be reduced, due to the difficulty to distinguish green from cherry beans.
In the 1 st HJ, there was a clear discrepancy between the detachment forces of green and cherry beans, and this is a moment in which automatic classification systems tend to show highest success rates in distinguishing the fruits. Thus, for the conditions of this experiment, selective harvest could start from this moment.
In addition, a maturity index of 70% was found in the 1 st HJ, indicating that the variation of detachment force at this moment is really associated with fruit maturation, which reinforces the hypothesis that this was the adequate moment to start a selective harvest. Maturity indices above 65% were used where: k -number of lines in the confusion matrix; N -number of observations; Xi -marginal total of each line of the confusion matrix; and, X + j -marginal total of each column of the confusion matrix.
Kappa coefficient significance was analyzed by the Z test, which allowed to verify if the classification by NN was considered as better than a random classification (Leeuw et al., 2006).
The NN considered as with best performance was used to classify the fruits regarding the detachment force in the five plants analyzed at the five moments of harvest. In addition, the following measures were also analyzed: partial hit percentage (PH%), relative to the percentage of hits of correct classification of each class, and total hit percentage (TS%), relative to the mean of partial hits of each class.

Results and Discussion
From the third moment of harvest, there were fruits at cherry stage, representing 50% of the volume of grains in the plant (Table 2). Grains at the cherry stage substantially increased in the 1 st and 2 nd HJ, but dehydrated and dried fruits appeared in the 2 nd HJ, which may reduce the quality of the coffee drink.  Green  100  100  50  (1) (3) HA, HM and HJ -Half of April, May and June by Silva et al. (2015) to obtain high efficiency in the selective harvest of coffee with different harvester vibrations. A supervised classifier based on neural networks was selected using green beans harvested in the 2 nd HA and cherry beans harvested in the 2 nd HJ (Table 3), to classify green and cherry beans based on the detachment force. According to the producer's accuracy, 89.33% of green beans and 88.79% of cherry beans were correctly classified. User's accuracy indicated that, among beans classified as green, 77.44% were correctly classified, while among beans classified as cherry, 92.79% were correctly classified. This fact demonstrates that approximately 22.00% of green beans have detachment force with the same magnitude as that of cherry beans, and this factor is unfavorable to the selective harvest through vibration. The Kappa coefficient of 0.77 was considered as substantially strong (Landis & Koch, 1977) and demonstrated that the classification using the selected NN was better than a random classification at 0.01 significance level.
In general, the analysis of detachment force of coffee beans has been related to harvest efficiency (Silva et al., 2013;Santinato et al., 2015) and to the spatial variability of this parameter under different conditions (Ferraz et al., 2012;Carvalho et al., 2017). Although supervised classifiers based on coffee detachment force are still scarce, the parameters of the NN classifier presented in Table 3 demonstrate that this analysis tool has potential to assist in the development of automated systems that indicate the adequate moment for harvest.
The percentages of success in the classification of green and cherry beans were assessed in the five plants analyzed and at the five moments of harvest (Table 4). The NN classifier showed average rate of hits higher than 80% at all moments, except the 2 nd HM (45 days after the beginning of the harvest window). This period can be considered as of lowest variation in the detachment force of green and cherry fruits, and is the most critical moment to perform selective harvest through vibration. Despite the presence of green and cherry beans in the same plants, the mean rate of total hits was higher than 90% in the 1 st HJ (60 days after the beginning of the harvest window), being the most adequate moment for selective harvest.
Although the 2 nd HM is a possible moment to start harvesting, the classifier's rate of hits (63.58%) demonstrates that the similar values of detachment force between green and cherry beans hamper the automated differentiation, making the selective harvest less efficient and, therefore, not recommended for these experimental conditions. In addition, the maturity level with 50% of green beans at this moment will also lead to reduction in coffee drink quality and increase in the number of operations during harvest (Oliveira et al., 2007;Santinato et al., 2015).
In the 1 st HJ, the average rate of hits according to the NN classifier was 94.17%, indicating that this was an adequate moment to automatically distinguish green beans from cherry beans, based on the detachment forces. Given the high rate of hits of the classifier and maturity level with about 70% cherry beans, this moment proved to be the most adequate to start the selective harvest for the conditions of the present study.