## 3 Application of the Proposed Method to the Fruit Variety Classification
### Research Method  
#### 3.2.1 CNN for Fruit Classification  
In the proposed fruit classification method, the inference procedure based on CNN is used several times for classification of one variety of fruit. Therefore, the CNN architecture should be as simple as possible, with the goal of handling the task of classification with the highest possible prediction accuracy. By advancing previous research [1; 23], we present a simplified CNN architecture in Table 1. This CNN model has been tested for the variety classification of apples.  
\begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**Layer** & **Purpose** & **Filter** & **No of Filters** & **Weights** & **Bias** & **Activation** \\ \hline
1 & Image input layer & & & & & \(150\times 50\times 3\) \\
2 & Convolution + ReLU & \(3\times 3\) & 32 & \(3\times 3\times 3\times 32\) & \(1\times 1\times 32\) & \(148\times 148\times 32\) \\
3 & Max\_pooling & \(2\times 2\) & & & & \(74\times 74\times 32\) \\
4 & Convolution + ReLU & \(3\times 3\) & 64 & \(3\times 3\times 32\times 64\) & \(1\times 1\times 64\) & \(72\times 72\times 64\) \\
5 & Max\_pooling & \(2\times 2\) & & & & \(36\times 36\times 64\) \\
6 & Flatten & & & & \(1\times 1\times 82,944\) \\
7 & Drop out & & & & & \(1\times 1\times 82,944\) \\
8 & Fully connected + ReLU & & & \(64\times 82,944\) & \(64\times 1\) & \(1\times 1\times 64\) \\
9 & Fully connected + Softmax & & & \(6\times 64\) & \(6\times 1\) & \(1\times 1\times 6\) \\  & \multicolumn{3}{c}{Output layer} & & \(1\times 1\times 6\) \\ \hline \hline \end{tabular}
\end{table}
Table 1: An architecture of the CNN model for fruit classification.  
Here, we propose a deep neural network model architecture with 9 layers of neurons. The first layer is an input layer that contains \(150\times 150\times 3\) neurons (RGB image with \(150\times 150\times 3\) pixels as a resized image with \(320\times 258\times 3\) pixels). The next 4 layers constitute two tracks with convolution pooling layers that use receptive field (convolutional kernels) of size \(3\times 3\) with no stride and no padding. The layers give 32 and 64 features maps, respectively. The convolution layers use nonlinear ReLU (Rectifier Linear Unit) activation functions as follows [24]:  
\[ReLU(x)=\max(0,x). \tag{1}\]  
This function reduces (turns into zero) the number of parameters in the network, resulting in faster learning. To reduce dimensionality and simultaneously capture the features contained in the sub-regions binned, the max pooling strategy [25] is used in the 3 rd and 5 th layers. The convolutional and max-pooling layers extract features from image. Then, in order to classify the fruits, the fully-connected layers are applied to the previous dropout layer. Dropout is applied to each element within the feature maps (with a 50% chance of setting inputs to zero), thus allowing for randomly dropping units (along with their connections) from the neural network during training and helping prevent overfitting by adding noise to its hidden units [26].  
The 8 th layer provides 64 ReLU fully-connected neurons. The last layer as a final classifier has the 6 Softmax neurons, which correspond to the six varieties of apples.  
To train the CNN model (optimize its weights and biases), the Adam (Adaptive moment estimation) algorithm [27] was employed with cross entropy as the loss function. The Adam algorithm is a computationally-efficient extension of the stochastic gradient descent method.  
The presented architecture of the CNN model was tested for fruit classification in three different ways. First, the network was trained (and validated) with image data from apple objects (original images). Second, the network was trained (and validated) with training data for a single apple object (called the image with the apple or ROI as the Region Of Interest). Finally, the network was trained (and validated) with the both training data. In all cases, different network weights were obtained for the same CNN model. All trained CNN models were tested using the same testing data.