# A Novel Model to Detect and Classify Fresh and Damaged Fruits to Reduce Food Waste Using a Deep Learning Technique

Authors: T. Bharath Kumar; Deepak Prashar; Gayatri Vaidya; Vipin Kumar; S. Deva Kumar; F. Sammy
Journal: Journal of Food Quality
 (2022)

---

## Abstract

Due to a lack of efficient measures for dealing with food waste at many levels, including food supply chains, homes, and restaurants, the world’s food supply is shrinking at an alarming pace. In both homes and restaurants, overcooking and other factors are to be blamed for the majority of food that is wasted. Families are the primary source of food waste, and we sought to reduce this by identifying fresh and damaged food. In agriculture, the detection of rotting fruits becomes crucial. Despite the fact that people routinely classify healthy and rotten fruits, fruit growers find it ineffective. In contrast to humans, robots do not grow tired from doing the same thing again and again. Because of this, finding faults in fruits is a declared objective of the agricultural business in order to save labour, waste, manufacturing costs, and time spent on the process. An infected apple may infect a healthy one if the defects are not discovered. Food waste is more likely to occur as a consequence of this, which causes several problems. Input images are used to identify healthy and deteriorated fruits. Various fruits were employed in this study, including apples, bananas, and oranges. For classifying photographs into fresh and decaying fruits, softmax is used, while CNN obtains fruit image properties. A dataset from Kaggle was used to evaluate the suggested model’s performance, and it achieved a 97.14 percent accuracy rate. The suggested CNN model outperforms the current methods in terms of performance.


---

## Body

## 1. Introduction

The population of the country is increasing day by day, but we do not have adequate availability of food supply for them. This problem is increasing day by day as per the reports disclosed by the FAO [1]. Every year, the world generates 1.3 billion tonnes of edible food waste. Food waste emits 3.3 billion tonnes of CO2 each year, which is comparable to GHG emissions released into the atmosphere. The total volume of water required to create food that is lost or squandered each year is similar to the annual flow of Russia’s Volga River or three times the volume of Lake Geneva. Similarly, 1.4 billion hectares of land are utilised each year to produce food that is lost or squandered, accounting for 28% of worldwide agricultural acreage [2, 3]. Target 12.3 of the Sustainable Development Goals (SDGs) aims to cut global food waste in retail and consumer settings in half by 2030, as well as reduce food losses, particularly postharvest losses, along supply chains. In support of this critical goal, UNEP’s first Food Waste Index report offers insights into the scope of food waste as well as a framework for governments to establish baselines and track progress toward the SDG target. Food waste from families, retail outlets, and the food service industry are estimated to total 931 million tonnes per year, according to the report. Nearly 570 million tonnes of this trash are generated at home [4, 5]. The analysis also finds that the global average of 74 kg of food lost per capita per year is strikingly similar across low-, middle-, and high-income countries, implying that most countries have the potential to improve [6]. On the other hand, food waste is also increasing in different ways such as package, retail, postharvesting, storage, and household. Reducing food waste is also identified by the world and placed as one of the important goals in Sustainability Development Goals (SDG 12.3) [7]. At the same time, the literature and reports are confirming that the majority of food waste is coming from households in the country. All household waste food items are due to damage, overcooking, plate waste, spoiled food, etc. [8, 9]. All these food items will be kept inside the refrigerator to safeguard for some time, and then, they are used based on the requirement. However, the majority of people do not know whether the food items kept inside are fresh, damaged, already had an expiry date, and so on because the majority of the people are using the traditional fridges as smart fridges are expensive [10, 11]. Traditional refrigerators use cutting-edge technologies like IoT and deep learning to recognize the food stored within. We can utilize certain sensors to detect the expiry date of the packaged item kept inside the refrigerator, and the user will receive a message informing them of the food item’s expiry date. So, the research is conducted on reusing the traditional fridges by incorporating devices like cameras in compartments, and also, the models are developed to calculate how to best accurately identify the food inside the fridge using deep learning techniques [12]. Detecting the image or classifying the food items are done very well with convolutional neural networks (CNNs). This paper focused on detecting the three types of fruits, namely, oranges, apples, and bananas, in fresh and damaged states [13]. Fruit classification is a difficult subject to solve since fruits come in a variety of forms, colors, sizes, textures, and other characteristics. A dependable and sturdy solution to this challenge can be used in a variety of ways. Supermarket price determination is one feasible and much-needed application of such a technology. Fruit classification is a crucial activity performed by cashiers at supermarket checkout counters. For pricing determination, these cashiers must be able to identify not just the fruit type but also the variety [14, 15]. Food waste at retail and consumer levels must be reduced, and supply chain losses must be minimized in order to meet SDG 12.3. There are two ways this Food Waste Index report intends to contribute to the achievement of SDG 12.3.First, it includes the most thorough data collection, analysis, and modelling on food waste to date, resulting in an updated estimate of worldwide food waste. While confidence intervals for estimates vary by region and sector, country-level estimates of food waste provide new insight into the scope of the problem and the enormous preventive potential in low-, middle-, and high-income nations. Second, by assessing food waste at the household, food service, and retail levels, this study gives governments a mechanism for tracking national progress toward the zero-food waste target [16]. This technique can be used by governments to create solid data to inform national food waste prevention programmes. Individuals of all ages and walks of life are affected by food waste. One-third of the food produced for human consumption is thrown away every year. Previously, deep learning approaches surpassed numerous well-established algorithms in comparable areas, such as image classification, in the past [17]. Data samples are processed using reduced intermediate representations, making feature extraction methods that need further preprocessing unnecessary. One of the most effective deep learning methods for image categorization is convolutional neural networks. Traditional approaches including k-nearest neighbors, multilayer perception, and support vector machines have been demonstrated to be inferior to convolutional neural networks [18]. In the commercial sector, several organizations use third-party devices to gather data and examine individual contributions to the worldwide issue of food waste detection and reduction. These gadgets keep track of the weight and kind of food that is thrown out (vegetables, fruit, boneless chicken, pasta, etc.). Some businesses are using third-party devices to gather data and evaluate individual contributions to the global food waste issue in order to identify and decrease commercial food waste. The weight and kind of food that is thrown out are recorded by these gadgets (vegetables, fruit, boneless chicken, pasta, etc.) [19]. Using the CNN to assess whether fruits are damaged or fresh is the primary goal of this paper. Similarly, the use of machine learning in minimizing food waste is rising on a daily basis in a wide range of different ways [20, 21]. In order to discover food in the refrigerator, the notion of convolutional neural networks (CNNs) is quite useful. At the same time, we have pretrained models such as ALexa, Google Net, ImageNet, VGG16, and VGG19 to train the datasets in recognizing food photographs. This article is organized as follows: Introduction is given in Section 1, Related Work is described in Section 2, Proposed CNN Model is given in Section 3, Results and Discussion is under Section 4, and Conclusion is given in Section 5.


## 2. Related Work

For total automation, food waste and container classifiers are necessary. A noteworthy contribution of this research is that it emphasizes the need of cleaning the test data while also highlighting the significance of keeping it undisturbed until the very end in order to prevent biasing of our estimate for the out-of-sample error [22, 23]. Deep convolutional neural networks (DCNNs) significantly enhance food recognition accuracy when combined with conventional picture characteristics, Fisher Vectors with HoG, and color patches, according to Yoshiyuki Kawano [24]. Kagaya’s research focuses on the challenges of utilising a convolutional neural network (CNN) to recognise and classify food photographs [25]. Because of the wide variety of foods available, it might be difficult to accurately identify food products by their pictures. Deep learning is made possible with the use of the CNN. It has lately been shown to be a powerful picture recognition tool. In order to aid in the resolution of food-related issues, the CNN was enlisted. Ashutosh deep convolutional neural networks (GoogLeNet) are used to classify and identify foods and nonfoods in this study [26]. As a result, we conducted the experiments utilising the images from publicly available picture databases, as well as images taken using cellphones and portable cameras. An accuracy rate of 99.2 percent accounted for food/nonfood classification, and an accuracy rate of 83.6 percent accounted for food category identification. Using images taken with a mobile or wearable cameras, food identification engines, such as those developed by Ragusa et al., may be useful for tracking a patient’s meal plan and eating habits over time. There is a considerable challenge in the subject of distinguishing between food-related and nonfood-related items [7]. Combining shallow and deep representations, as well as multiclass or single-class classification processes, food and nonfood categorization methodologies are currently in use. There are several ways to tell whether a fruit or vegetable is in good condition. Degrading or fading freshness is the opposite of fresh. Both individual clients and the fresh food trading company could benefit from an automated method for detecting these groups [27, 28]. Research conducted by Frida shows how to use the video camera in the system to capture photographs to construct a system that can recognise fruits and vegetables in a retail store. Weight-based pricing for various fruits and vegetables is available to customers. Based on the superior object-identification technology Faster R-CNN, the proposed detection network, Lite Fully Convolutional Network, contains numerous key improvements to raise accuracy and decrease the time required for conclusion [29]. They used an 80-class dataset of real-world refrigerators to test the usefulness of each component of our method. According to Dubey, realising the concept of a smart city requires the knowledge of both individual and societal motivations [30]. Waste management for a green society should incorporate elements such as automatic lid opening and closing in reaction to human approach to the rubbish, as well as detection of harmful gases. In the name of Raheel and Siddiqi, transfer learning and fine-tuning are examined in this study to see whether they may improve classification accuracy in this position [31]. Inception version 3 and VGG16 models are used for this purpose. To find out how well a forecasting algorithm might anticipate guests’ attendance before and during the pandemic, Malefors said that the study’s purpose was to test the system’s accuracy [32]. Machine learning was used to predict future guest attendance in school and preschool catering facilities in Sweden before and during the outbreak by collecting data on visitor attendance before and during the pandemic. Distinguishing between medium-fresh, pure-fresh, and decaying produce is the most difficult, owing to the little changes between each kind. By assuming that the fruit or vegetable’s class is already known, current approaches attempt to solve the binary conundrum of fresh or rotten food by finding commonalities across a wide variety of fruits and vegetables [33, 34]. The fundamental objective of this project was to lower the price of smart refrigerators for the general public. When it comes to developing a smart refrigerator with the fewest feasible sensors, this project’s major goal is to increase software efficiency to compensate for any sensor or intelligent decision-making shortcomings. In addition, using three large benchmark datasets of small objects, this article analyses the performance of many important deep learning methods for tiny object recognition, including YOLOv3, Faster R-CNN, and SSD. We found that Faster R-CNN beat YOLOv3 despite the poor detection accuracy (less than 0.4) of several deep learning methods on small objects. Many researchers have provided updates to the backbone network, VGG16, to improve semantic and edge information in the feature map. The model’s mAP score was 78.9% on the test set. The ability to locate even the tiniest of targets has increased dramatically [35]. The model presented by researchers to identify fruit items has an accuracy of 92.5 percent. 96 percent of the fruit products were correctly identified using the model presented. Using upgraded deep neural networks, we classify carrot fruits to monitor and reduce waste. We investigate the topic of carrot classification in depth and demonstrate that convolutional neural networks provide a simple solution. We also enhance the convolutional neural network (CNN) by integrating average and max pooling. Compared to previous merging approaches, the employed merging operation boosts the accuracy of the carrot categorization. So, after preprocessing, the enhanced deep CNN categorized 878 carrot samples in varied forms (regular and irregular) [36].


## 3. Proposed CNN Model

### 3.1. CNN Basic Architecture

Deep neural networks have excelled other machine learning systems in terms of performance. In other domains, they also produced some of the earliest achievements in superhuman pattern recognition. Furthermore, it is commonly acknowledged that deep learning is a critical step in the development of Strong AI. Deep neural networks, particularly convolutional neural networks (CNNs), have been demonstrated to be good at recognizing image patterns. We will exhibit results from well-known datasets as well as the strategies we employed. Although less usual, it is possible to pretrain a deep neural network using a deep belief network in the same way as the other networks. Because it may improve network quality and save training time, this process is critical. Convolutional deep belief networks may be used with deep belief networks to produce hybrid designs that combine the best of both worlds. Feature extraction is a convolution tool’s ability to separate and identify an image’s distinguishing qualities. It uses the results of the convolution process to predict the image’s class based on the information gathered in the previous phases.


#### 3.1.1. Convolution Layer

At this stage, the input photographs are being processed to extract their various attributes. AnM × M filter of a certain size is used in this layer to do the mathematical convolution with the input picture. You may get an idea of how much of an effect a certain filter has on a picture by swiping the filter over the input (M × M). As a consequence, a feature map is created, which includes details about the picture such as its corners and edges. Further layers use this feature map as a starting point for learning additional picture characteristics. A convolutional neural network is made up of three basic categories of layers: the convolutional layer, the pooling layer, and the softmax layer. In the convolutional layer, the input picture is convolved with multiple kernels. The pooling layer performs a spatial invariance average or maximum operation to minimise the size of the feature map. The feature extraction module is made up of a convolutional layer and a pooling layer. A convolutional neural network is employed as a feature extractor in this paper. The softmax activation function is used in the softmax layer to categorise input feature maps into class values. They convolute the complete image with different types of kernels and apply feature mapping in the intermediate steps to provide a greater number of feature map outputs. Figure 1 is a block diagram which represents the basic architecture for classification. It consists of two layers which are convolution and pooling. Through these, successful classification is done and several problems related to food wastage have been solved.Figure 1
CNN basic architecture.The following is the general formula for convolution operations:(1)yjl=f∑i=1Njl−1wij∗xil−1+bjl,j=1,2,3,…,M,where yjl indicates the j-th feature map of the convolutional layer, wij indicates the convolutional kernel, ∗ is the symbol of the convolution operation, xil−1 is the i-th feature map of the upper layer, bjl represents the offset of the j-th convolutional kernel of the current layer, Njl−1 reflects the total number of feature maps, M is the total number of feature maps of the convolution layer, and f(·) is the activation function. In CNN applications, the sigmoid, tanh, and rectified linear unit (ReLU) activation functions are among the available options. In comparison to the other functions, the ReLU function is much quicker to compute while still delivering decent results. As a result, we are activating the ReLU feature. The definition of the ReLU function is as follows:(2)fx=x,ifx>0,0,otherwise.


#### 3.1.2. Pooling Layers

By reducing the amount of the convolutional layer’s output, a technique known as pooling layers may cut computing costs and prevent overfitting. Pooling methods based on average and maximum pooling are most often employed. Using the maximum pooling approach for downsampling in this investigation allowed the computation to swiftly converge. The pooling layers each utilize a 2 2 subsampling frame.(3)yJl=f1n∑i=1Njl−1xil−1+bjl,where yjln denotes the window size from the convolutional layer to the sampling layer and j indicates the j-th feature map after pooling, ∑i=1Njl−1xil−1 means the downsampling process, and f(·) is the pooling function. Pooling and convolutional layers are linked in an alternating fashion. Network depth increases the total number of retrieved feature maps, but the size decreases. The qualities that were culled have a greater range of nuance.


#### 3.1.3. Fully Coupled Layers

Fully connected layers in neural networks are what make people think in a sophisticated way. The convolution and pooling layers hide them from view, but they are present. The inputs of the totally linked layer are completely linked to the outputs of the layer in front of it. The completely linked layer turns the 2D feature map into a 1D feature vector that can be used to classify things. In order to figure out the connection layer, we use the following formula:(4)hw,bx=fwxT+b,where hw,bx represents the neuron outcome, x represents the data eigenvector, w represents the weight vector, b represents the offset vector, f(·) represents the activation function, and x represents the input eigenvector. By disconnecting a predetermined percentage of neurons after training, the network is able to generalize better and prevent overfitting.(1) Dropout. The training dataset is prone to overfitting if all of the attributes are connected to the FC layer. When applied to new data, a model that outperforms on training data suffers. Dropout layers are used to address this issue by removing a few neurons from the neural network during training, resulting in a smaller model that is easier to train and understand. After passing a dropout of 0.3, the neural network randomly loses 30% of its nodes.(2) The Function of Activation. The CNN model’s activation function, last but not the least, is critical. They are employed in the learning and estimation of any continuous and complex network variable-to-variable relationship. In a nutshell, it specifies which model information should be passed forward and which should not. Adding nonlinearity to the network makes it more interesting. It is usual to utilise activation functions such as sigmoid and ReLU in neural networks. A specific usage for each of these routines may be found in the code. Sigmoid and softmax functions are preferred for binary classification CNN models, whereas softmax is used for multiclass classification.


### 3.2. Model Architecture

The proposed CNN model architecture is shown in Figure2, and a block diagram of the proposed model is shown in Figure 3.Figure 2
Proposed CNN model architecture.Figure 3
Block diagram of the proposed model.


#### 3.2.1. Implementation

TensorFlow is a free and open-source end-to-end machine learning platform. Data flow and differentiable programming are used in this symbolic mathematics toolbox for deep neural network training and inference. It gives programmers access to a wide range of open-source tools, frameworks, and resources for creating machine learning applications. TensorFlow, developed by Google, is the most well-known deep learning framework at the moment.Keras is a high-level deep learning API created by Google for neural network implementation. It is written in Python and is used to build neural networks.


### 3.3. Dataset Preparation

The dataset is downloaded fromhttps://Kaggle.com, and it consists of 6 classes (3 Fresh, 3 Rotten); we applied the preprocessing techniques on the images, such as labeling and resizing. The data is split into two parts: train data and test data. The total number of images is about 8400; 90% of images from each class are trained by the model, and 10% of them are used for testing.


#### 3.3.1. Labeling

In every class, all images are labeled for improving the chances of recognition by the model and maintain uniformity in the dataset as mentioned in Table1.Table 1
Number of images in each class for training.
S. no.ClassNo. of imagesLabel_trainLabel_test1Fresh apples1260FA1..1260FA1..1402Fresh oranges1260FreshO1..1260FreshO1..1403Fresh bananas1260FB1..1260FB1..1404Rotten apples140Rotten1..1260Rotten1..1405Rotten oranges140RottenO1..1260RottenO1..1406Rotten bananas140RottenB1..1260RottenB1..140Total8400


#### 3.3.2. Resizing

In the dataset, all images of each class are resized to 256 × 256 using the Python Imaging Library (PIL) and saved to the specified folder.


## 3.1. CNN Basic Architecture

Deep neural networks have excelled other machine learning systems in terms of performance. In other domains, they also produced some of the earliest achievements in superhuman pattern recognition. Furthermore, it is commonly acknowledged that deep learning is a critical step in the development of Strong AI. Deep neural networks, particularly convolutional neural networks (CNNs), have been demonstrated to be good at recognizing image patterns. We will exhibit results from well-known datasets as well as the strategies we employed. Although less usual, it is possible to pretrain a deep neural network using a deep belief network in the same way as the other networks. Because it may improve network quality and save training time, this process is critical. Convolutional deep belief networks may be used with deep belief networks to produce hybrid designs that combine the best of both worlds. Feature extraction is a convolution tool’s ability to separate and identify an image’s distinguishing qualities. It uses the results of the convolution process to predict the image’s class based on the information gathered in the previous phases.


### 3.1.1. Convolution Layer

At this stage, the input photographs are being processed to extract their various attributes. AnM × M filter of a certain size is used in this layer to do the mathematical convolution with the input picture. You may get an idea of how much of an effect a certain filter has on a picture by swiping the filter over the input (M × M). As a consequence, a feature map is created, which includes details about the picture such as its corners and edges. Further layers use this feature map as a starting point for learning additional picture characteristics. A convolutional neural network is made up of three basic categories of layers: the convolutional layer, the pooling layer, and the softmax layer. In the convolutional layer, the input picture is convolved with multiple kernels. The pooling layer performs a spatial invariance average or maximum operation to minimise the size of the feature map. The feature extraction module is made up of a convolutional layer and a pooling layer. A convolutional neural network is employed as a feature extractor in this paper. The softmax activation function is used in the softmax layer to categorise input feature maps into class values. They convolute the complete image with different types of kernels and apply feature mapping in the intermediate steps to provide a greater number of feature map outputs. Figure 1 is a block diagram which represents the basic architecture for classification. It consists of two layers which are convolution and pooling. Through these, successful classification is done and several problems related to food wastage have been solved.Figure 1
CNN basic architecture.The following is the general formula for convolution operations:(1)yjl=f∑i=1Njl−1wij∗xil−1+bjl,j=1,2,3,…,M,where yjl indicates the j-th feature map of the convolutional layer, wij indicates the convolutional kernel, ∗ is the symbol of the convolution operation, xil−1 is the i-th feature map of the upper layer, bjl represents the offset of the j-th convolutional kernel of the current layer, Njl−1 reflects the total number of feature maps, M is the total number of feature maps of the convolution layer, and f(·) is the activation function. In CNN applications, the sigmoid, tanh, and rectified linear unit (ReLU) activation functions are among the available options. In comparison to the other functions, the ReLU function is much quicker to compute while still delivering decent results. As a result, we are activating the ReLU feature. The definition of the ReLU function is as follows:(2)fx=x,ifx>0,0,otherwise.


### 3.1.2. Pooling Layers

By reducing the amount of the convolutional layer’s output, a technique known as pooling layers may cut computing costs and prevent overfitting. Pooling methods based on average and maximum pooling are most often employed. Using the maximum pooling approach for downsampling in this investigation allowed the computation to swiftly converge. The pooling layers each utilize a 2 2 subsampling frame.(3)yJl=f1n∑i=1Njl−1xil−1+bjl,where yjln denotes the window size from the convolutional layer to the sampling layer and j indicates the j-th feature map after pooling, ∑i=1Njl−1xil−1 means the downsampling process, and f(·) is the pooling function. Pooling and convolutional layers are linked in an alternating fashion. Network depth increases the total number of retrieved feature maps, but the size decreases. The qualities that were culled have a greater range of nuance.


### 3.1.3. Fully Coupled Layers

Fully connected layers in neural networks are what make people think in a sophisticated way. The convolution and pooling layers hide them from view, but they are present. The inputs of the totally linked layer are completely linked to the outputs of the layer in front of it. The completely linked layer turns the 2D feature map into a 1D feature vector that can be used to classify things. In order to figure out the connection layer, we use the following formula:(4)hw,bx=fwxT+b,where hw,bx represents the neuron outcome, x represents the data eigenvector, w represents the weight vector, b represents the offset vector, f(·) represents the activation function, and x represents the input eigenvector. By disconnecting a predetermined percentage of neurons after training, the network is able to generalize better and prevent overfitting.(1) Dropout. The training dataset is prone to overfitting if all of the attributes are connected to the FC layer. When applied to new data, a model that outperforms on training data suffers. Dropout layers are used to address this issue by removing a few neurons from the neural network during training, resulting in a smaller model that is easier to train and understand. After passing a dropout of 0.3, the neural network randomly loses 30% of its nodes.(2) The Function of Activation. The CNN model’s activation function, last but not the least, is critical. They are employed in the learning and estimation of any continuous and complex network variable-to-variable relationship. In a nutshell, it specifies which model information should be passed forward and which should not. Adding nonlinearity to the network makes it more interesting. It is usual to utilise activation functions such as sigmoid and ReLU in neural networks. A specific usage for each of these routines may be found in the code. Sigmoid and softmax functions are preferred for binary classification CNN models, whereas softmax is used for multiclass classification.


## 3.1.1. Convolution Layer

At this stage, the input photographs are being processed to extract their various attributes. AnM × M filter of a certain size is used in this layer to do the mathematical convolution with the input picture. You may get an idea of how much of an effect a certain filter has on a picture by swiping the filter over the input (M × M). As a consequence, a feature map is created, which includes details about the picture such as its corners and edges. Further layers use this feature map as a starting point for learning additional picture characteristics. A convolutional neural network is made up of three basic categories of layers: the convolutional layer, the pooling layer, and the softmax layer. In the convolutional layer, the input picture is convolved with multiple kernels. The pooling layer performs a spatial invariance average or maximum operation to minimise the size of the feature map. The feature extraction module is made up of a convolutional layer and a pooling layer. A convolutional neural network is employed as a feature extractor in this paper. The softmax activation function is used in the softmax layer to categorise input feature maps into class values. They convolute the complete image with different types of kernels and apply feature mapping in the intermediate steps to provide a greater number of feature map outputs. Figure 1 is a block diagram which represents the basic architecture for classification. It consists of two layers which are convolution and pooling. Through these, successful classification is done and several problems related to food wastage have been solved.Figure 1
CNN basic architecture.The following is the general formula for convolution operations:(1)yjl=f∑i=1Njl−1wij∗xil−1+bjl,j=1,2,3,…,M,where yjl indicates the j-th feature map of the convolutional layer, wij indicates the convolutional kernel, ∗ is the symbol of the convolution operation, xil−1 is the i-th feature map of the upper layer, bjl represents the offset of the j-th convolutional kernel of the current layer, Njl−1 reflects the total number of feature maps, M is the total number of feature maps of the convolution layer, and f(·) is the activation function. In CNN applications, the sigmoid, tanh, and rectified linear unit (ReLU) activation functions are among the available options. In comparison to the other functions, the ReLU function is much quicker to compute while still delivering decent results. As a result, we are activating the ReLU feature. The definition of the ReLU function is as follows:(2)fx=x,ifx>0,0,otherwise.


## 3.1.2. Pooling Layers

By reducing the amount of the convolutional layer’s output, a technique known as pooling layers may cut computing costs and prevent overfitting. Pooling methods based on average and maximum pooling are most often employed. Using the maximum pooling approach for downsampling in this investigation allowed the computation to swiftly converge. The pooling layers each utilize a 2 2 subsampling frame.(3)yJl=f1n∑i=1Njl−1xil−1+bjl,where yjln denotes the window size from the convolutional layer to the sampling layer and j indicates the j-th feature map after pooling, ∑i=1Njl−1xil−1 means the downsampling process, and f(·) is the pooling function. Pooling and convolutional layers are linked in an alternating fashion. Network depth increases the total number of retrieved feature maps, but the size decreases. The qualities that were culled have a greater range of nuance.


## 3.1.3. Fully Coupled Layers

Fully connected layers in neural networks are what make people think in a sophisticated way. The convolution and pooling layers hide them from view, but they are present. The inputs of the totally linked layer are completely linked to the outputs of the layer in front of it. The completely linked layer turns the 2D feature map into a 1D feature vector that can be used to classify things. In order to figure out the connection layer, we use the following formula:(4)hw,bx=fwxT+b,where hw,bx represents the neuron outcome, x represents the data eigenvector, w represents the weight vector, b represents the offset vector, f(·) represents the activation function, and x represents the input eigenvector. By disconnecting a predetermined percentage of neurons after training, the network is able to generalize better and prevent overfitting.(1) Dropout. The training dataset is prone to overfitting if all of the attributes are connected to the FC layer. When applied to new data, a model that outperforms on training data suffers. Dropout layers are used to address this issue by removing a few neurons from the neural network during training, resulting in a smaller model that is easier to train and understand. After passing a dropout of 0.3, the neural network randomly loses 30% of its nodes.(2) The Function of Activation. The CNN model’s activation function, last but not the least, is critical. They are employed in the learning and estimation of any continuous and complex network variable-to-variable relationship. In a nutshell, it specifies which model information should be passed forward and which should not. Adding nonlinearity to the network makes it more interesting. It is usual to utilise activation functions such as sigmoid and ReLU in neural networks. A specific usage for each of these routines may be found in the code. Sigmoid and softmax functions are preferred for binary classification CNN models, whereas softmax is used for multiclass classification.


## 3.2. Model Architecture

The proposed CNN model architecture is shown in Figure2, and a block diagram of the proposed model is shown in Figure 3.Figure 2
Proposed CNN model architecture.Figure 3
Block diagram of the proposed model.


### 3.2.1. Implementation

TensorFlow is a free and open-source end-to-end machine learning platform. Data flow and differentiable programming are used in this symbolic mathematics toolbox for deep neural network training and inference. It gives programmers access to a wide range of open-source tools, frameworks, and resources for creating machine learning applications. TensorFlow, developed by Google, is the most well-known deep learning framework at the moment.Keras is a high-level deep learning API created by Google for neural network implementation. It is written in Python and is used to build neural networks.


## 3.2.1. Implementation

TensorFlow is a free and open-source end-to-end machine learning platform. Data flow and differentiable programming are used in this symbolic mathematics toolbox for deep neural network training and inference. It gives programmers access to a wide range of open-source tools, frameworks, and resources for creating machine learning applications. TensorFlow, developed by Google, is the most well-known deep learning framework at the moment.Keras is a high-level deep learning API created by Google for neural network implementation. It is written in Python and is used to build neural networks.


## 3.3. Dataset Preparation

The dataset is downloaded fromhttps://Kaggle.com, and it consists of 6 classes (3 Fresh, 3 Rotten); we applied the preprocessing techniques on the images, such as labeling and resizing. The data is split into two parts: train data and test data. The total number of images is about 8400; 90% of images from each class are trained by the model, and 10% of them are used for testing.


### 3.3.1. Labeling

In every class, all images are labeled for improving the chances of recognition by the model and maintain uniformity in the dataset as mentioned in Table1.Table 1
Number of images in each class for training.
S. no.ClassNo. of imagesLabel_trainLabel_test1Fresh apples1260FA1..1260FA1..1402Fresh oranges1260FreshO1..1260FreshO1..1403Fresh bananas1260FB1..1260FB1..1404Rotten apples140Rotten1..1260Rotten1..1405Rotten oranges140RottenO1..1260RottenO1..1406Rotten bananas140RottenB1..1260RottenB1..140Total8400


### 3.3.2. Resizing

In the dataset, all images of each class are resized to 256 × 256 using the Python Imaging Library (PIL) and saved to the specified folder.


## 3.3.1. Labeling

In every class, all images are labeled for improving the chances of recognition by the model and maintain uniformity in the dataset as mentioned in Table1.Table 1
Number of images in each class for training.
S. no.ClassNo. of imagesLabel_trainLabel_test1Fresh apples1260FA1..1260FA1..1402Fresh oranges1260FreshO1..1260FreshO1..1403Fresh bananas1260FB1..1260FB1..1404Rotten apples140Rotten1..1260Rotten1..1405Rotten oranges140RottenO1..1260RottenO1..1406Rotten bananas140RottenB1..1260RottenB1..140Total8400


## 3.3.2. Resizing

In the dataset, all images of each class are resized to 256 × 256 using the Python Imaging Library (PIL) and saved to the specified folder.


## 4. Results and Discussion

### 4.1. Platform and Specifications

The research work was implemented on Jupyter Notebook on Anaconda Navigator. The important python libraries such as TensorFlow and Keras were also integrated before proceeding to the coding part. At the same time, the system configuration was increased as mentioned in Table 2 due to working with an adequate number of images in the dataset.The model is trained with 7560 images and tested with 840 images. The training accuracy was 98.4%, and the test accuracy was 97.14%. Figure4 shows the model accuracy during training and validation, whereas Figure 5 shows the loss during the training and testing phase. Table 2 shows specifications used for the predictions, and Table 3 focuses on different parameters used. Figure 4 depicts the accuracy of the model during training and validation loss. It shows that with increase in the number of epochs, the model gives more accuracy. When the batch size increases, the accuracy will be decreased as observed in the implementation:Steps_per_epoch = train_data_size//BATCH_SIZEValidation steps = test_data_size//BATCH_SIZEFigure 4
Accuracy of the model during training and validation loss.Figure 5
Loss during training and testing the dataset.Table 2
Specifications used for the predictions.
S. no.CategorySpecification1RAM16 GB2Processor11th Generation Intel Core i73GraphicsNVIDIA GEFORCE RTX 3050 GPUTable 3
Different hyperparameters used.
OptimizerAdamMetricsAccuracyLosscategorical_crossentropyEpochs100Image size56Learning rate0.001


### 4.2. Comparison of Models with Existing Techniques

Table4 shows the comparison of different models with the proposed model. It is found that the proposed model is able to enhance the performance when compared to various existing models.Table 4
Comparison of models with existing techniques.
S. no.State-of-the-art methodsAccuracy (%)1Wu, A., Zhu, J., and Ren, T.92.52Wang, L., Li, A., and Tian, X96.73H. Mureşan and M. Oltean96.34The proposed model97.14


## 4.1. Platform and Specifications

The research work was implemented on Jupyter Notebook on Anaconda Navigator. The important python libraries such as TensorFlow and Keras were also integrated before proceeding to the coding part. At the same time, the system configuration was increased as mentioned in Table 2 due to working with an adequate number of images in the dataset.The model is trained with 7560 images and tested with 840 images. The training accuracy was 98.4%, and the test accuracy was 97.14%. Figure4 shows the model accuracy during training and validation, whereas Figure 5 shows the loss during the training and testing phase. Table 2 shows specifications used for the predictions, and Table 3 focuses on different parameters used. Figure 4 depicts the accuracy of the model during training and validation loss. It shows that with increase in the number of epochs, the model gives more accuracy. When the batch size increases, the accuracy will be decreased as observed in the implementation:Steps_per_epoch = train_data_size//BATCH_SIZEValidation steps = test_data_size//BATCH_SIZEFigure 4
Accuracy of the model during training and validation loss.Figure 5
Loss during training and testing the dataset.Table 2
Specifications used for the predictions.
S. no.CategorySpecification1RAM16 GB2Processor11th Generation Intel Core i73GraphicsNVIDIA GEFORCE RTX 3050 GPUTable 3
Different hyperparameters used.
OptimizerAdamMetricsAccuracyLosscategorical_crossentropyEpochs100Image size56Learning rate0.001


## 4.2. Comparison of Models with Existing Techniques

Table4 shows the comparison of different models with the proposed model. It is found that the proposed model is able to enhance the performance when compared to various existing models.Table 4
Comparison of models with existing techniques.
S. no.State-of-the-art methodsAccuracy (%)1Wu, A., Zhu, J., and Ren, T.92.52Wang, L., Li, A., and Tian, X96.73H. Mureşan and M. Oltean96.34The proposed model97.14


## 5. Conclusion

The results demonstrate that the suggested CNN model is capable of correctly differentiating between the fresh and rotten fruits and that it beats existing strategies in the process. The proposed CNN model would, as a result, automate the human brain’s function of distinguishing between the fresh and rotten fruits, reducing the likelihood of human mistake in fruit classification. An accuracy of 97.14 percent is achieved by using the proposed CNN model. The scope of this study will be broadened in the future to cover a greater variety of classified fruits and vegetables, increasing the chance of reducing food waste, which is a big concern in today’s contemporary society.



---

*Source: 4661108-2022-05-23.xml*