# Local Vegetable Freshness Classification Based on Chronological Monitoring Using Transfer Learning Approach

Mahedi Hasan Abeer, Meherun Nessa Lamia, Jannatul Feardous Nafsi, Fabia

Chowdhury, Mahi Sarwar Anol, Md. Sazzadur Ahamed

► To cite this version:

Mahedi Hasan Abeer, Meherun Nessa Lamia, Jannatul Feardous Nafsi, Fabia Chowdhury, Mahi Sarwar Anol, et al.. Local Vegetable Freshness Classification Based on Chronological Monitoring Using Transfer Learning Approach. 6th International Conference on Computational Intelligence in Data Science (ICCIDS), Feb 2023, Chennai, India. pp.50-66, 10.1007/978-3-031-38296-3_5. hal-05466040

HAL Id: hal-05466040

https://inria.hal.science/hal-05466040v1

Submitted on 19 Jan 2026

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons CC BY 4.0 - Attribution - International License
<figure><img src="image_2.png" /></figure>

ifip

International Federation for Information Processing

This document is the original author manuscript of a paper submitted to an IFIP
conference proceedings or other IFIP publication by Springer Nature. As such, there
may be some differences in the official published version of the paper. Such
differences, if any, are usually due to reformatting during preparation for publication or
minor corrections made by the author(s) during final proofreading of the publication
manuscript.
<figure><img src="image_3.png" /></figure>

# Local Vegetable Freshness Classification Based on Chronological Monitoring Using Transfer Learning Approach

Mahedi Hasan Abeer(✉), Meherun Nessa Lamia, Jannatul Feardous Nafsi, Fabia Chowdhury, Mahi Sarwar Anol, and Md. Sazzadur Ahamed

Department of Computer Science and Engineering, Daffodil International University, Dhaka,
Bangladesh

{mahedi15-13786, meherun15-14002, jannatul15-13868, fabia15-14046, mahi15-13664}@diu.edu.bd

**Abstract.** Ensuring good quality vegetables in the diet is one of the primary challenges when it comes to establishing food security. With the advancement of scientific technologies, manual identification for freshness of vegetables is not practical at all as it is time consuming and inaccurate. To solve this issue Implementing a machine vision-based system that can quickly discover the freshness of vegetables through images makes the accuracy level according to our aspiration. Dataset was collected by manually clicking pictures of our selected vegetables. To create a customized dataset, we carefully chose new conditions for three selected vegetables, ‘eggplant’, ‘okra’ and ‘cauliflower’, from the market and prepared the dataset. After collecting six thousand of basic images, we sorted them into 3 categories: fresh, aged, rotten which was decided by physical attributes and image capture time (Day). Association between raw dataset and augmentation, we tried to increase the amount of dataset where we will reach an effortless position to train a dataset. Transfer learning models that are used in the preliminary stage were InceptionV3, Xception, MobileNetV-2, DenseNet201. After practical implementation we got our desired result from DenseNet201. Though all these models give us decent accuracy level but after training DenseNet201 we were able to achieve the accuracy of 97.72%. This study will tremendously diminish the labor cost, and vegetables identification could also be made spontaneously.

**Keywords:** Computer Vision · DenseNet201 · Augmentation · Transfer Learning · Deep Neural network

## 1 Introduction

Vegetables are considered as one of the significant nutritional sources for local Bangladeshi people. Adults are required to maintain 50% of vegetables in their provisions. From the highly horticultural vegetables, eggplant and okra score a very high rank in nutrition, and cauliflower carries the second most nutritious position in winter
vegetables. A vegetable may drop its nutritional value from its firm condition in less than a week hence, consuming fresh vegetables is foremost. Despite the nutrient and cultivation value, the issue is that many vegetables get wasted because of the backdated farming method, including the task of vegetable quality detection and sorting, with human eye dependency. Physically sorting vegetables is time-consuming, labor is expensive, and coordinated eye dependency is ineffectual in handing out precise results. However, being an economically developing nation, the agricultural industry acquired many contemporary techniques. This research on vegetable quality detection is the solution for sorting vegetables in massive amounts and can offer IT support to the horticulture economy.

The rudimentary objective of this research is to automate the freshness detection process of vegetables in real time. The consumer and the marketer can detect fresh vegetables expeditiously at a concurrent time. With the accurate result of the proposed model, the public can make worry-free decisions. The beneficiation of this research draws out some points-

1. Generate a custom dataset and accumulate it for future purposes.

2. Propose an automation model that reduces human eye dependency.

3. Implement deep learning and neural network models for real-time execution.

4. Indirectly help in agricultural food waste by detecting rotten vegetables.

For vegetable detection, we use several transfer learning models. After collecting custom data with the mobile device, we test our data with a pre-trained model DenseNet201, InceptionV3, Xception, and MobileNetV2 for better accuracy of freshness detection.

## 2 Literature Review

In the year 2021, Anuja Bhargava et al. [1] used pre-processing, segmentation and SVM, ANN, SRC, LR for the identification and sorting of various vegetables and fruits based on Machine Learning approach with greater accuracy. Used database contains healthy and defective vegetables and fruits (a total of 25,988 datasets of images) was collected manually by different authors. The max accuracy they have achieved was 96.59%. Meenaxi M Raikara et al. (2020) [2] had suggested a work stand on convolution neural networking techniques. AlexNet, GoogLeNet, ResNet50 was the used model in the work. They had collected 3200 number of image data by themselves. By using restnet50 they had reached the highest accuracy of 99.17%. In the year 2020, Nazrul Ismail [3] and his team came up with an idea of instantaneous visual inspection mechanism for grading fruits using computer vision and deep learning. ReNet-50, MobileNetV2, DenseNetV2, NASNet-A, EfficientNet-B0, EfficientNet-B1, EfficientNet-B2 was used to implement this model. Internal Feeding Worm (IFW) was the used database and they have reached the accuracy of 99.2%.

Nizamettin Erbaş, et al. (2020) [4] come up with an idea which was to classify the quality of hazelnuts using deep Learning Algorithm, Data augmentation & Transfer learning. Alexnet architecture also used in their study. Alexnet architecture. MVTec Anomaly Detection (MVTec 2021) dataset has been used for the implementation & 99% accuracy respectively. In the year 2022 Yaodi Li et al. [5] proposed a study on surface defect identifying of fresh-cut Cauliflowers using Convolutional Neural Network (CNN)
with Transfer Learning. A comparative study was performed by combining VGG19, InceptionV3, and NASNetMobile. For the data set, 479 samples of cauliflower had been selected for data collection and after applying augmentation they succeed to gather 4790 numbers of data for the testing purpose and 99.27% accuracy was achieved, respectively.

Zhenbo Li et al. (2020) [6] offered a research study on vegetable reorganization and classification based on updated VGG on open-source deep learning framework Caffe. To train the vegetable image data set VGG network model had been used. VGG-M network was used in batch normalization layers to improve the convergence. A vegetable image data set was built and expended for training which contains 48,000 images and 96.5% was the max accuracy. Dinesh Kumar J.R et al. (2021) [7] was proposed a study on a systematic ML based concept for the quality analysis of fruits using CNN model. Tasted dataset was collected manually from different fruits. CNN model used to analyze 8 classes of fruits with different materials for predicting high quality fruits. The max accuracy was 99.1%. In the year of 2022 [8] Mohammad Hosseinpour Zarnaq et al. came up with a study of freshness and quality assumption of parsley based on the technology of artificial intelligence and image processing. For feature reduction linear discriminant analysis (LDA) and principal component analysis (PCA) methods were used. It also involved Multilayer perceptron (MLP) neural networks, support vector machine (SVM) and decision trees (DTs) classifiers. For the testing process they have analyzed and collected the dataset manually and reached the max accuracy of 97.22%.

In the year 2022, a comparative analysis based on Convolutional Neural Networks (CNN) and SVMS was proposed by Diclehan Karakaya et al. [9] for fruit freshness classification. Publicly available dataset in Kaggle which contains fresh and rotten apple, banana and orange images and achieved a good amount of accuracy. In the year (2019) Immanuel Anthony Nadar et al. [10] offered a research study of quality analysis on agricultural based on Convolutional Neural Networks (CNN). Other neural such as Artificial Neural Network (ANN), Recurrent Neural Network (RNN) and K-Nearest Neighbours (KNN) for comparative analysis has been used to train the model and for increasing the accuracy. Approximately 13,000 images were collected for the dataset and reached the accuracy of 85%. In the year 2020 a review of convolutional neural network (CNN) based fruit image processing had proposed by Naranjo-Torres et al. [11]. The UEC-FOOD100 dataset used to train the model which contains about 15,000 from 100 classes of food images and the second dataset had 40,000 fruit images. The max accuracy of 95.95% was reached. Predicting sensory evaluation was proposed by Byeong-Hyo Cho et al. [12] in the year of 2021 for evaluating the freshness of spinach. SVM classification and ANN machine learning models was selected for developing the model. Total 230 numbers of input features were used to classify the model and 84% of highest accuracy was reached. Sheng Huang et al. (2021) [13] came up with an idea of classifying eggplant seeds based on machine learning approach and multispectral imaging classification. 1DCNN and 2DCNN was used to train the model. The used dataset of corresponding authors by request. 98.80% was the max accuracy of those models. M. Israk Ahmed et al. (2021) [14] suggested DCNN based image classification of vegetable by the use of transfer learning. CNN was used to see its performance for vegetable. Several pre-trained CNN models were applied for the implementation of the process. CNN architectures (VGG16, MobileNet, InceptionV3, ResNet etc.) was also
used to see which technique works in as best way based on accuracy. The used dataset
contains 21,000 number of images and the dataset was divided in 15 different classes
for the classification. The model's highest accuracy was nearly 99.9% respectively.
Deep learning base multi-class plant disease identifying process was introduced by
Arunabha M. Roy et al. [15] in the year 2021. They had established the model based
on convolution neural networks (CNN), artificial intelligence (AI) and computer vision.
YOLOv4 algorithm was also considered in the study. Available Kaggle Plant-Pathology
Apple Dataset was used to construct the single dataset and also to train the model. 95.9%
max accuracy was obtained.

## 3 Methodology

The primary focus of this study is to find out the Freshness of a vegetable by using Deep
learning and neural network models. The Classification model used multiple vegeta-
bles this will help the neural network layers to detect the freshness of vegetables more
precisely.

<figure><img src="image_4.png" /><figcaption>Fig. 1. Methodology Workflow</figcaption></figure>

3.1 Dataset Description

Proposed research studies Vegetable Quality Degradation over time is conducted to train the dataset using different Transfer learning models to find out the best accuracy for local vegetable image Classification and among them select the appropriate Model for classification. This research is designed to overcome the problems of manual sorting techniques. We anticipated lowering labor costs and enhancing the precision and effectiveness of the sorting process in the agricultural sector. We have chosen different local vegetables that are found all over the world and are nutritious for our well-being. Three categories of vegetables were used for training the dataset with a transfer learning model. The following vegetables were selected for the experiment: Cauliflower, ladies'
fingers (Okra), Eggplant (different shape). For the data collection, we collected freshly cut Cauliflower, ladies' fingers (Okra), and Eggplants of three different shapes in size that are Green round Eggplant, long purple Eggplant, and Purple round Eggplant from the Local market. A sample of the dataset is given in Fig. 1 (Fig. 2).

<figure><img src="image_5.png" /><figcaption>**Fig. 2.** Sample Images of Dataset.</figcaption></figure>

Images of each vegetable were taken from the mobile camera of 12 megapixel. All the images of the vegetables were taken in the natural light source with white background. Around 250 photos were taken per day for a week and saved in \*.jpg format. Every photo has a fixed time duration maintained. We divided the images of three vegetables into 9 classes. For the data collection the total Raw datasets is around 6000, After Augmentation the total images of the dataset is 13140. The Dataset Description is Given in Table 1.

<table><caption>**Table 1.** Dataset description.</caption><thead><tr><td>Classes</td><td>Original Dataset</td><td>Augmented Dataset</td></tr></thead><tbody><tr><td>Fresh Cauliflower</td><td>666</td><td>1460</td></tr><tr><td>Fresh Eggplant</td><td>552</td><td>1460</td></tr><tr><td>Fresh Okra</td><td>711</td><td>1460</td></tr><tr><td>Aged Cauliflower</td><td>507</td><td>1460</td></tr><tr><td>Aged Eggplant</td><td>832</td><td>1460</td></tr><tr><td>Aged Okra</td><td>947</td><td>1460</td></tr><tr><td>Rotten Cauliflower</td><td>576</td><td>1460</td></tr><tr><td>Rotten Eggplant</td><td>623</td><td>1460</td></tr><tr><td>Rotten Okra</td><td>579</td><td>1460</td></tr><tr><td>Total</td><td>6000</td><td>13140</td></tr></tbody></table>
During our research work we used google Collaboratory for implementing our work. Which have NvidiaK80/T4 as GPU with a memory of 12/16 GB with a GPU memory clock of 0.82GHz/1.59GHz. It has a dual core CPU and Ram of 12GB with 357.2 GB disk space.

In this study the number of primary images is more than 6000. Identified all the unusable images where the target object is not clear for the final dataset. To clear the dataset, we dropped all the images that are not focused, blurry, over exposed and under exposed images for clearing the dataset. In a supervised learning model labeling of images is an automated process no need to manually label datasets.

## 3.2 Data Pre-processing

In this research we are using two data pre-processing techniques. It is Data resizing and Data scaling. Data resizing is performed to make sure that our input image is acceptable by the input layer of DenseNet201 architecture and Data scaling will help our model to give better performance and training speed.

## 3.3 Data Resizing

The DenseNet201 architecture contains four main stages just as shown in the reference diagram. This network input architecture can receive an image of height and width which must be strictly greater than 32. It has a channel width of 3.

During our work we resized the dataset image to 224 by 224 to make the input acceptable for the input layer of Network Architecture. So, our actual input is of the form 224x224x3.

## 3.4 Data Scaling

During implementation we collected color images using the camera. A color image corresponds to RGB channels. These parameters of image are generally represented using a separate array of pixels which contains an unsigned integer between range 0 to 255 range.

In data scaling we reduce this range between 0 to 1. Neural networks generally process inputs using small weight values. Input with large integer values can hamper, perhaps slow down the learning operation. To avoid this issue, we can perform normalization. In Normalization we divide every pixel value by 255. As a result we get an array of pixels which will contain unsigned integer values between range 0 to 1.

## 3.5 Cropping Unnecessary Portion

To ensure proper feature extraction of the actual object we decided to crop the unnecessary portion of images. So that the feature extraction probability of the actual object rises.
## 3.6 Storing Data

A sorting operation was performed on the basis of image creation date after the finishing dataset collection. By following this procedure Day 1 and Day 2 from the collected images were stored in a folder named "Fresh". Day 3 to Day 5 was stored in a folder named "Aged". Day 6 and Day 7 was stored in a folder named "Rotten". With Successful accumulation of the images in the desired folder we can be assured that our supervised algorithm will identify and use these folders as classes (Fresh, Aged, Rotten) to train the model.

Finally, we had around 4380 images for each folder corresponding to the actual class after storing the images in the correct folder which was used for the corresponding class.

## 3.7 Data Augmentation

During our work we tried to fit the selected models on a raw dataset. In raw dataset we had around 6000 images. After training the models we didn't had enough satisfactory result. To address the reason behind low performance we tried various methods but still failed to address it. Finally, we decide to increase our dataset.

To increase our dataset, we used Seven data Augmentation techniques. At first, we used rotation range argument. We had a range of -15 to +15. After that we used shear range of 0.2. In each Images. It basically distorts the images along the axis. The main goal behind it is to rectify the perception angles. It basically used to give computer the examples of how human sees an object from different angles. After that we added zoom range argument. It is used for zooming the images. We used 0.2 as parameter. If we specify 0.2 then it will be transformed to [0.2, 1.2] range. Which means zooming in 20% and zooming out 120%. Then we applied horizontal flip and vertical flip for each image. After that we applied different brightness in the range of [0.5, 1.5]. During rotation int some picture our main object got out of the actual frame so we used fill_mode argument with 'constant' as parameter.

In the end we had a dataset of 13140 image. At this point we decided to train our models again to evaluate the result and it worked out. So, the main reason behind low accuracy was less amount of dataset which got fixed with image augmentation.

## 3.8 CNN and Transfer Learning

In deep learning, CNN is a form of multi-layer perceptions that is frequently used for image identification. Because it can handle vast volumes of data, deep learning has proven to be a very powerful resource. Hidden layer technology is much more popular than conventional methods, particularly for pattern recognition. Convolutional Neural Networks are among the most widely used deep neural networks. CNN often begins with an input layer and finishes with an output layer, with several hidden layers existing in between. For training a model Starting from scratch requires a lot of computer hardware and might be time-consuming and tough as CNN needs large scale data, sometimes it is difficult to get the desired result [12]. We implemented the transfer learning method to resolve these issues. Transfer learning is the process by which a pre-trained model picks up knowledge from a big dataset and represents it as weights in a neural network. These
weights are then applied to a separate network with a different dataset and task. As a result, by transferring the first network's learned features to the second network rather than training the second network from scratch.

## InceptionV3

Inception is a Deep neural network. The InceptionV3 is an updated version of InceptionV1. Previously in InceptionV1 there were 1 × 1 convolutional filter before 3 × 3 convolutional layers and 5 × 5 Convolutional layers to reduce the number of dimensions for less use of computational resources. To make this model more accurate. In 2015 InceptionV3 was introduced with factorizing Smaller convolutional blocks which means the network will break the 5 × 5 convolution layer into 3 × 3 two blocks of layer. By using 3 × 3, 3 × 3 + 3 × 3 is equal to 18 parameters which means the number of parameters is reduced from 25. After that this model introduces Factorization into Asymmetric Convolutions to reduce the number of parameters. InceptionV3 has 42 layers and it has better accuracy rate and computational performance power compared to previous models that have been introduced InceptionV1 and InceptionV2.

## Xception

Xception is called an Extreme version of Inception. It is a Convolutional neural network architecture where Depth wise Separable Convolution is involved with a modified version. The pointwise convolution is followed by a depthwise convolution, which is known as depthwise separable convolution. Xception is a better version than InceptionV3. Xception is the reversed idea which is applied on InceptionV3. In the InceptionV3 model the initial input blocks were compressed using 1×1 convolutional layer after that discrete categories of filters on each depth space was used. When Xception is used just the reverse occurs. Rather, it seeks filter for each depth map individually before using 1×1 convolution to flatten the input space. For this reason, Xception has better Accuracy compared with other Inception models that have been proposed.

## MobileNetV2

MobileNetV2 use bottom wise distinct convolutions to assemble light-weight deep neural networks that are ideal for embedded vision and mobile applications. Three convolutional layers are found in the block of MobileNetV2 architecture. In first two blocks there are depthwise convolution that filters the inputs. After that it have a 1 × 1 point to point convolution layer in the third layer which makes the number of channels thinner. For this reason it is called the projection layer—as it reflects data with a higher number of dimensions (channels) into a tensor with a much lower number of dimensions.

## DenseNet201

The method which was used for image classification and quality detection of local vegetables is based on DenseNet201. Densely connected Convolutional Network is very popular because of its architecture which is proposed to be deeper, accurate and efficient to train any large dataset. DenseNet201 creates connection between layers in such a way that the input of a block is inter-connected with all other preceding blocks so that Every
layer gets feature maps from all layers that came before it which allows a denser and
more flexible network with fewer channels.

**Proposed Methodology**

In order to decrease labor costs which is associated with manual sorting, our study's
goal was to determine whether a local vegetable was fresh, edible, or rotten. For that we
have used a pre-trained transfer learning model named 'DenseNet201' which provided
the best performance during feature extraction.

<figure><img src="image_6.png" /><figcaption>Fig. 3. Proposed methodology</figcaption></figure>

In parallel, performance for InceptionV3, Xception, MobileNetV2 was also
observed. After finishing the preprocessing methods. Our Dataset Consists 6000 raw
images of different vegetables after applying augmentation techniques we have accrued
total 13140 images, 8410 Training images, 2102 Validation images and for 2628 testing
images to train the transfer learning model predict more accurately. We have used four
pre-trained Transfer learning models with our customized dataset. We have separately
trained the dataset with the raw images and augmented images.

According to the result table each model shows impressive test accuracy on both the
raw and augmented dataset. But the best model that has performed in feature extraction
is DenseNet201 where the test loss and Accuracy in raw dataset was 0.3245 and 92.73%.
On the other hand, test loss and Accuracy in Augmented dataset was 0.2157 and 97.72%.
Our proposed model for Vegetable freshness Detection is DenseNet201.

The suggested model is used to extract features from the custom dataset.
DenseNet201 is an image Classification Deep learning model. DenseNet overcomes the
Vanishing Gradient problem and provides high accuracy compared to other convolutional
neural network models. Figure 3 shows the architecture of the proposed DenseNet201
Model for evaluating vegetable quality over time (Fig. 4).

Each layer of denseNet201 is interconnected with every other layer. In Densnet
classifiers have features of all complexity which means it takes features from the early
layer of the network where the resolution of the features are high but those features are
not very informative it also takes input from the middle of the layer and takes features
<figure><img src="image_7.png" /><figcaption>Fig. 4. Internal Architecture of proposed transferred DenseNet201</figcaption></figure>

from the last layer which are very complex features. So densenet connects all kinds of features considering simple to complex and collects features maps then it will give you classification on the input images. DenseNet201 improves gradient-flow during training (Fig. 5).

<figure><img src="image_8.png" /><figcaption>Fig. 5. Block Diagram of DenseNet201</figcaption></figure>

In DenseNet we have Dense Blocks and inside that we have convolutional layers. Inside a dense block we concatenate the feature maps where the size of the feature maps remains the same. After Dense Block we have Transition layers. In the transition layer having Conv 1 × 1 and average pool 2 × 2. We down sampling the feature maps that we receive in the output of the previous layer. After performing down sampling this move forward to the next dense block. Each Convolutional layer consists of batch Norm, Relu, Conv 3 × 3, Dropout and Transition layer Consists of Batch Norm, Relu, Conv 1 × 1,DropOut, Pool 2 × 2.

DenseNet201 shows an impressive feature classification in this research. The advantages of using DenseNet201 is in the convolutional layer the features learned by layer 1 are directly accessible by layer 4 which gives an accurate feature map and high classification accuracy rate. In this case Layer 4 does not have to relearn a feature learned by layer 1 because it can access that information via concatenation. As a result DenseNet201 comes handy when it comes to decrease the number of working parameters.
# 4 Result and Discussion

## 4.1 Proposed Model Performance

DenseNet201 was trained for about 210 min on our dataset we were able to achieve some really satisfactory results. We can see the track of overall result in the table below. From the table we can see that the final accuracy was about 97.72%. It is to mention that after augmentation the total image quantity in our dataset was 13140. We can evaluate our model performance through precision, recall, support and f1 score individually also (Table 2).

<table><caption>**Table 2.** Tested model performance</caption><thead><tr><th>Model</th><th>Dataset</th><th>Test Loss</th><th>Test Accuracy</th></tr></thead><tbody><tr><td rowspan="2">InceptionV3</td><td>Raw</td><td>1.5229</td><td>59.95%</td></tr><tr><td>Augmented</td><td>0.5752</td><td>74.86%</td></tr><tr><td rowspan="2">Xception</td><td>Raw</td><td>1.9954</td><td>52.98%</td></tr><tr><td>Augmented</td><td>0.8837</td><td>63.61%</td></tr><tr><td rowspan="2">MobileNet-v2</td><td>Raw</td><td>0.5539</td><td>78.20%</td></tr><tr><td>Augmented</td><td>0.4639</td><td>86.23%</td></tr><tr><td rowspan="2">DenseNet201(Proposed)</td><td>Raw</td><td>0.3245</td><td>92.73%</td></tr><tr><td>Augmented</td><td>0.2157</td><td>97.72%</td></tr></tbody></table>

**Precision:** A number which is calculated by dividing accurately anticipated positive observation by total anticipated positive observation. A High Precision score is achieved when there is less amount of false positive prediction which represents a good fit of a model.

$$ \text{Precision} = \frac{\text{TP}}{(\text{TP} + \text{FP})}. \qquad (1) $$

From the table below we can see that precision for aged cauliflower was 0.97, for aged eggplant it was 0.99, for aged okra it was 0.95, for fresh cauliflower 0.95, for fresh eggplant it was 0.98, for fresh okra it was 0.99, for rotten cauliflower it was 0.99, for rotten eggplant 0.99 and for rotten okra it was 0.99. So we can say that our model is very effective in detecting correct labels.

**Recall:** Recall is a number which is calculated by dividing correctly predicted positive observations by all observations in the actual true class. It gives us an idea of how many we are able to interpret from the actual class.

$$ \text{Recall} = \frac{\text{TP}}{(\text{TP} + \text{FN})}. \qquad (2) $$

From the table below we can see that recall for Aged cauliflower was 0.95, for Aged eggplant it was 0.96, for aged okra it was 0.98, for fresh cauliflower 0.99, for fresh eggplant
it was 1.00, for fresh okra it was 0.96, for rotten cauliflower it's 0.97, for rotten eggplant 0.99 and for rotten okra it was 0.99.

**F1 Score:** A score which is the harmonic mean of Precision and recall. This score takes both false positives and false negatives in consideration. Initially understanding accuracy is not a simple task. F1 score gives us some extra information related to accuracy if there is an uneven class distribution.

$$F1 \text{ Score} = 2 * (\text{Recall} * \text{Precision})/(\text{Recall} + \text{Precision}). \quad (3)$$

From the table below we can see that F1 score for aged cauliflower was 0.96, for aged eggplant it was 0.98, for aged okra it was 0.96, for fresh cauliflower 0.97, for fresh eggplant it was 0.99, for fresh okra it was 0.97, for rotten cauliflower it was 0.97, for rotten eggplant 0.99 and for rotten okra it was 0.99. So we can say that our model is able to recognize most of the test labels properly.

**Accuracy:** An evaluation metric in machine learning which is represented as the ratio between Number of correct predictions and total number of predictions. It gives us an overall idea of our models' prediction performance.

$$\text{Accuracy} = \frac{\text{Number of predictions}}{\text{Total number of Predictions}}. \quad (4)$$

After validation during model evaluation, we were able to achieve the accuracy of 97.72%. Which is quite satisfactory (Fig. 6 and Table 3).

<table><caption>**Table 3.** Model Evaluation result for proposed.</caption><thead><tr><th>Proposed Model</th><th>class</th><th>Precision</th><th>Recall</th><th>support</th><th>f1-score</th><th>Accuracy</th></tr></thead><tbody><tr><td rowspan="8">DenseNet201</td><td>Aged Cauliflower</td><td>0.97</td><td>0.95</td><td>147</td><td>0.96</td><td rowspan="8">97.72%</td></tr><tr><td>Aged Eggplant</td><td>0.99</td><td>0.96</td><td>141</td><td>0.98</td></tr><tr><td>Aged Okra</td><td>0.95</td><td>0.98</td><td>135</td><td>0.96</td></tr><tr><td>Fresh Cauliflower</td><td>0.95</td><td>0.99</td><td>161</td><td>0.97</td></tr><tr><td>Fresh Eggplant</td><td>0.98</td><td>1.00</td><td>166</td><td>0.99</td></tr><tr><td>Fresh Okra</td><td>0.99</td><td>0.96</td><td>142</td><td>0.97</td></tr><tr><td>Rotten Cauliflower</td><td>0.99</td><td>0.97</td><td>145</td><td>0.98</td></tr><tr><td>Rotten Eggplant</td><td>0.99</td><td>0.99</td><td>149</td><td>0.99</td></tr><tr><td>Rotten Okra</td><td>0.99</td><td>0.99</td><td>128</td><td>0.99</td></tr></tbody></table>

The above figure contains some examples of predicted label. In top of every picture there is header of true label and predicted label. Green color header Represents correct predictions and red color represents incorrect predictions.
<figure><img src="image_9.png" /><figcaption>Fig. 6. Predicted labels by DenseNet201</figcaption></figure>

## 4.2 Confusion Matrix

For achieving a better understanding of our model's performance, we generated a confusion matrix during result analysis. It is basically a visualization tool that shows the prediction rate for each class in supervised or unsupervised learning. It helps to find errors which is represented by the ratio between correct and incorrect prediction. In the Fig. 7 below we can see the graphical representation of confusion matrix for our result evaluation. Here the rows are corresponding to predicted value and column is corresponding to actual class.

## 4.3 Explanations of Curves

Training dataset is a part of the actual sample dataset which is used for fitting a model for performing the prediction task. A test dataset is a part of a sample dataset which was not used to fit the model but is used to assess the model's performance in actual scenarios. It has the same probability distribution as the training dataset.

A part of the sample dataset used to perform an unbiased assessment of a CNN model and its overall fit on the training dataset while turning model hyperparameters is known as Validation Dataset. During our work we separated our dataset into train data and test data in 80 by 20 ratio. There was a total of 13140 images in the dataset (1460 in each class). There was a total of 8410 training images, 2102 validation images and 2628 testing images. During validation and evaluation, we applied K-fold cross validation technique to assess our model's performance. Below we have two separate graphs one
<figure><img src="image_10.png" /><figcaption>Fig. 7. Confusion Matrix for DenseNetV2</figcaption></figure>

contains the information of training loss and validation loss and the other one is for training accuracy and validation accuracy. This information is represented as a curve. Blue curve for training dataset and orange curve for validation dataset. We are measuring the changes of the curve with the perspective of epochs (Fig. 8).

<figure><img src="image_11.png" /><figcaption>Fig. 8. Training loss by Validation loss Curve.</figcaption></figure>

In the above graph we can see a training loss by validation loss curve. Training loss is a matrix which represents how a model fits for the training data. Similarly, validation loss is a matrix which represents how a model fits for the validation data. Training loss and validation loss is generally calculated by adding up the errors for each set. From the above graph we can see that during the beginning of model training on 0 epoch there were big differences between training loss by validation loss points. As the time passed with each epoch the loss started to drop for both training dataset and test dataset. After about 7-8 epochs the curves started to come closer to each other. But still there were some significant differences. But with each epoch it was improving. After about 50 epochs
the curves reached really closer and was almost at a constant difference. This represents a good fit for the model because both training loss and validation loss decreases and stabilizes after 50 epochs. These curves help us decide the end point of model training keeping us free from the concern of over training which saves our valuable time (Fig. 9).

<figure><img src="image_12.png" /><figcaption>Fig. 9. Training Accuracy by Validation Accuracy Curve.</figcaption></figure>

In the above graph we can see a graph containing two curves. One is for training dataset accuracy and the Second is for validation dataset accuracy. From the graph we can see that in the beginning at 0 epoch the accuracy is very low and almost unacceptable. As time was passing with each epoch of model training the accuracy curve for both training dataset and testing dataset was rising. After around 50 epochs both training and validation accuracy increased and took place above almost 90% Range for training dataset and above almost 88% for validation dataset. After that both training accuracy and testing accuracy has reached almost at a stable rate and each curve is reaching a stable position at this stage with each epoch of training there isn't that much of a significant difference present. Which gives the hint to stop our training so that we don't over train the model.

while analyzing both of this curve we found that there was no overfit or underfit issue addressed in the model during training thus providing a great generalization model giving optimal performance. Thus, Densenet201 is best fit for our work which achieved the of accuracy 97.72%. The results of this study show that it is more beneficial to use DenseNet201 compared to other models.

# 5 Conclusion

Ensuring fresh vegetables is a matter of importance to anyone who is concerned with healthy foods. In this study we proposed a modern method for detecting the freshness of vegetables. The proposed model in this study consists of connected convolutional layers in a way in which it gives a superior classification accuracy compared to other models. After observing the custom collected dataset of all three classes and finishing the training session when we performed evaluation of the models, the DenseNet201 tremendously showed the best accuracy of 97.72%. So, our study was quite successful at implementing the system but there were some limitations at the same time. During data collection and
selection, we faced some major complexity in making an ideal version of a custom dataset. Some of the pictures were damaged, some images had light issues, and overall, some of our dataset was not fulfilling basic conditions. So, our future motivation will be to build an interactive application for mobile devices by using this model in the backend part and also improving the quality of the data into applicable conditions. Additionally, implementing the system from scratch again afterwards. Also, we have plans to try out some other transfer learning models which satisfy our requirements to keep up with the evolving time. Detecting freshness of vegetables could be done by human eyesight, our motive is to diminish the dependency on the human eye and give surety to the customers of having fresh vegetables from the market. By applying this method in an actual scenario to predict the freshness of vegetables the customers of the local market will be highly benefited on the other hand it also has a fine scope in reducing the labor cost.

## References

1. Bhargava, A., Bansal, A., Goyal, V.: Machine learning-based detection and sorting of multiple vegetables and fruits. Food Anal. Methods **15**(1), 228-242 (2022)

2. Raikar, M.M., Meena, S.M., Kuchanur, C., Girraddi, S., Benagi, P.: Classification and Grading of Okra-ladies finger using Deep Learning. Procedia computer science **171**, 2380-2389 (2020)

3. Ismail, N., Malik, O.A.: Real-time visual inspection system for grading fruits using computer vision and deep learning techniques. Information Processing in Agriculture **9**(1), 24-37 (2022)

4. Erbaş, N., Çınerar, G., Kılıç, K.: Classification of hazelnuts according to their quality using deep learning algorithms. Czech Journal of Food Sciences **40**(3), 240-248 (2022)

5. Li, Y., Xue, J., Wang, K., Zhang, M., Li, Z.: Surface defect detection of fresh-cut cauliflowers based on convolutional neural network with transfer learning. Foods **11**(18), 2915 (2022)

6. Li, Z., Li, F., Zhu, L., Yue, J.: Vegetable recognition and classification based on improved VGG deep learning network model. Int. J. Computat. Intelli. Sys. **13**(1), 559-564 (2020)

7. Kumar, J.R., Dinesh, K., Priyadharsini, T., Vickram, S.A., Raja, E.G.V., Yogesh, B., Ganesh Babu, C.: A Systematic ML Based Approach for Quality Analysis of Fruits Impudent. In: 2021 Third International Conference on Intelligent Communication Technologies and Virtual Mobile Networks (ICICV), pp. 1-10. IEEE (2021)

8. Zarnaq, M.H., Omid, M., Soltani Firouz, M., Jafarian, M., Bazyar, P.: Freshness and quality assessment of parsley using image processing and artificial intelligence techniques. Agricultural Engineering International: CIGR Journal **24**(2) (2022)

9. Karakaya, D., Ulucan, O., Turkan, M.: A comparative analysis on fruit freshness classification. In: 2019 Innovations in Intelligent Systems and Applications Conference (ASYU), pp. 1-4. IEEE (2019)

10. Sahitya, A., Nadar, I., Sakhiya, P., Mishra, A.: Quality Analysis on Agricultural Produce Using CNN. Available at SSRN 3867633 (2021)

11. Naranjo-Torres, J., Mora, M., Hernández-García, R., Barrientos, R.J., Fredes, C., Valenzuela, A.: A review of convolutional neural network applied to fruit image processing. Appl. Sci. **10**(10), 3443 (2020)

12. Koyama, K., Tanaka, M., Cho, B.-H., Yoshikawa, Y., Koseki, S.: Predicting sensory evaluation of spinach freshness using machine learning model and digital images. PLoS ONE **16**(3), e0248769 (2021)

13. Sun, L., et al.: Research on classification method of eggplant seeds based on machine learning and multispectral imaging classification eggplant seeds. Journal of Sensors 2021 (2021)
14. Ahmed, M.I., Mamun, S.M., Uz Zaman Asif, A.: DCNN-Based Vegetable Image Classification Using Transfer Learning: A Comparative Study. In: 2021 5th International Conference on Computer, Communication and Signal Processing (ICCCSP), pp. 235–243. IEEE (2021)

15. Roy, A.M., Bhaduri, J.: A deep learning enabled multi-class plant disease detection model based on computer vision. *AI 2*(3), 413–428 (2021)