SSLED
SSLED
Article
TinyML-Sensor for Shelf Life Estimation of Fresh Date Fruits
Ramasamy Srinivasagan 1, * , Maged Mohammed 2,3 and Ali Alzahrani 1
Abstract: Fresh dates have a limited shelf life and are susceptible to spoilage, which can lead to
economic losses for producers and suppliers. The problem of accurate shelf life estimation for fresh
dates is essential for various stakeholders involved in the production, supply, and consumption of
dates. Modified atmosphere packaging (MAP) is one of the essential methods that improves the
quality and increases the shelf life of fresh dates by reducing the rate of ripening. Therefore, this study
aims to apply fast and cost-effective non-destructive techniques based on machine learning (ML) to
predict and estimate the shelf life of stored fresh date fruits under different conditions. Predicting
and estimating the shelf life of stored date fruits is essential for scheduling them for consumption at
the right time in the supply chain to benefit from the nutritional advantages of fresh dates. The study
observed the physicochemical attributes of fresh date fruits, including moisture content, total soluble
solids, sugar content, tannin content, pH, and firmness, during storage in a vacuum and MAP at 5 and
24 ◦ C every 7 days to determine the shelf life using a non-destructive approach. TinyML-compatible
regression models were employed to predict the stages of fruit development during the storage
period. The decrease in the shelf life of the fruits begins when they transition from the Khalal stage to
the Rutab stage, and the shelf life ends when they start to spoil or ripen to the Tamr stage. Low-cost
Visible–Near–Infrared (VisNIR) spectral sensors (AS7265x—multi-spectral) were used to capture the
internal physicochemical attributes of the fresh fruit. Regression models were employed for shelf
Citation: Srinivasagan, R.;
life estimation. The findings indicated that vacuum and modified atmosphere packaging with 20%
Mohammed, M.; Alzahrani, A.
CO2 and N balance efficiently increased the shelf life of the stored fresh fruit to 53 days and 44 days,
TinyML-Sensor for Shelf Life
respectively, when maintained at 5 ◦ C. However, the shelf life decreased to 44 and 23 days when the
Estimation of Fresh Date Fruits.
Sensors 2023, 23, 7081. https://
vacuum and modified atmosphere packaging with 20% CO2 and N balance were maintained at room
doi.org/10.3390/s23167081 temperature (24 ◦ C). Edge Impulse supports the training and deployment of models on low-cost
microcontrollers, which can be used to predict real-time estimations of the shelf life of fresh dates
Academic Editors: Jose Manuel
using TinyML sensors.
Molina López and Alexander Wong
Received: 22 June 2023 Keywords: artificial intelligence (AI); TinyML; edge computing; modified atmosphere; prediction
Revised: 2 August 2023 models; Short-Wave Near-Infrared; food supply chain; regression models
Accepted: 8 August 2023
Published: 10 August 2023
1. Introduction
Substantial losses occur within the food product supply chain, especially in fruits and
Copyright: © 2023 by the authors.
Licensee MDPI, Basel, Switzerland.
vegetables, from when they are cultivated until they reach the consumer. A considerable
This article is an open access article
quantity of food is produced but is not consumed due to these losses in the supply chain.
distributed under the terms and This segment of postharvest losses is approximately 25–30% [1]. Roughly 14 percent of the
conditions of the Creative Commons world’s food is lost between harvest and retail, and another 17 percent is wasted in retail
Attribution (CC BY) license (https:// and at the consumption level. The 2030 Agenda for Sustainable Development, specifically
creativecommons.org/licenses/by/ SDG 12, Target 12.3, aims to halve per capita global food waste at the retail and consumer
4.0/). levels and reduce food losses along production and supply chains [1].
The date palm (Phoenix dactylifera L.) is one of the oldest fruit trees that grows widely
in the Middle East and North Africa. Dates are a key source of income and a staple food
for locals in many regions where they are cultivated. They have also played an essential
role in those countries’ socioeconomic and environmental conditions [2]. Consequently,
the demand for date-importing countries like India, Germany, the United Kingdom, the
USA, the Netherlands, Canada, Spain, Italy, Belgium, and Switzerland has increased
significantly. Given the importance of the date palm trade on a local and global scale,
ensuring a continuous supply in the market is vital [3].
A total of 8.46 million tons of date fruit are produced annually worldwide. In 2022,
Saudi Arabia exported 1.54 million tonnes. Date fruit is renowned for its high nutritional
value, and clinical studies have proven that consuming two to three servings of date fruit
per day is beneficial for patients with Type-2 diabetes due to its low Glycemic Index (GI).
Consuming foods with a GI index of less than 50 is recommended. Date varieties such as
Khalas cv., Hilali, Sukkary, Sagai, and Shaqra have a GI of less than 50 and are considered
safe to consume when they reach the mature stage. Fresh dates are suggested as a healthy
and nutritious snack because they have a lower calorie and sugar content compared with
dried dates (Tamr). The GI of fresh fruits is 2–3 times lower than that of mature dates,
and they are also rich in calcium and other nutrients. However, all varieties of fresh dates
can be consumed without restrictions (regarding the number of servings per day that may
increase Glycemic levels) if consumed before reaching the mature stage. It is important
to note that the shelf life of fresh fruits is only 10–12 days before reaching maturity in an
uncontrolled environment [4–6].
Dates fruit is known for its great nutritional value, and it has been proven in a clinical
study that two to three servings of dates fruit per day are beneficial for patients with
diabetes (Type-2) because of their low Glycemic Index (GI). A GI index of less than 50 is
recommended for consumption [4]. The dates varieties, Khalas cv., Hilali, Sukkary, Sagai,
and Shaqra, have a GI of less than 50 and are very safe to consume at the mature stage. Fresh
dates are recommended as a healthy and nutritious snack due to their low calorie and sugar
content compared with dried dates (Tamr). The GI of fresh fruits is 2–3 order times less
than that of mature fruits and is rich in calcium apart from its nutritional content. However,
if consumed before the mature stage, all the fresh date varieties can be consumed without
restrictions (number of servings in a day, which will not increase GL-Glycemic Level).
Nonetheless, fresh date fruits exhibit seasonality and are available from July to Novem-
ber. Consequently, storing these fruits under appropriate conditions is imperative to en-
sure food security. The key objectives of fruit storage encompass preserving fruits for
consumption beyond their regular season, maintaining the quality of the food, slowing
down the decaying process, ensuring a steady supply to the market, and obtaining better
pricing [7–9].
The dates’ freshness and shelf life depend on preserving their physicochemical prop-
erties, including moisture content (MC), total soluble solids (TSS), firmness, pH, and water
activity (AW). However, the conventional methods of analyzing these properties and other
quality indicators in the fruit are time-consuming, labor-intensive, and damaging. Conse-
quently, the need for rapid and non-destructive testing of fruit quality has emerged as a
crucial area of research. Non-destructive techniques, such as spectroscopic and imaging
methods, have proven highly effective in food control. These analytical techniques offer
numerous advantages, including preserving samples, producing swift results, and conduct-
ing checks during production processes. As a result, they have been extensively studied
and utilized in the agro-food sector for a considerable period of time [10].
The most commonly widespread non-destructive techniques in the food industry are
indeed visual/Near-Infrared (NIR) spectroscopy, NIR spectroscopy (NIRs), and image and
multi/hyperspectral analysis [11]. The hyperspectral imaging technique to detect fungal
contamination of edible date fruits using Latent Discriminant Analysis and Quadratic
Discriminant Analysis was investigated in [12]. This work evaluates the possibility of an
Sensors 2023, 23, 7081 3 of 28
objective, fast, and non-destructive method to identify healthy and fungal-infected date
fruits. Four wavelengths (1120, 1300, 1610, and 1650 nm) were used for this study [12].
Visible (Vis; 400–750 nm) and near-infrared red (NIR; 750–2500 nm) region spec-
troscopy have been employed to evaluate the quality and internal attributes of fruits and
vegetables. Focusing specifically on “point” spectroscopy rather than hyperspectral imag-
ing, various non-destructive testing applications have been successfully concluded using
this approach [13]. Several researchers have used spectral bands (Visible, Short-Wave
Near-Infrared (SWNIR), NIR, and IR) to observe the reflectance properties to estimate the
quality or shelf life of various fruits such as Kesar mango [14], grapes [15], persimmon [16],
muskmelon [17], kiwi fruit [18], strawberry [19], Royal Gala [20], and pineapple [21].
The researchers [17,22–29] have put forth a collection of deep learning (DL) and
machine learning (ML) techniques to classify and grade the quality of date fruits. However,
these approaches predominantly rely on cloud services for training and inference, making
them unsuitable for edge computing. In contrast, edge artificial intelligence (AI) primarily
processes data locally, reducing internet data transfer and conserving significant bandwidth.
Moreover, edge computing devices are designed for highly efficient power consumption,
resulting in lower power requirements than cloud data centers. To meet the demands of
edge AI computing, we propose adopting lightweight AI models that can be deployed
on microcontrollers, a new paradigm of Edge AI computing referred to as Tiny Machine
Learning (TinyML). This approach satisfies all the requirements for edge AI computing
and enables efficient processing and classification of date fruit quality without relying on
resource-intensive cloud services [30,31].
Understanding the shelf life of perishable food products is essential for ensuring food
safety and quality and reducing food waste. Fresh dates have a limited shelf life and are
susceptible to spoilage, which can lead to economic losses for producers and suppliers. The
problem of accurate shelf life estimation for fresh dates is essential for various stakeholders
involved in the production, supply, and consumption of dates [32,33]. By addressing this
problem, we can enhance food safety, reduce waste, and improve the overall efficiency and
sustainability of the food industry. By addressing this problem and developing a reliable
methodology for estimating the shelf life of fresh dates, we aim to provide a practical
solution to enhance the quality control processes throughout the supply chain. This can
benefit producers, suppliers, and consumers by reducing food waste, improving product
quality, and ensuring that dates reach consumers at their peak freshness. Accurately
estimating shelf life also has broader implications for the food industry. It can enable better
inventory management, reduce losses, and optimize production and distribution processes.
Additionally, it contributes to overall sustainability efforts by minimizing food waste and
resource utilization.
This study investigates the integration of non-destructive techniques, machine learning
(ML) regression models, and packaging methods to assess and predict the shelf life of fresh
date fruits. While previous studies have investigated shelf life estimation using various
methods, this research focuses explicitly on date fruits. It introduces low-cost VisNIR
spectral sensors for non-destructive assessment of internal quality attributes. Additionally,
ML regression models are developed to predict the stages of fruit development and estimate
shelf life based on observed quality attribute data. Furthermore, the study explores the
effects of different packaging conditions, including modified atmosphere packaging and
vacuum packaging. By combining these elements, the research provides a comprehensive
approach that goes beyond previous efforts in the literature and offers new insights into
accurate shelf life estimation and preservation techniques for fresh date fruits.
The main contribution of the current study lies in applying non-destructive tech-
niques, machine learning (ML) regression models, and modified atmosphere packaging
(MAP) to estimate and predict the shelf life of fresh date fruits. In addition, the study
demonstrates the effectiveness of low-cost VisNIR spectral sensors for the non-destructive
assessment of internal quality attributes, enabling continuous monitoring of fruit quality
without sample destruction. The development of ML regression models enhances the
Sensors 2023, 23, 7081 4 of 28
accuracy of shelf life estimation by utilizing observed quality attribute data. Addition-
ally, the research highlights the benefits of MAP in extending the shelf life of date fruits.
These contributions provide valuable insights into optimizing fruit quality management
and decision-making for optimal freshness and nutritional benefits of fresh date fruits
throughout the supply chain.
TinyML delivers intelligence to low-memory and low-power tiny devices by enabling
machine learning. This research proposes a new lightweight model for fresh date fruit
shelf life estimation based on a low-cost, handy VIS/NIR range spectral sensor and CNN
architecture deployable on any Microcontroller supported by the Edge Impulse Platform.
The proposed model is trained and validated using the Edge Impulse cloud platform using
an in-house dataset.
The main objectives of the current study are the following:
1. Assess the physicochemical attributes of date fruits throughout their storage period in
various modified atmospheres and determine the shelf life for each storage condition.
2. Develop a low-cost, fast inference, and portable shelf life estimator using a TinyML-
assisted 18-channel spectrometer.
3. Develop real-time predictive regression models trained from Edge Impulse utilizing
the reflectance property to predict the shelf life of fresh dates.
4. Validate the results obtained using the developed predictive models against the
observed laboratory results.
The rest of the paper is structured as follows: First, we introduce the Materials and
Methods used in Section 2; Section 3 details the results and discussion. Section 4 concludes
the work and Section 5 suggests future work.
Sensors Wavelengths
AS72653 410 435 460 485 510 535
AS72652 560 585 645 705 900 940
AS72651 610 680 730 760 810 860
The normalized responsivity for the entire spectrum of the Triad AS7265x chipset is
reproduced from the manufacturer’s Datasheet in Figure 1. The normalized responsivity
peaking occurs for various wavelengths and is coded with Alphabets “A, B---K, and L” [37].
The wavelengths used in the AS7265x optical sensors correspond to a particular ab-
sorption peak of particular interest in this fresh date fruit maturity analysis (Khalal to Tamr).
As reported by Giovenzana et al. [10] and Beghi et al. [11], 630 and 690 nanometers are
near the characteristic peak of chlorophyll, 730 nanometers are near the third overtone of
the -OH bond, and lastly, 810 and 860 nanometers are near the combination band of the
-OH groups of sugars. Major attributes determining the shelf life of dates are pH, total
soluble solids (TSS), sugar, MC, water activity (AW), tannin, and firmness. Water activity
and moisture content in the fruit maturity stages were analyzed in different modified
atmospheric conditions [36] and verified that the ratio (MC/aw) is 0.33. The non-invasive
assessment of fruit firmness remains a “holy grail” in postharvest research [13]. According
Sensors 2023, 23, 7081 6 of 28
to Walsh et al. [13], a change in firmness is associated with minor changes in chemical com-
position, such as pectin levels. It is unlikely that NIRS can be used to detect these chemical
changes in intact fruit. Thus, there is no consensus that firmness can be robustly (and
directly) assessed using Vis-SWNIR. Finally, the major attributes considered for predicting
the shelf life and analyzing the freshness of date fruits are pH, TSS, sugar, moisture, and
tannin. Figure 2 shows the methodology flow for the proposed shelf life estimation. The
Figure 1. The
date fruit responsivity
samples of AS7265x—18-channel
at various modified atmospheresoptical sensor [37].
are subjected to both conventional
testing for major attributes (pH, TSS, tannin, moisture content, and sugar) and the AS7265x
Sensors 2023, 23, x FOR PEER REVIEW sensors.
The The
wavelengths
mapped data used in the
are used forAS7265x optical sensors
AI model development correspond
through to a flow.
Edge Impulse 6 ofa
particular
sorption
The finalpeak
modelof is particular
deployed oninterest in this
the Arduino Nanofresh date
sense fruit maturity
microcontroller analysis (Khalal
for inferencing
Tamr). As reported by Giovenzana et al. [10] and Beghi et al. [11], 630 and 690 nanomet
shelf life estimation.
are near the characteristic peak of chlorophyll, 730 nanometers are near the third overto
of the -OH bond, and lastly, 810 and 860 nanometers are near the combination band of t
-OH groups of sugars. Major attributes determining the shelf life of dates are pH, to
soluble solids (TSS), sugar, MC, water activity (AW), tannin, and firmness. Water activ
and moisture content in the fruit maturity stages were analyzed in different modified
mospheric conditions [36] and verified that the ratio (MC/aw) is 0.33. The non-invas
assessment of fruit firmness remains a “holy grail” in postharvest research [13]. Accordi
to Walsh et al. [13], a change in firmness is associated with minor changes in chemi
composition, such as pectin levels. It is unlikely that NIRS can be used to detect the
chemical changes in intact fruit. Thus, there is no consensus that firmness can be robus
(and directly) assessed using Vis-SWNIR. Finally, the major attributes considered for p
dicting the shelf life and analyzing the freshness of date fruits are pH, TSS, sugar, mo
ture, and tannin. Figure 2 shows the methodology flow for the proposed shelf life estim
tion. The date fruit samples at various modified atmospheres are subjected to both co
ventional testing for major attributes (pH, TSS, tannin, moisture content, and sugar) a
the AS7265x sensors. The mapped data are used for AI model development through Ed
Impulse flow. The final model is deployed on the Arduino Nano sense microcontroller
inferencing
Figure 1. Theshelf life estimation.
Figure 1. The responsivity of AS7265x—18-channel optical sensor [37].
responsivity of AS7265x—18-channel optical sensor [37].
The prime activities in each agriculture task and AI models used are listed below in
Table 2.
The shelf life of food products mainly depends on environmental factors in the food
supply chain. Environmental factors play an essential role in the dynamic change in the
quality pattern of food products over time. Hence, the potential of incremental learning
or lifelong machine learning approach may be utilized for building models with high
classification or prediction accuracy. Lifelong learning (LL) involves a reinforcement
learning approach and using the accumulated knowledge over time for future learning and
solving problems [56].
To apply any machine learning approach, datasets, training, and Inference are the
three pillars to improving food sustainability and reducing food waste.
Figure 3 shows the process of bringing food (fresh dates) from farmers to consumers.
Throughout the process, various stakeholders, such as farmers, packaging companies,
logistics providers, and retailers, work together to ensure the dates are safely transported
and delivered to consumers. Similarly, various Internet of Things Sensors, actuators,
and ML models are used to preserve the freshness of date fruit. However, the choice of
Sensors 2023, 23, x FOR PEER REVIEW
Model development and deployment is decided by two approaches: Cloud computing 8 of
and28
Edge computing.
Figure 3.
Figure 3. The
The supply
supply chain
chain of
of fresh
fresh dates.
dates.
2.5. Computing
2.5. Choices for
Computing Choices for ML
ML Model
Model
Cloud computing
Cloud computing isis aa model
model for
for delivering
delivering computing
computing services
services over
over the
the internet.
internet. It
It
allows users
allows users to
to access
access virtual
virtual resources
resources such
such as
as computing
computing power, storage, software,
power, storage, software, and
and
services on
services on demand
demand without
without managing
managing their
their own
own physical
physical hardware.
hardware.
Edge computing is an emerging computing paradigm that refers to a range of net-
works and devices at or near the user. Edge computing is about processing data closer to
where it is being generated, enabling processing at greater speeds and volumes, leading
to greater real-time action-led results.
The following parameters have the same choice of computing as in Table 3: We define
Sensors 2023, 23, 7081 8 of 28
2.10. Structure of Neural Network Used for Spectral Shelf Life Estimator for Dates (SSLED)
In this study, Tiny Machine Learning-based ANNs have been used to predict the
shelf life of fresh date fruit. The reflected light from the AS7265x chipset corresponding to
major physicochemical properties, i.e., date fruits’ pH, TSS, sugar, tannin, and MC, were
Sensors 2023, 23, 7081 10 of 28
The Edge Impulse cloud training platform performs the necessary training and deploys
the model to the Edge device. The Nano 33 BLE then conducts real-time inference to
estimate the shelf life, also called the “Freshness Index”.
The reflectance ratio is calculated using the measurement of incident light and the
reflected light values obtained from the AS7265x—18-channel optical sensor. To measure
incident light, we utilize a calibration process where we expose the sensor to a known
light source. This allows us to establish a baseline value for incident light. The calibration
ensures that we have a consistent reference point for measuring the reflectance of the dates.
Regarding the measurement of reflected light, the AS7265x sensor provides photonic
values rather than direct reflectance values. However, these photonic values are propor-
tional to the light the dates reflect. The sensor detects and quantifies light intensity across
different channels, or spectral bands. By analyzing the photonic values for each channel, we
can determine the reflectance characteristics of the dates and calculate the reflectance ratios.
2.10. Structure of Neural Network Used for Spectral Shelf Life Estimator for Dates (SSLED)
In this study, Tiny Machine Learning-based ANNs have been used to predict the shelf
life of fresh date fruit. The reflected light from the AS7265x chipset corresponding to major
physicochemical properties, i.e., date fruits’ pH, TSS, sugar, tannin, and MC, were taken as
input for the regression NN model.
The input layer acquires data from the AS7265x Triad optical sensor through the I2C
port of the Arduino Nano33 BLE sense microcontroller (Edge Device). The connection
diagram illustrating the spectral sensor to Arduino is shown in Figure 6. The neural
network diagram of the TinyML SSLED prediction model is shown in Figure 7. The hidden
Sensors 2023, 23, x FOR PEER REVIEW layer performs the data transformation and feature extraction, and the output layer delivers
11 of 28
the continuous predicted values and the shelf life/freshness index based on the major
attributes of fresh date fruit.
Figure 7. TinyML-based
Figure7. TinyML-basedspectral
spectralshelf
shelflife
lifeestimator
estimatorfor
fordates
dates(SSLED)
(SSLED)neural
neuralnetwork
networkarchitecture.
architec-
ture.
The dataset was randomly divided into three subsets to train and evaluate the models:
60% forThistraining, 20% for
study utilized testing,
the and 20%Cloud
Edge Impulse for the holdout
platform subset.
[37,38] The training
to develop TinyMLdataset
pre-
was used to determine the weights and build the model, while the testing data helped
diction models and assess their accuracy. Edge Impulse offers a straightforward approach
identify errors and prevent overtraining during the training process. Finally, the holdout
to gathering data using built-in or external sensors in smart devices like mobile and em-
data validated the artificial neural network prediction model.
bedded devices compared with other machine learning development platforms. It boasts
a user-friendly
2.11. interface, assists in data analysis, model design, and testing, and provides
Model Evaluation
a deployable version of the model without requiring extensive coding knowledge, facili-
In this work, we used root mean square error and mean absolute percentage error to
tating rapid prototype development.
evaluate the TinyML prediction model using the following equation:
The neural networks in the multilayer perceptron module were trained using a back-
propagation learning algorithm with s the Adam optimizer. 2
The Adam optimization
method adaptively estimates first- and ∑ni=1 (Oi − Pmoments
second-order i) in stochastic gradient de-
RMSE = (1)
scent, efficiently updating the weights to minimize n the error function.
The dataset was randomly divided into three subsets to train and evaluate the mod-
els: 60% for training, 20% for testing, and×20%
1 for the Oi − Pi subset. The training dataset
× ∑i=1 holdout
n
MAPE = 100 (2)
was used to determine the weights and build the model,
n Oi while the testing data helped
identify
where errors
RMSE is and prevent error,
the relative overtraining
MAPE during the training
is the mean absoluteprocess. Finally,
percentage theOholdout
error, i is the
data validated the artificial neural network prediction model.
measured value, n is the number of the measured values, and Pi is the predicted value of
the target parameter data, i.
used as a guide to label the dataset. In the current study, we focused on the three main
stages of fruit maturity to capture a representative range of date fruit properties spanning
from the Khalal to the Tamr stage. These stages were carefully selected to include dates at
various ripeness levels, allowing us to observe variations in fresh fruit shelf life estimations.
We considered that the shelf life expires after the fresh fruits turn into the second maturity
stage (Rutab) or the fruits are spoiled. To determine the shelf life intervals for the fresh or
Khalal stage, we conducted measurements throughout the entire storage of the dates. The
measurements were taken at regular intervals, weekly for specific periods, depending on
the change in the significant attributes we monitored under each storage temperature and
method. By incorporating measurements throughout the entire ripening stage period, we
aimed to comprehensively understand the attribute variations and their correlations with
the shelf life of fresh dates. This information allowed us to accurately label the values of
significant attributes based on the specific shelf life intervals for the fresh fruits.
Figure8.8.Reflected
Figure Reflected photon
photon count
count versusversus wavelengths
wavelengths for threefor three maturation
maturation stages of fruit.
stages of fruit.
From the laboratory results and reported results from related works [10–13,36,57],
From
we found thethe laboratory
following results
spectral bands and reported
sensitive results from
to the significant related
attributes works
of date [10–13,36
fruits,
we found
which the following
are listed in Table 5. spectral bands
We termed sensitive
the spectral to the
band significant
sensitive to eachattributes
attribute asof date fr
which are listed in Table 5. We termed the spectral
pH-SWNIR, TSS-SWNIR, Sugar-SWNIR, MC-SWNIR, and Tan-SWNIR. band sensitive to each attribute as
SWNIR, TSS-SWNIR, Sugar-SWNIR, MC-SWNIR, and Tan-SWNIR.
Major Attribute
Wavelength in nm
Number Terminology/Name
1 MC-SWNIR 535, 705, 940
2 pH-SWNIR 510, 680, 900
3 Sugar-SWNIR 460, 645, 810
4 Tan-SWNIR 560, 585, 610
5 TSS-SWNIR 410, 560, 730
The spectral measurements were conducted on the same day when the laboratory tests
were conducted on the samples as they progressed through different maturity stages of date
fruit, and the results matched the attributes of date fruits. The results were very convincing,
and they prove the robustness of the Triad Spectrometer used for experimentation. The
three-spectral sensor used is the AS7265x—triad sensor, which has three optical sensors
(As72651, As72652, and AS72653), and hence we sum up all the three reflectance photon
count values from the samples driven from White LED sources, NIR LEDs, and UV.
Having verified the correctness/matching of spectral bands with measurement results
and identified the range of values for all major attributes during the fruit maturity stages,
the dataset was used to train the neural network. At first, we verified the correctness or
matching of the spectral bands. Spectral bands are specific ranges of wavelengths captured
by the sensors used in the study. It is essential to validate that the spectral bands correspond
accurately to the specific attributes or characteristics of the measured date fruit.
Next, we identified the range of values for all major attributes during various stages of
fruit maturity. These attributes include moisture content, sugar level, pH, and other quality
parameters relevant to the shelf life of date fruits. By determining the appropriate range of
values for these attributes at different maturity stages, we established the target variables
for the neural network to predict accurately.
Once the correctness and range of attribute values were confirmed, this dataset became
the input for training the neural network. The neural network learns from this dataset by
iteratively adjusting its internal parameters to minimize the difference between predicted
and actual attribute values. Through this training process, the neural network becomes
better at estimating the shelf life of date fruits based on the captured spectral information.
Even though we chose five attributes to estimate the shelf life of fruit, the moisture
content is primarily responsible for fruit freshness/shelf life. So, we tried to plot the
reflectance ratio of moisture content related to four treated samples maintained at 5 ◦ C and
24 ◦ C, totaling eight samples. Figure 9 shows the reflectance ratio for moisture content for
various treatments. Reflectance ratio is the measure between incident light and reflected
light; it gives the measure of absorption by sample under target. The Khalal stage (fresh
fruit) reflected 80% of the incident light on the first day. When the fruit matures/ripens,
the reflectance ratio deteriorates, indicating the degradation of freshness and, in turn, shelf
life. The vacuum-sealed bags maintained at 5 ◦ C showed the strongest resilience to fruit
maturity/ripening, and it took 53 days to transform from khalal into the Tamr stage. In
other words, we can say that the Glycemic Index of cv. Khalas was under control for 53 days.
Whereas the unsealed sample kept at room temperature (24 ◦ C) has lost its freshness in
10 days. From this graph, we can conclude that the cheapest and most affordable treatment
is a vacuum-sealed bag, which is kept at room temperature and retains shelf life for 24 days.
Figure 10 shows the plot for the cumulative reflectance value from the spectral sensor
of five major attributes, and one can notice the same trend as in Figure 9 since moisture
content is a major reason for fruit maturity and TSS and sugar content are influenced by
moisture content.
in 10 days. From this graph, we can conclude that the cheapest and most affordable treat-
ment is a vacuum-sealed bag, which is kept at room temperature and retains shelf life for
24 days. Figure 10 shows the plot for the cumulative reflectance value from the spectral
sensor of five major attributes, and one can notice the same trend as in Figure 9 since
moisture content is a major reason for fruit maturity and TSS and sugar content are influ- 14 of 28
Sensors 2023, 23, 7081
2000
VSB(5) VSB(24)
MAP2(5) MAP2(24)
1500 MAP1(5) MAP1(24)
Reflectance Value
Unsealed(5) Unsealed(24)
1000
500
0
0 5 10 15 20 25 30 35 40 45 50 55
# Days
Parameters Specifications
Model Type Sequential
Input layer 15 major features + 3 (Vacuum, MAP2, MAP1)
First level Hidden Dense layer 20 neurons
Second level Hidden
10 neurons
Dense Layer
Dropout rate 0.2
Output Layer 1 neuron (Y-Predicted, no activation function)
Learning Rate 0.005
Activation function for all layers ReLu
Batch Size 32
Epochs 100
Optimizer Adam
Loss function MSE (Mean Squared Error)
Number of Training Cycles 100
Unsealed Unsealed
Treatments VSB (5) VSB (24) MAP2(5) MAP2(24) MAP1(5) MAP1(2)
(5) (24)
Training
Dataset 960 706 706 448 416 272 240 120
(80%)
Testing and
Validation 240 178 178 112 104 68 60 30
Dataset (20%)
The Edge Impulse cloud platform is designed to deploy models for real-time appli-
cations on the edge device (Arduino Nano 33 BLE). Based on the hyperparameter used
for the neural network model, the inference time is 1 milli second, and the RAM usage is
1.8k out of 256 KB to store model parameters. Also, the neural network model consumes
only 10.9 KB out of the 1 MB of flash available. These numbers show that this model is
optimized for TinyML implementation and for real-time inferencing.
The performance results, accuracy, and MSE for various confidence threshold settings
for all treated categories of samples after training using all validation set samples are shown
in Table 8.
The range of attribute values (moisture content, total soluble solids, and sugar) was
almost 16 to 60 and was responsible for fruit maturity/ripening. However, the tannin
value range changed between 0.3 and 6.19 and the pH value between 5.30 and 6.9, which
were responsible for fruit maturity/ripening. Even though it looks linear, there is a small
amount of nonlinearity during the lab test and a visible short wave near the infrared
sensor. Hence, we introduced a nonlinear activating function (ReLu) in the neural network
introduced in the tinyML flow. The accuracy plots for all modified atmosphere samples
at different confidence levels were plotted with and without reluctant activations, and we
conclude that ReLu is much needed for the SSLED sensor. To satisfy both the accuracy
and lightweight model of the tiny sensor proposed, which is not a shallow network, we
performed a sensitivity analysis for various hyperparameters (batch size, number of hidden
Sensors 2023, 23, 7081 17 of 28
layers, Adam optimizer, momentum), and from the results, we conclude that a bat with a
size of 32, two hidden layers, and momentum of 0.9 offered better accuracy. The learning
rate and epochs are not very sensitive. The learning rate was chosen as 0.005, and # epochs
was 100 to converge.
Threshold
Packing Type Temperature
Metrics 1 1.25 1.5 1.75 2
MAPE 89.39 96.6 97.87 98.3 98.3
5
RMSE 0.39 0.39 0.39 0.39 0.39
VSB
MAPE 96.65 96.65 99.44 100 100
24
RMSE 0.23 0.23 0.23 0.23 0.23
MAPE 85.8 97.73 100 100 100
5
RMSE 0.39 0.39 0.39 0.39 0.39
MAP2
MAPE 97.13 100 100 100 100
24
RMSE 0.15 0.15 0.15 0.15 0.15
MAPE 83.65 90.38 96.15 96.15 96.15
5
RMSE 0.61 0.61 0.61 0.61 0.61
MAP1
MAPE 76.4 88.2 92.18 94.16 96.12
24
RMSE 0.68 0.68 0.68 0.68 0.68
MAPE 75.2 84.67 92.76 94.1 95.2
5
RMSE 0.69 0.69 0.69 0.69 0.69
Unsealed
MAPE 86.36 93.18 93.18 95.45 100
24
RMSE 0.65 0.65 0.65 0.65 0.65
model is robust. The reason for poor accuracy related to the MAP1(24) and unsealed (5)
categories of samples could be that some of the samples could have been spoiled in that
sealed bag due to bruises/friction during the cleaning process or some other internal at-
tributes.
Figure11.
Figure 11.Sensitivity
Sensitivity analysis
analysis for hyperparameters
for hyperparameters (momentum,
(momentum, batch size,batch size,numbers).
and layer and layer number
Figure 12 compares the model accuracy with and without the activation func
Figure 12A shows that the activation function significantly benefits the model’s accur
The activation function introduces nonlinearity to the neural network, enabling the m
to capture complex patterns and relationships within the data. As a result, the mod
accuracy improves, demonstrating the importance of selecting the appropriate activa
functions for this task. Figure 12B shows the plot for the model accuracy without the
vation function. Without an activation function, the model might struggle to learn c
plex patterns and perform poorly on the given task. This is because linear models can
learn linear relationships between features, limiting the model’s representation po
The results indicate that activation functions are crucial for higher accuracy and b
generalization in the ANN models.
The confidence threshold setting suggested by Edge Impulse based on the num
(A)
of samples in the dataset is 4.3, but we restricted it(B) to lower levels. Increasing confid
threshold
Figure 12.
Figure values
12. Model will
Modelaccuracy always
accuracywith yield
withactivation better
function
activation results.
(A)(A)
function andand Since
model shelf
accuracy
model lifewithout
is reported
without
accuracy activation in the num
activation
of days(B).
function
function with a resolution of 1 day, the ideal confidence threshold should be 1. Out o
(B).
four treated samples maintained at 5 °C and 24 °C, MAP2(24) gives 97.13% accuracy
a MSETheofconfidence
0.15. Onthreshold
the other setting
hand,suggested by Edge Impulse
MAP1(24)-MAP based on
trays sealed the number
with 10% O2, 20%
of samples in the dataset is 4.3, but we restricted it to lower levels. Increasing confidence
and N balance at room temperature yield 76.4% accuracy with a MSE of 0.68. The m
threshold values will always yield better results. Since shelf life is reported in the number
accuracy
of days withplot is plottedoffor
a resolution various
1 day, confidence
the ideal confidence thresholds starting
threshold should be from
1. Outideal
of all case 1 u
four treated samples maintained at 5 C and 24 C, MAP2(24) gives 97.13% accuracy with all the s
2, with an increment of 0.25, as shown
◦ in Figure
◦ 13. This plot shows that even
aples
MSEshow more
of 0.15. On than 93%hand,
the other accuracy for a confidence
MAP1(24)-MAP threshold
trays sealed of 1.5,
with 10% O2 ,and
20%even
CO2 , for an i
threshold setting of 1, most of the sample’s model accuracy is greater than 85 per
and N balance at room temperature yield 76.4% accuracy with a MSE of 0.68. The model
accuracy plot is plotted for various confidence thresholds starting from ideal case 1 up
except for the MAP1(24) and unsealed (5) categories of samples. This proves that
to 2, with an increment of 0.25, as shown in Figure 13. This plot shows that even all the
samples show more than 93% accuracy for a confidence threshold of 1.5, and even for an
ideal threshold setting of 1, most of the sample’s model accuracy is greater than 85 percent,
except for the MAP1(24) and unsealed (5) categories of samples. This proves that the model
is robust. The reason for poor accuracy related to the MAP1(24) and unsealed (5) categories
of samples could be that some of the samples could have been spoiled in that sealed bag
due to bruises/friction during the cleaning process or some other internal attributes.
Figure 13. Model accuracy for treated samples for various confidence thresholds.
Using the feature explorer option of the Edge Impulse platform, the RMS value of
reflectance concerning spectral sensors AS7261 and AS7262 and shelf life RMS are plotted
for better data visualization for all eight samples and are given in Figure 14. From all those
plots, we can see the linear relationships between the reflectance value of the spectral sen-
sor and shelf life, confirming the robustness of the model. In all the following plots, the X-
axis shows the shelf life over several days. From right to left, marked from 0–fresh fruit
(Khalal)/starting day of ripening to last day/fully ripened (Tamr stage), the RMS value of
(A) (B)
Sensors 2023, 23, 7081 19 of 28
Figure 12. Model Accuracy with Activation Function (A) and Model Accuracy without Activation
Function (B).
Figure 13. Model accuracy for treated samples for various confidence thresholds.
Figure 13. Model accuracy for treated samples for various confidence thresholds.
Usingthe
Using thefeature
feature explorer
explorer option
option of the
of the EdgeEdge Impulse
Impulse platform,
platform, the RMS the value
RMS of value of
reflectanceconcerning
reflectance concerning spectral
spectral sensor
sensors AS7261
AS7261 and and AS7262
AS7262 andlife
and shelf shelf
RMS lifeareRMS is plotted
plotted
for
for better
betterdata
datavisualization
visualization forfor
allall
eight samplesand
8 samples and are
are given
given in Figure
Figure 14.14. From
Fromall all those
those plots, we can see the linear relationships between the reflectance value
plots we can see the linear relationships between the reflectance value of the spectral sen- of the spectral
sensor
sor and and shelflife,
shelf life,confirming
confirming thetherobustness
robustness of the model. In
of model. In all
allthe
thefollowing
following plots, theX- axis
plots
X-axis shows the shelf life over several days. From right to left, marked from 0–fresh fruit
shows the shelf life in several days. From Right to left marked from 0 – fresh fruit ( Khalal)/
(Khalal)/starting day of ripening to last day/fully ripened (Tamr stage), the RMS value of
starting day of ripening to last day/ fully ripened ( Tamr stage ), The RMS value of reflec-
reflectance (a.u) wrt AS7262 is marked as Rb RMS. Similarly, the RMS value of reflectance
tance (a.u) wrt AS7262 is marked as Rb RMS. Similarly, RMS value of reflectance wrt
for AS7261 is marked as Refl RMS. The colors (blobs) given for the samples in Figure 14 were
AS7261 is marked
(VIBGYOR) as Refl
and reported byRMS. TheImpulse
the Edge colors (blob)
studiogiven for the
application forsamples in Figure 14 were
better visualization.
(VIBGYOR)
Violet and fruit
for ripened reported
(moreby Edge
days) impulse
to Red studio application
for Khalal/fresh date fruitfor(0thbetter
day).visualization. Vi-
olet Figure
for ripened
15 shows fruit (more days)
a snapshot toclassification
of live Red for Khalal /fresh
results fromdateEdgefruit ( 0th day).
Impulse studio. The
sample taken for the demonstration is from unsealed trays kept at 24 C. The sample was◦
labeled as having a shelf life of 6, predicted as 5.16, and is pretty accurate with a confidence
of 0.99. The light blue color blob (bigger size) shows the live sample classification in the
screenshot. The shelf life of samples kept in an unsealed tray at room temperature ranges
from 1 to 10 days. Here, a shelf life of 0 days means the fruit matures fully (Tamr), whereas a
shelf life of 10 days means it will take 10 days to reach the Tamr stage from the Khalal stage.
Sensors Sensors 2023,
2023, 23, 708123, x FOR PEER REVIEW 20 of
2028
of 28
(A) (B)
(C) (D)
(E) (F)
(G) (H)
Figure 14. Data visualization plots covering four treated samples kept at cold storage room (5 ◦ C)
and at normal temperature (room temperature 24 ◦ C). (A) unsealed at 5 ◦ C, (B) unsealed at 24 ◦ C,
(C) MAP1 at 5 ◦ C, (D) MAP1 at 24 ◦ C, (E) MAP2 at 5 ◦ C, (F) MAP2 at 24 ◦ C, (G) VSB at 5 ◦ C, and
(H) VSB at 24 ◦ C.
The sample taken for the demonstration is from unsealed trays kept at 24 °C. The sample
was labeled as having a shelf life of 6, predicted as 5.16, and is pretty accurate with a
confidence of 0.99. The light blue color blob (bigger size) shows the live sample classifica-
tion in the screenshot. The shelf life of samples kept in an unsealed tray at room tempera-
Sensors 2023, 23, 7081 ture ranges from 1 to 10 days. Here, a shelf life of 0 days means the fruit matures fully
21 of 28
(Tamr), whereas a shelf life of 10 days means it will take 10 days to reach the Tamr stage
from the Khalal stage.
Figure15.
Figure 15.Live
Liveclassification
classificationresults
results for
for sample from
from unsealed
unsealedtray
traykept
keptatatroom
roomtemperature.
temperature.
Figure16
Figure 16shows
showsthe
the eight
eight subplots
subplots of
of model
modeltest
testresults—data
results—datavisualization covering
visualization covering
◦ C) and a normal temperature (24 ◦ C).
fourtreated
four treatedsamples
sampleskept
kept at
at aa cold
cold storage
storage room
room(5 (5°C) and a normal temperature (24 °C).
Thegreen
The greenblobs
blobsare
arecorrectly
correctlypredicted,
predicted, and
and the red ones
ones are
are wrongly
wronglypredicted.
predicted.
Sensors
Sensors 2023,2023, 23, x FOR PEER REVIEW
23, 7081 22 of2228of 28
(A) (B)
(C) (D)
(E) (F)
(G) (H)
Figure 16. Model test results for all treated samples when confidence threshold was set to 1.5: (green
blobs are correct; red ones are incorrect prediction). (A) unsealed at 5 ◦ C, (B) unsealed at 24 ◦ C, (C)
MAP1 at 5 ◦ C, (D) MAP1 at 24 ◦ C, (E) MAP2 at 5 ◦ C, (F) MAP2 at 24 ◦ C, (G) VSB at 5 ◦ C, and (H)
VSB at 24 ◦ C.
Sensors 2023, 23, x FOR PEER REVIEW To have better insight in reading and interpreting the model test result performance, 23 of 28
the results for all samples in unsealed (5 °C) and unsealed (24 °C) (the top two of the
subplots of Figure 15) are plotted for shelf life in the number of days versus all the samples
in that16.
Figure category andresults
Model test shown forin
allFigures 17 and 18,
treated samples respectively.
when confidence threshold was set to 1.5: (green
blobs are correct; red ones are incorrect prediction). (A) unsealed at 5 °C, (B) unsealed at 24 °C, (C)
Sensors 2023, 23, 7081 23 of 28
MAP1 at 5 °C, (D) MAP1 at 24 °C, (E) MAP2 at 5 °C, (F) MAP2 at 24 °C, (G) VSB at 5 °C, and (H)
VSB at 24 °C. Test Predicted
16
To
To havebetter
have betterinsight
insight in
in reading
reading and
and interpreting
interpreting the
the model
model test
test result
result performance,
performance,
the results
the results
14 forfor all
all samples
samples in in unsealed
unsealed (5
(5 ◦°C)
C) andand unsealed
unsealed (24
(24 ◦°C) (the top
C) (the top two
two of
of the
the
subplots
subplots 12 of
of Figure
Figure 15)
15) are
are plotted
plotted for
for shelf
shelf life
life in
in the
the number
number of
of days
days versus
versus all
all the
the samples
samples
in that
that category
category and
and shown
shownin inFigures
Figures1717and
and18, 18,respectively.
respectively.
Shelflife in days
in
10
8
Test Predicted
6
16
4
14
2
12
0
Shelflife in days
10 1 6 11 16 21 26 31 36 41 46 51 56
Test_Samples
8
6
Figure 17. Model test results for unsealed samples at cold storage (5 °C).
4
Figure
2 17 shows the model test results of the unsealed sample kept at 5 °C. The ob-
servation is that samples 1 up to 4 are labeled (the test sample) as having a shelf life of 0,
0
but the model
1
predicted
6 11
1.78
16
days
21
with26an error
31
of36
more41than 46 100 percent.
51
Similarly, sam-
56
ple numbers 36 to 39 are supposed to predict that
Test_Samplesa shelf life of 9 has an error of more than
100 percent. For samples 5–9 and 57–59, the error is less than 100 percent. The remaining
other samples are predicted correctly, and these results are obtained with a confidence
Figure 17. Model
threshold
Figure 17. Model test results
of 1.5.test resultsfor
forunsealed
unsealedsamples
samplesat
atcold
coldstorage
storage(5(5◦°C).
C).
Figure 17 shows the model test results of the unsealed sample kept at 5 °C. The ob-
12
servation is that samples 1 up to 4 are labeled (the test sample) as having a shelf life of 0,
but the model predicted 1.78 days with an error of more thanTest 100 percent.
Predicted
Similarly, sam-
10
ple numbers 36 to 39 are supposed to predict that a shelf life of 9 has an error of more than
100 percent. For samples 5–9 and 57–59, the error is less than 100 percent. The remaining
Shelf life in days
8
other samples are predicted correctly, and these results are obtained with a confidence
threshold of 1.5.
6
12
4
Test Predicted
10
2
Shelf life in days
8
0
1 6 11 16 21 26 31 36 41
6
Test_Samples
4
Figure 18. Model test results for unsealed samples at room temperature.
2
Figure 17 shows the model test results of the unsealed sample kept at 5 ◦ C. The
observation is that samples 1 up to 4 are labeled (the test sample) as having a shelf life of 0,
0
but the model predicted 1.78 days with an error of more than 100 percent. Similarly, sample
numbers 361 to 39 are
6 11
supposed 16
to predict 21
that 26
a shelf life of319 has an
36 41
error of more than 100
percent. For samples 5–9 and 57–59, theTest_Samples
error is less than 100 percent. The remaining other
samples are predicted correctly, and these results are obtained with a confidence threshold
of 1.5.
Figure 18 shows the model test results of the unsealed samples kept at 24 ◦ C. The
observation is that samples 1 up to 4 are labeled as having a shelf life of 0, but the model
predicted 1.78 days, which has an error of more than 100 percent. The remaining samples
are predicted correctly, and these results are obtained with a confidence threshold of 1.5.
Figure 18. Model test results for unsealed samples at room temperature.
Figure 18 shows the model test results of the unsealed samples kept at 24 °C. The
Sensors 2023, 23, 7081 observation is that samples 1 up to 4 are labeled as having a shelf life of 0, but the 24 model
of 28
predicted 1.78 days, which has an error of more than 100 percent. The remaining samples
are predicted correctly, and these results are obtained with a confidence threshold of 1.5.
From the
From thesubplots
subplots of ofFigure
Figure16,
16,we wevalidate
validatethatthatthethemodel
modelperforms
performsadequately
adequately for for
mostof
most ofthe
thesample
samplein infour
fourcategories:
categories: VSB,
VSB, MAP2,
MAP2, MAP1,
MAP1, andandunsealed.
unsealed. There
There were
were fewfew
wrongpredictions
wrong predictions highlighted
highlighted in in Figures
Figures 17 17 and
and 18;
18;other
other than
thanthat,
that, most
most samples
samples were
were
predictedcorrectly.
predicted correctly.We Webelieve
believethethe wrong
wrong prediction
prediction is due
is due to to some
some other
other internal
internal attrib-
attribute
ute
of of date
date fruit.fruit.
The plot
The plot showing
showing the theaccuracy
accuracyand andloss
losscurve
curve forfor
both training
both andand
training validation for 100
validation for
epochs
100 during
epochs the the
during training
trainingcycle is shown
cycle is shownin Figure
in Figure 19. After 90 epochs,
19. After the model
90 epochs, the modelcon-
verges very
converges well
very and
well is is
and thethecorrect
correctfit.
fit.This
Thisplot
plotisisgenerated
generatedwithwith aa seed
seed of 31 (the
(the initial
initial
weights and
weights and bias
bias during
during training
training are
are random
random andand vary
vary with
with different
different seeds)
seeds) during
during the the
trainingstage
training stagetotoreport
reportthethemodel
modelaccuracy
accuracyconsistently.
consistently.
0.8
Acc/Loss
0.6
0.4
0.2
0
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100
Epoch
Figure19.
Figure 19.Training
Trainingand
andvalidation
validationaccuracy
accuracyand
andloss
losscurves
curvesfor
forVSB
VSBsamples
samplesatatroom
roomtemperature.
temperature.
Wevalidated
We validatedour ourmodel
modelwith withlab
labresults
resultsfrom
fromthetheDPRC
DPRClaboratory
laboratorywhenwhenwe wedid
didlive
live
testing. To the best of our knowledge, we did not find any papers working on shelf life
testing. To the best of our knowledge, we did not find any papers working on shelf life
predictionusing
prediction usingthetheTinyML
TinyML regression
regression model
model for shelf
for shelf life prediction
life prediction of dates.
of fresh fresh dates.
How-
However,
ever, severalseveral
relatedrelated
studies studies exist
exist for for Galas,
Royal Royal Galas, strawberries,
strawberries, mangos, mangos,
bananas, bananas,
musk
musk melons, and grapes using Computer Vision models and other classification models.
melons, and grapes using Computer Vision models and other classification models. Most
of the work has reported around 95% accuracy. Our model results
Most of the work has reported around 95% accuracy. Our model results are also good, are also good, ranging
from 95%from
ranging to 100%
95%for different
to 100% confidence
for different thresholdthreshold
confidence settings. The selected
settings. Themicrocontroller,
selected micro-
Nano 33 BLE, was tested on a Cr2032 Lithium ion 3v3 battery
controller, Nano 33 BLE, was tested on a Cr2032 Lithium ion 3v3 battery (225 (225 mAH) and mAH)
consumes and
much less inferencing power. The TinyML kit will consume only
consumes much less inferencing power. The TinyML kit will consume only 1–2 mA; 1–2 mA; however, during
how-
the sampling
ever, during thetime, the spectral
sampling time,sensor LED is sensor
the spectral taking LED
12.5 mA. The battery
is taking 12.5 mA. will
Thelast for a
battery
week
will last for a week without recharging, assuming 10 min of sampling/inferencing perdata
without recharging, assuming 10 min of sampling/inferencing per day. The day.
acquisition time is justtime
The data acquisition 3 s with
is justcalibration, the inference
3 s with calibration, the time is lesstime
inference thanis100
lessms,
thanand
100with
ms,
a 225 mAH battery, it will last for a minimum of a week.
and with a 225 mAH battery, it will last for a minimum of a week.
The challenge we faced in the TinyML training phase using the Edge Impulse platform
The challenge we faced in the TinyML training phase using the Edge Impulse plat-
was only uploading data for training models. Edge Impulse supports only the onboard
form was only uploading data for training models. Edge Impulse supports only the
sensors of selected microcontrollers/edge devices to acquire the data directly (live upload).
onboard sensors of selected microcontrollers/edge devices to acquire the data directly
The AS7265X sensor we used was an off-the-shelf sensor, and hence we had to acquire
(live upload). The AS7265X sensor we used was an off-the-shelf sensor, and hence we had
the data and store it on an SD card, then convert the reflectance value corresponding to
to acquire the data and store it on an SD card, then convert the reflectance value corre-
all the attributes for shelf life prediction as a comma separated value (csv), which took
sponding to all the attributes for shelf life prediction as a comma separated value (csv),
a considerable amount of time in weekly sampling and testing. However, the model
deployment was easy due to the Edge Impulse platform.
4. Conclusions
We conclude that simple vacuum packaging and low-cost shelf prediction—lightweight
models with a low-cost spectral sensor (40 USD)—support edge computing, a key enabler
Sensors 2023, 23, 7081 25 of 28
to predict shelf life, thus ensuring sustainable nutrient food availability throughout the year.
Consumers in food and agro-industry verticals such as quality management, production,
storage, logistics, supply chain, and processing can choose the type of treatment and ML
models (cloud/edge). A low-cost handheld spectral sensor integrated with an Arduino
Nano 33 BLE microcontroller able to predict the shelf life of fresh fruit at all stages of the
fruit ripening process has been experimentally verified for its robustness by validating
against lab results. The accuracy of the lightweight regression model for all the treated
samples was above 93% for a confidence threshold of 1.5. The reported performance shows
that this TinyML sensor can be used as a handheld device for real-time prediction of the
shelf life and freshness of the fruit.
5. Future Works
Ensemble Machine learning techniques that accommodate both vision and spectral-
based sensors for shelf life estimation, which can cover all perishable food items in the
supply chain and benefit a broad category of customers in the supply chain, may be
attempted.
Author Contributions: Conceptualization, M.M., R.S., and A.A.; methodology, M.M. and R.S.;
software, R.S. and M.M.; validation, M.M., R.S., and A.A.; formal analysis, M.M.; investigation,
M.M. and R.S.; resources, R.S., M.M., and A.A.; data curation, M.M. and R.S.; writing—original draft
preparation, M.M., R.S., and A.A.; writing—review and editing, M.M., R.S., and A.A.; visualization,
M.M.; project administration, R.S., M.M. and A.A.; funding acquisition, R.S., M.M., and A.A. All
authors have read and agreed to the published version of the manuscript.
Funding: This work was supported by the Deputyship for Research and Innovation, Ministry of
Education in Saudi Arabia [Grant No. INST031].
Institutional Review Board Statement: Not applicable.
Informed Consent Statement: Not applicable.
Data Availability Statement: The data are available upon request from the corresponding author.
Acknowledgments: The authors thank the Deputyship for Research and Innovation, Ministry of
Education in Saudi Arabia, for funding this research work (Project number INST031).
Conflicts of Interest: The authors declare no conflict of interest.
Nomenclature
A. U. Arbitrary Unit
AI Artificial Intelligence
ANN Artificial Neural Network
CNN Convolutional Neural Network
DT Decision Trees
ET Ensemble Technique
GI Glycemic Index
IoT Internet of Things
IR Infrared Red
Inference, Training, Scalability, Bandwidth, Latency, Economics,
ITSBLERP
Reliability, and Privacy Characteristics
K-MC K-Means Clustering
K-NN K-Nearest Neighbor
LDA Linear Discriminant Analysis
LI Lifelong Learning (Ll)
LR Linear Regression
LSTM Long Short-Term Memory
MAE Mean Absolute Error
MAP Modified Atmosphere Packaging
Sensors 2023, 23, 7081 26 of 28
MC Moisture Content
ML Machine Learning
NB Naïve Bayes
NIR Near-Infrared Red
PCA Principal Component Analysis
MAPE Mean absolute percentage error
RF Random Forest
RLM Reinforcement Learning Models
RMSE Root Mean Square Error
RNN Recurrent Neural Network
SC Sugar Content
SSLED Spectral Shelf Life Estimator For Dates
SVM Support Vector Machines
SWNIR Short-Wave Near-Infrared
TC Tannin Content
TFLM Tensor Flow Lite for Microcontrollers
TinyML Tiny Machin Learning
TSS Total Soluble Solids
wa Water Activity
Xgboost Extreme Gradient Boosting
References
1. United Nation Environment Programme Food Waste Index Report 2021. Available online: https://wedocs.unep.org/bitstream/
handle/20.500.11822/35280/FoodWaste.pdf (accessed on 1 April 2023).
2. Chao, C.C.T.; Krueger, R.R. The Date Palm (Phoenix dactylifera L.): Overview of Biology, Uses, and Cultivation. HortScience 2007,
42, 1077–1082. [CrossRef]
3. Dhehibi, B.; Ben Salah, M.; Frija, A. Date Palm Value Chain Analysis and Marketing Opportunities for the Gulf Cooperation
Council (GCC) Countries. In Agricultural Economics—Current Issues; Kulshreshtha, S., Ed.; IntechOpen: Rijeka, Croatia, 2019; pp.
11–17.
4. Mirghani, H.O. Dates Fruits Effects on Blood Glucose among Patients with Diabetes Mellitus: A Review and Meta-Analysis. Pak.
J. Med. Sci. 2021, 37, 1230–1236. [CrossRef] [PubMed]
5. Alkaabi, J.M.; Al-Dabbagh, B.; Ahmad, S.; Saadi, H.F.; Gariballa, S.; Ghazali, M. Al Glycemic Indices of Five Varieties of Dates in
Healthy and Diabetic Subjects. Nutr. J. 2011, 10, 59. [CrossRef] [PubMed]
6. AlGeffari, M.A.; Almogbel, E.S.; Alhomaidan, H.T.; ElMergawi, R.; Barrimah, I.A. Glycemic Indices, Glycemic Load and Glycemic
Response for Seventeen Varieties of Dates Grown in Saudi Arabia. Ann. Saudi Med. 2016, 36, 397–403. [CrossRef]
7. Gallagher, M.J.S.J.S.; Mahajan, P.V.V. The Stability and Shelf Life of Fruit and Vegetables. In Food and Beverage Stability and Shelf
Life; Kilcast, D., Subramaniam, P., Eds.; Woodhead Publishing: Cambridge, UK, 2011; pp. 641–656. ISBN 9781845697013.
8. Thompson, A.K.A.K. Fruit and Vegetable Storage. In Food, Health and Nutrition; SpringerBriefs in Food, Health, and Nutrition;
Springer International Publishing: Cham, Switzerland, 2016; pp. 1–126. ISBN 978-3-319-23590-5.
9. Suriati, L.; Utama, I.M.S.; Harjosuwono, B.A.; Wayan Gunam, I.B. Physicochemical Characteristics of Fresh-Cut Tropical Fruit
during Storage. Int. J. Adv. Sci. Eng. Inf. Technol. 2020, 10, 1731–1736. [CrossRef]
10. Giovenzana, V.; Tugnolo, A.; Casson, A.; Guidetti, R.; Beghi, R. Application of Visible-near Infrared Spectroscopy to Evaluate the
Quality of Button Mushrooms. J. Near Infrared Spectrosc. 2019, 27, 38–45. [CrossRef]
11. Beghi, R.; Giovenzana, V.; Brancadoro, L.; Guidetti, R. Rapid Evaluation of Grape Phytosanitary Status Directly at the Check
Point Station Entering the Winery by Using Visible/near Infrared Spectroscopy. J. Food Eng. 2017, 204, 46–54. [CrossRef]
12. Teena, M.A.; Manickavasagan, A.; Ravikanth, L.; Jayas, D.S. Near Infrared (NIR) Hyperspectral Imaging to Classify Fungal
Infected Date Fruits. J. Stored Prod. Res. 2014, 59, 306–313. [CrossRef]
13. Walsh, K.B.; Blasco, J.; Zude-Sasse, M.; Sun, X. Visible-NIR ‘Point’ Spectroscopy in Postharvest Fruit and Vegetable Assessment:
The Science behind Three Decades of Commercial Use. Postharvest Biol. Technol. 2020, 168, 111246. [CrossRef]
14. Dutta, J.; Deshpande, P.; Rai, B. AI-Based Soft-Sensor for Shelf Life Prediction of ‘Kesar’ Mango. SN Appl. Sci. 2021, 3, 657.
[CrossRef]
15. Pampuri, A.; Tugnolo, A.; Giovenzana, V.; Casson, A.; Pozzoli, C.; Brancadoro, L.; Guidetti, R.; Beghi, R. Application of a
Cost-Effective Visible/Near Infrared Optical Prototype for the Measurement of Qualitative Parameters of Chardonnay Grapes.
Appl. Sci. 2022, 12, 4853. [CrossRef]
16. Suzuki, M.; Masuda, K.; Asakuma, H.; Takeshita, K.; Baba, K.; Kubo, Y.; Ushijima, K.; Uchida, S.; Akagi, T. Deep Learning Predicts
Rapid Over-Softening and Shelf Life in Persimmon Fruits. Hortic. J. 2022, 91, 408–415. [CrossRef]
17. Albert-Weiss, D.; Osman, A. Interactive Deep Learning for Shelf Life Prediction of Muskmelons Based on an Active Learning
Approach. Sensors 2022, 22, 414. [CrossRef] [PubMed]
Sensors 2023, 23, 7081 27 of 28
18. Shao, Y.Y.; Wang, Y.X.; Xuan, G.T.; Gao, Z.M.; Liu, Y.; Han, X.; Hu, Z.C. Hyperspectral Imaging Technique for Estimating the
Shelf-Life of Kiwifruits. Guang Pu Xue Yu Guang Pu Fen Xi/Spectrosc. Spectr. Anal. 2020, 40, 1940–1946.
19. Basak, J.K.; Madhavi, B.G.K.; Paudel, B.; Kim, N.E.; Kim, H.T. Prediction of Total Soluble Solids and PH of Strawberry Fruits
Using RGB, HSV and HSL Colour Spaces and Machine Learning Models. Foods 2022, 11, 2086. [CrossRef]
20. Cao, M.; Wang, D.; Qiu, L.; Ren, X.; Ma, H. Shelf Life Prediction of ‘Royal Gala’ Apples Based on Quality Attributes and Storage
Temperature. Hortic. Sci. Technol. 2021, 39, 343–355. [CrossRef]
21. Mohd Ali, M.; Hashim, N.; Abd Aziz, S.; Lasekan, O. Shelf Life Prediction and Kinetics of Quality Changes in Pineapple (Ananas
Comosus) Varieties at Different Storage Temperatures. Horticulturae 2022, 8, 992. [CrossRef]
22. Albarrak, K.; Gulzar, Y.; Hamid, Y.; Mehmood, A.; Soomro, A.B. A Deep Learning-Based Model for Date Fruit Classification.
Sustainability 2022, 14, 6339. [CrossRef]
23. Bhole, V.; Kumar, A. A Transfer Learning-Based Approach to Predict the Shelf Life of Fruit. Intel. Artif. 2021, 24, 102–120.
[CrossRef]
24. Altaheri, H.; Alsulaiman, M.; Muhammad, G.; Amin, S.U.; Bencherif, M.; Mekhtiche, M. Date Fruit Dataset for Intelligent
Harvesting. Data Brief 2019, 26, 104514. [CrossRef] [PubMed]
25. Faisal, M.; Albogamy, F.; Elgibreen, H.; Algabri, M.; Alqershi, F.A. Deep Learning and Computer Vision for Estimating Date Fruits
Type, Maturity Level, and Weight. IEEE Access 2020, 8, 206770–206782. [CrossRef]
26. Faisal, M.; Alsulaiman, M.; Arafah, M.; Mekhtiche, M.A. IHDS: Intelligent Harvesting Decision System for Date Fruit Based on
Maturity Stage Using Deep Learning and Computer Vision. IEEE Access 2020, 8, 167985–167997. [CrossRef]
27. Nasiri, A.; Taheri-Garavand, A.; Zhang, Y.-D. Image-Based Deep Learning Automated Sorting of Date Fruit. Postharvest Biol.
Technol. 2019, 153, 133–141. [CrossRef]
28. Iorliam, I.B.; Ikyo, B.A.; Iorliam, A.; Okube, E.O.; Kwaghtyo, K.D.; Shehu, Y.I. Application of Machine Learning Techniques for
Okra Shelf Life Prediction. J. Data Anal. Inf. Process. 2021, 9, 136–150. [CrossRef]
29. Muhammad, G. Date Fruits Classification Using Texture Descriptors and Shape-Size Features. Eng. Appl. Artif. Intell. 2015, 37,
361–367. [CrossRef]
30. Hymel, S.; Banbury, C.; Situnayake, D.; Elium, A.; Ward, C.; Kelcey, M.; Baaijens, M.; Majchrzycki, M.; Plunkett, J.; Tischler, D.;
et al. Edge Impulse: An MLOps Platform for Tiny Machine Learning. arXiv 2022, arXiv:2212.03332. [CrossRef]
31. Janapa Reddi, V.; Plancher, B.; Kennedy, S.; Moroney, L.; Warden, P.; Suzuki, L.; Agarwal, A.; Banbury, C.; Banzi, M.; Bennett, M.;
et al. Widening Access to Applied Machine Learning with TinyML. Harvard Data Sci. Rev. 2022, 4, 1–38. [CrossRef]
32. Yahia, E.M.; Lobo, M.G.; Kader, A.A. Harvesting and Postharvest Technology of Dates. In Dates: Postharvest Science, Processing
Technology and Health Benefits; John Wiley & Sons Ltd.: Chichester, UK, 2013; pp. 105–135. ISBN 9781118292419.
33. Mohammed, M.; Sallam, A.; Alqahtani, N.; Munir, M. The Combined Effects of Precision-Controlled Temperature and Relative
Humidity on Artificial Ripening and Quality of Date Fruit. Foods 2021, 10, 2636. [CrossRef]
34. Al-Mentafji, H.N. AOAC Official Methods of Analysis of AOAC, 18th ed.; AOAC International: Washington, DC, USA, 2005.
35. Mohammed, M.; El-Shafie, H.; Munir, M. Development and Validation of Innovative Machine Learning Models for Predicting
Date Palm Mite Infestation on Fruits. Agronomy 2023, 13, 494. [CrossRef]
36. Mohammed, M.; Munir, M.; Aljabr, A. Prediction of Date Fruit Quality Attributes during Cold Storage Based on Their Electrical
Properties Using Artificial Neural Networks Models. Foods 2022, 11, 1666. [CrossRef]
37. AMS-OSRAM Datasheet. Available online: https://ams-osram.com/support/technical-support-form (accessed on 18 June 2023).
38. Meshram, V.; Patil, K.; Meshram, V.; Hanchate, D.; Ramkteke, S.D. Machine Learning in Agriculture Domain: A State-of-Art
Survey. Artif. Intell. Life Sci. 2021, 1, 100010. [CrossRef]
39. Mohammed, M.; Hamdoun, H.; Sagheer, A. Toward Sustainable Farming: Implementing Artificial Intelligence to Predict
Optimum Water and Energy Requirements for Sensor-Based Micro Irrigation Systems Powered by Solar PV. Agronomy 2023, 13,
1081. [CrossRef]
40. Kumar, N.; Dahiya, A.K.; Kumar, K.; Tanwar, S. Application of IoT in Agriculture. In Proceedings of the 2021 9th International
Conference on Reliability, Infocom Technologies and Optimization (Trends and Future Directions) (ICRITO), Noida, India, 3–4
September 2021; pp. 1–4.
41. Ejaz, N.; Elhag, M.; Bahrawi, J.; Zhang, L.; Gabriel, H.F.; Rahman, K.U. Soil Erosion Modelling and Accumulation Using RUSLE
and Remote Sensing Techniques: Case Study Wadi Baysh, Kingdom of Saudi Arabia. Sustainability 2023, 15, 3218. [CrossRef]
42. Lavanya, G.; Rani, C.; Ganeshkumar, P. An Automated Low Cost IoT Based Fertilizer Intimation System for Smart Agriculture.
Sustain. Comput. Inform. Syst. 2020, 28, 100300. [CrossRef]
43. Garcia Furuya, D.E.; Ma, L.; Faita Pinheiro, M.M.; Georges Gomes, F.D.; Gonçalvez, W.N.; Junior, J.M.; de Castro Rodrigues, D.;
Blassioli-Moraes, M.C.; Furtado Michereff, M.F.; Borges, M.; et al. Prediction of Insect-Herbivory-Damage and Insect-Type Attack
in Maize Plants Using Hyperspectral Data. Int. J. Appl. Earth Obs. Geoinf. 2021, 105, 102608. [CrossRef]
44. Yu, X.; Wang, Y.; Wu, L.; Chen, G.; Wang, L.; Qin, H. Comparison of Support Vector Regression and Extreme Gradient Boosting
for Decomposition-Based Data-Driven 10-Day Streamflow Forecasting. J. Hydrol. 2020, 582, 124293. [CrossRef]
45. Ramazi, P.; Kunegel-Lion, M.; Greiner, R.; Lewis, M.A. Predicting Insect Outbreaks Using Machine Learning: A Mountain Pine
Beetle Case Study. Ecol. Evol. 2021, 11, 13014–13028. [CrossRef]
46. Mohammed, M.; Munir, M.; Ghazzawy, H.S. Design and Evaluation of a Smart Ex Vitro Acclimatization System for Tissue Culture
Plantlets. Agronomy 2022, 13, 78. [CrossRef]
Sensors 2023, 23, 7081 28 of 28
47. Mohammed, M.; Alqahtani, N.K. Design and Validation of Automated Sensor-Based Artificial Ripening System Combined with
Ultrasound Pretreatment for Date Fruits. Agronomy 2022, 12, 2805. [CrossRef]
48. Guillén, M.A.; Llanes, A.; Imbernón, B.; Martínez-España, R.; Bueno-Crespo, A.; Cano, J.C.; Cecilia, J.M. Performance Evaluation
of Edge-Computing Platforms for the Prediction of Low Temperatures in Agriculture Using Deep Learning. J. Supercomput. 2021,
77, 818–840. [CrossRef]
49. Bian, H.X.; Tu, P.; Hua-li, X.; Shi, P. Quality Predictions for Bruised Apples Based on Dielectric Properties. J. Food Process. Preserv.
2019, 43, e14006. [CrossRef]
50. El-Shafie, H.; Mohammed, M.; Alqahtani, N. A Preliminary Study on Flight Characteristics of the Longhorn Date Palm Stem
Borer Jebusaea Hammerschmidtii (Reiche 1878) (Coleoptera: Cerambycidae) Using a Computerized Flight Mill. Agriculture 2022,
12, 120. [CrossRef]
51. Sagheer, A.; Kotb, M. Unsupervised Pre-Training of a Deep LSTM-Based Stacked Autoencoder for Multivariate Time Series
Forecasting Problems. Sci. Rep. 2019, 9, 19038. [CrossRef] [PubMed]
52. Kashyap, P.K.; Kumar, S.; Jaiswal, A.; Prasad, M.; Gandomi, A.H. Towards Precision Agriculture: IoT-Enabled Intelligent
Irrigation Systems Using Deep Learning Neural Network. IEEE Sens. J. 2021, 21, 17479–17491. [CrossRef]
53. Mohammed, M.; Riad, K.; Alqahtani, N. Design of a Smart IoT-Based Control System for Remotely Managing Cold Storage
Facilities. Sensors 2022, 22, 4680. [CrossRef] [PubMed]
54. Eltawil, M.A.; Mohammed, M.; Alqahtani, N.M. Developing Machine Learning-Based Intelligent Control System for Performance
Optimization of Solar PV-Powered Refrigerators. Sustainability 2023, 15, 6911. [CrossRef]
55. Kapoor, A. Hands-On Artificial Intelligence for IoT: Expert Machine Learning and Deep Learning Techniques for Developing Smarter IoT
Systems; Packt Publishing Ltd.: Birmingham, UK, 2019.
56. Saha, D.; Manickavasagan, A. Machine Learning Techniques for Analysis of Hyperspectral Images to Determine Quality of Food
Products: A Review. Curr. Res. Food Sci. 2021, 4, 28–44. [CrossRef] [PubMed]
57. Wang, M.; Xu, Y.; Yang, Y.; Mu, B.; Nikitina, M.A.; Xiao, X. Vis/NIR Optical Biosensors Applications for Fruit Monitoring. Biosens.
Bioelectron. X 2022, 11, 100197. [CrossRef]
58. Jagtap, A.D.; Kawaguchi, K.; Karniadakis, G.E. Adaptive Activation Functions Accelerate Convergence in Deep and Physics-
Informed Neural Networks. J. Comput. Phys. 2020, 404, 109136. [CrossRef]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual
author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to
people or property resulting from any ideas, methods, instructions or products referred to in the content.