# A Review of Convolutional Neural Network Applied to Fruit Image Processing
## 8 Deep Learning Frameworks and CNN-Based Examples
### CNN-Based Examples for Fruit Classification
#### 8.2.1 Example of Fruit Classification  
For classification, we used the dataset Fruit-360 [70], which contains 82,213 images (\(100\times 100\) pixels) of fruits and vegetables of 120 classes, already subdivided into training and test sets. We selected six categories (three kind of apples and pears) from the dataset--Apple Golden 1, Apple Pink Lady, Apple Red 1, Pear Red, Pear Williams, and Pear Monster. Once the categories have been selected to carry out the classification study, the next step is to design the CNN architecture. Figure 10 depicts the CNN architecture adopted in this case. We designed a CNN with quite simple architecture comprised of the input layer, three convolutional layers, a flattening layer, one fully connected layer, and the output layer. We train our model by 10 epochs and using the Stochastic Gradient Descent (SGD) optimizer with momentum. Firstly, all filters are randomly initialized from a normal distribution and all biases are equal zero. Some of the network adjustment parameters are indicated in Table 4, which were fixed by applying a coarse-to-fine grid strategy on a small part of the training set. First, a set of parameters was defined, which was varied in combination as a small number of training epochs (3-5) were executed. According to the preliminary obtained results, the parameters were refined to then execute a greater number of training epochs and set those for which the best training performance was obtained. We perform 10-fold cross-validation on the database aiming to obtain unbiased results in our experiments. Besides, we separate 10% of the training data for validation purposes. Thus, our training set was comprised of 2779 images and 307 images in the validation set. Figure 11 shows the average loss and accuracy curves during the model training process. The \(x\)-axis represents the training epoch number. It should be noted that from the 5 th-epoch, the loss value is close to 0, and the accuracy result is close to 1 for both training and validation. These training and validation results seem to be perfect due to the low variability of the used dataset. Figure 10: Designed CNN architecture for fruit classification. After the training process, we evaluate our model on 1034 testing images. In Figure 12, we show the activation maps obtained by the 3 rd convolution layer for an Apple Pink Lady and a Pear Williams. It is noticeable the differences between both fruits based on their activation maps, which are later used by the fully connected layers to make the class predictions. Figure 13 depicts the confusion matrix for classification results on the testing image set, where it can be noted the misclassifications between Pear Red, Apple Red 1, and Apple Pink Lady classes. The final average accuracy was 95.45% with an average F1-score of 0.96. In addition to the previous example and aiming to compare the performance, we implemented deeper CNN solutions based on well-known pre-trained models with the Imagenet dataset [64] to compare their performance. For this purpose, we used architectures with different depths, including the most used models in the literature for fruit classification (see Figure 8a). Although the used dataset is different from Imagenet, in order to bring an example as simple as possible, we avoided optimizing the pre-trained model for the used dataset. Hence, we loaded each pre-trained model with the learned weights on Imagenet and froze their convolutional base. Then, we changed their top FC layers by adding one FC layer and modifying the number of outputs to six classes. Table 5 summarizes the results for each model. We perform the training process by using the same settings as in the initial example to obtain comparable results, which means the same input shape and batch size, 10-fold cross-validation, same training-validation-testing split, 10 training epochs, and the SGD optimizer with the same learning rate and momentum.