Machine-Learning-Based Spectroscopic Technique for Non-Destructive Estimation of Shelf Life and Quality of Fresh Fruits Packaged under Modiﬁed Atmospheres

: The safety and quality of fresh fruits deserve the greatest attention, and are a priority for producers and consumers alike. Modern technologies are crucial to accurately estimating and predicting fresh fruits’ quality and shelf life, to optimize supply chain management. Modified atmosphere packaging (MAP) is an essential method that maintains quality parameters and increases the shelf life of fresh fruits by reducing their ripening rates. This study aimed to develop a cost-effective, non-destructive technique using tiny machine learning (TinyML) and a multispectral sensor to predict/estimate the quality parameters and shelf life of packaged fresh dates under the natural atmosphere (Control), vacuum-sealed bags (VSBs), and MAP with different gas combinations: 20% CO 2 + N balance (MAP1), and 20% CO 2 + 10% O 2 + N balance (MAP2). The shelf life and quality parameters of the packaged fresh dates (pH, total soluble solids (TSSs), sugar content (SC), moisture content (MC), and tannin content (TC)) were evaluated under different storage temperatures and times. A multispectral sensor (AS7265x) was utilized to correlate the fruit quality parameters with spectrum analysis under the same storage conditions, to prepare the dataset to train the prediction models. The prediction models were trained in the Edge Impulse Platform, and deployed to an Arduino Nano 33 BLE sense microcontroller unit (MCU) for inference. The findings indicated that the vacuum and MAP1 efficiently increased the shelf life and maintained the quality parameters of the packaged fresh fruit to 43 ± 2.39 and 39 ± 3.34 days, respectively, at 5 ◦ C. The optimal neural network consisted of the input layer with 20 nodes (the packaging type, storage temperature, and 18 channels of the spectral sensor data at 410 to 940 nm wavelengths), two hidden layers with 20 and 12 nodes, and an output layer with one node for the target quality parameter or shelf life. These optimal prediction models efficiently predicted the shelf life with R 2 = 0.951, pH with R 2 = 0.854, TSSs with R 2 = 0.893, SC with R 2 = 0.881, MC with R 2 = 0.941, and TC with R 2 = 0.909. The evaluation of the developed prediction models under each packaging condition indicated that these models serve as powerful tools for accurately predicting fruit quality parameters, and estimating the shelf life of fresh dates


Introduction
The date palm (Phoenix dactylifera L.) is among the ancient fruit-bearing plants flourishing in North Africa and the Middle East.Date palm fruits are a staple food, and a primary source of revenue, for many communities [1].Approximately 8.46 million tons of date palm fruits are produced yearly worldwide.Saudi Arabia exported 1.54 million tons in 2022 [2].The pre-maturation, maturation, and ripening stages of date palm fruits are Hababauk, Kamri, Khalal, Rutab, and Tamr.These growth phases lead to various alterations in color, chemical composition, sweetness, and texture, both internally and externally, based on the maturity and ripeness.The Khalal stage is the initial stage of date fruit ripening [3,4].Date fruits can be marketed at the Khalal, Rutab, and Tamr ripening stages.Dates in the Khalal stage are edible, and ready for marketing as fresh ripe fruit.Khalal date fruits have a solid surface, crisp texture, and red or bright yellow color, based on the date palm tree cultivar.The fruit at the Rutab stage, in terms of appearance, has a partly browned color at its tip, which then extends gradually to the whole fruit.The Rutab fruits are delicate, have a short shelf life, and are highly perishable.Tamr is the final ripening stage of date fruits.The color of the Tamr fruits is usually dark brown, and the fruit texture is pliable or hard, based on the date palm cultivar [5].Fresh dates are suggested as a wholesome and nourishing snack, which is attributed to their reduced total sugar content compared to ripped date fruits (Tamr).When they are consumed before reaching full maturity, fresh dates can be enjoyed liberally, without raising concerns about the number of daily servings, and their potential impact on glycemic levels (GL) [6][7][8].However, fresh dates are seasonal, and available only between July and November.Therefore, food security demands the storage of fruits in suitable conditions, to preserve their quality for consumption out of season, to slow down fruit decay, to keep them in good shape, and to ensure an even supply to the market, to allow higher pricing [9][10][11].
Preserving the quality of fresh date palm fruits during the marketing process is a significant technical hurdle, particularly at the Khalal stage of maturity [12].The factors that affect the optimal packaging of fresh fruits include the respiration rate of the product, the desired gas composition to extend the shelf life, the surrounding temperature and gas composition, the volume, area, and thickness of the packaging material, and the permeability of the film to CO 2 and O 2 gases [13].Therefore, modified atmosphere packaging (MAP) is an efficient method that effectively prolongs the shelf life of many fresh products, by modifying the atmosphere surrounding the product inside a package.MAP involves replacing the air-sealed fruit package with modified gases, such as carbon dioxide, nitrogen, argon, and oxygen, which help to preserve the product's quality and freshness [14][15][16].In addition, intelligent MAP is a packaging system that can carry out intelligent functions, including detecting, sensing, tracing, recording, applying scientific logic, and communicating, to facilitate decision-making, to improve quality, extend shelf life, enhance safety, warn about potential problems, and provide information [17].
The quality parameters of dates are responsible for maintaining a fruit's freshness and shelf life.However, the traditional measurement analysis of these properties, and other parameters that can reflect the quality of the fruit, is not only time-consuming and labor-intensive, but also highly destructive to the fruit.Therefore, conducting a fast and non-destructive assessment of fruit quality has become a critical topic [4,18].The most popular widespread assessment methods in the food industry are indeed NIR spectroscopy (NIRs), image and multi/hyperspectral analysis, and vis/near-infrared (Vis-NIRs) spectroscopy [19].The techniques of NIRs, Vis-NIRs, and multispectral/hyperspectral analysis are all rooted in the principles of spectroscopy, but differ in terms of the wavelength range, and the interaction of light with matter.NIRs uses the near-infrared electromagnetic spectrum region from 700 to 2500 nanometers.NIRs is utilized to measure the absorption of light by the target materials.NIRs is a non-destructive method that does not destroy the material being evaluated.Therefore, NIRs offers an efficient quality evaluation for agricultural products.Vis-NIRs uses the electromagnetic spectrum's visible and near-infrared regions from 400 to 2500 nanometers.Vis-NIRs is more versatile than NIRs because it can measure a broader range of chemical compounds.Image and multi/hyperspectral analysis are spectroscopy types that use hyperspectral images to measure light absorption by materials.Hyperspectral images are images that contain information about the spectral reflectance or emission of materials at multiple wavelengths.Each technique offers special advantages and applications, contributing to a wide range of fields, such as agriculture, food safety, and remote sensing [20][21][22].The hyperspectral imaging method to detect the microbial contamination of date palm fruits, using latent and quadratic discriminant analyses, was investigated in [23].For example, a previous research identified fungal-infected and healthy date fruits using the different wavelengths of 1120, 1300, 1610, and 1650 nm [23].In addition, the NIR and visible spectroscopy were used to assess fruit and vegetable quality, and their internal characteristics [24].Numerous scholars have employed spectral ranges such as visible-short-wave near-infrared (Vis-SWNIR), near-infrared (NIR), and infrared (IR) bands, to analyze reflective characteristics for assessing the quality and shelf life of diverse fruits, including the chardonnay grapes [25], kesar mango [26], muskmelon [27], strawberry [28], persimmon [29], kiwi fruit [30], pineapple [31], date fruit [32], and Royal Gala [33].
The quality and shelf life of the fresh fruits in the supply chain undergo dynamic changes over time, depending on environmental factors.The machine learning (ML) approach can be beneficial in developing models that boast a high accuracy in estimation or prediction under these environmental factors [34].The prediction and estimation of the shelf life of fresh fruits is critical to scheduling them for consumption at the right time in the supply chain to benefit from their nutritional advantages [18].ML includes algorithms that derive niche information from data, and use this information in learning, for estimation, prediction, and classification.ML has the potential to enhance food sustainability by enhancing agricultural methods such as precision farming, which aims to minimize resource consumption, while maximizing crop yields.Furthermore, ML can oversee crop development, and provide more precise yield forecasts, aiding farmers in improved planning and waste reduction.Additionally, artificial intelligence (AI) finds utility within the supply chain, enabling food quality monitoring, and curtailing waste, by anticipating customer demand and optimizing logistics, resulting in more efficient deliveries [18,[35][36][37].
Internet of things (IoT) and ML applications are used to evaluate the quality of the fruit.In addition, the use of deep learning techniques to grade, classify, and predict the quality parameters of fruits has been proposed by several researchers [5,27,[37][38][39][40][41][42][43].The decision regarding model development and deployment is determined through two methodologies: cloud computing and edge computing.Cloud computing entails providing services via the internet, granting users access to virtual resources such as computing power, software, storage, and services on a need basis, without the management of hardware.On the other hand, edge computing pertains to a novel computing paradigm encompassing a diverse network and array of devices for the user.Edge computing involves processing data closer to the point of origin, facilitating faster and more voluminous data processing.This, in turn, results in immediate action-orientated outcomes in real time.The choice of computing is made according to several favorable parameters, such as the inference time, training time, bandwidth, scalability, latency, reliability, economics, and privacy.Therefore, most agricultural food chain activities benefit Edge AI computing [44].Edge AI conducts most of its data processing in a localized way, resulting in reduced data transmission over the internet, and a considerable preservation of internet bandwidth.Additionally, edge computing tools are fashioned with an exceptional power efficiency, translating to lower power demands for running AI at the edge than for cloud data centers.Lightweight models can be used to satisfy Edge AI computing requirements.In addition, the new Edge AI computing paradigm is known as tiny machine learning (TinyML), which can be deployed on micro-controllers [45].TinyML is a field of ML that focuses on the development of machine learning models that can run on small devices.TinyML models are typically much smaller and simpler than traditional machine learning models, making it possible to run them on devices with limited resources.TinyML presents intelligence to low-power and low-memory tiny devices, by allowing ML [46].
To our knowledge, no previous study has been conducted to predict the shelf life combined with quality parameters for fresh date fruits using the multispectral sensor and TinyML regression model.However, using computer vision and other classification models, several related works exist for other fruits, such as the Royal Gala, strawberry, mango, banana, musk melon, and grape.Accordingly, the current study aimed to estimate the shelf life and quality parameters of date fruits under different packaging atmospheres and temperature conditions, by developing a low-cost, non-destructive spectroscopic technique.Our contributions toward fulfilling the aim of the study can be outlined as follows:

•
Investigate the influence of MAP, temperature, and storage days on the shelf life and quality parameters of dates.

•
Evaluate the quality parameters and shelf life of dates during storage under storge conditions.

•
Develop a low-cost and fast inference multispectral sensor-based detector for reflectance spectroscopy data acquisition in dates during storage.

•
Develop predictive models, using Edge Impulse to predict the quality and shelf life of packaged dates, based on reflectance spectroscopy.

•
Validate the performance of the developed TinyML models for predicting packaged fruits' shelf life and quality under different storage conditions.

Collection and Preparation of the Samples
The fresh date samples (Khalas cv.) were harvested at the Khalal stage from the experimental orchard (25.268089 • N, 49.708498 • E) of the Date Palm Research Center of Excellence (DPRC), King Faisal University (KFU), Saudi Arabia.At the Khalal stage, the fruits are yellow, have a high moisture content, and are still hard, which gives them a crunchy texture.After this stage is the Rutab stage, when the yellow color begins to convert to brown, gradually.
The samples were cleaned, washed with potable water, and sorted immediately after harvesting.Approximately 250 g of the fruits were packaged into vacuum-sealed bags, and in modified atmosphere packaging (MAP) trays (35 × 135 × 185 mm) with a single layer.Afterward, half of the date fruits were packaged and stored at 5 • C in a cold storage room, and the other half was left at controlled room temperature (22 • C) for the conduction of the storage treatments.The vacuum sealer model VS6611X, Yumyth Electronic Tech Co., Limited, Guangdong, China, was used to seal the vacuum sealer bags, after they were packaged with precooled samples.The MAP trays were vacuumed, desired with gas mixtures, and sealed using a tray-sealing machine (VC999 TS300, Bernhard Inauen, Herisau, Switzerland).
The MAP experiment consisted of the following four treatments: • Unsealed trays in the natural atmosphere (Control).
The target-modified atmosphere (20% CO 2 + N balance and 10% O 2 + 20% CO 2 + N balance) was supplied from premixed gas cylinders.The validation of the gas concentration levels in the sealed MAP trays was performed after the completion of tray packaging with the target gas and, during storage time, using a portable gas analyzer (OXYBABY ® M+ gas, Gase Technik GmbH & Co KG, Salinger Feld, Witten, Germany).
The treated containers were stored at 5 ± 0.5 • C in the cold storage room, and at 22 ± 1 • C in the room temperature, for shelf life and quality parameter estimation at 0, 10, 20, 30, 40, 50, and 60 days of storage.Three containers from each packaging treatment were randomly selected for the initial quality evaluation, and after each storage time.In addition, the percentage of fresh fruits that turned into dates and Rutab, or spoiled, was calculated during storage days.

Quality Parameter Measurments
The fruit quality criteria, i.e., the moisture content (MC), total soluble solids (TSSs), total sugar (TS), pH, and tannin content (TC) were assessed within the fruit quality laborato-ries of the DPRC.The MC of the fruit was determined through the vacuum drying of a 50 g sample at 70 • C, using a vacuum-drying oven model LVO-2041P, Daihan Labtech Co., Ltd., Namyangju-si, Gyeonggi-do, Korea.The weight of the sample was then measured after 48 h, in accordance with the recognized analysis protocols of the Association of Official Analytical Chemists International (AOAC) [47].The portable aw device model (aqualab, 3Series 3, Decagon Devices, Inc., Pullman, WA, USA) was used to determine the fruit aw, according to the standard analysis methods of the AOAC [47].The digital laboratory refractometer (model RFM 840, Richmond Scientific Ltd.Unit 9, Lancashire, UK) was used to determine the TSSs of the date fruits.The anthrone-sulfuric acid colorimetry method was used to determine the TS of the date fruits.This method was described in [4,36,48].The absorbance at 630 nm wavelength was determined using a spectrophotometer (model Genesys 20, Thermo Scientific, Waltham, MA, USA).A portable pH meter (model S400, Mettler-Toledo LLC, Columbus, OH, USA) was used to measure the fruit pH.A spectrophotometer (model Genesys 20, Thermo Scientific, Waltham, MA, USA) was used to measure the TC of the fruits at 750 nm wavelength.The TC was quantified through the employment of a calibration curve derived from the measurement of the absorbance of predetermined concentrations of gallic acid [49].

Multispectral Sensor Description
A multispectral sensor (AMS -OSRAM AG, Tobelbader Straße, Premstaetten, Austria) was used to measure the spectral reflectance of the tested date fruits.This sensor consists of the AS7265x chipset that incorporates three chips, i.e., AS72651, AS72652, and AS72653, to deliver an 18-channel VIS to the Vis-SWNIR sensing array, covering wavelengths from 410 nm to 940 nm, to detect fresh dates' physicochemical properties.This chipset is equipped with on-device optical filters, characterized by on-device Gaussian band pass filters that exhibit a 20 nm full width.The chipset incorporates three sensors, each featuring six distinct wavelengths, totaling eighteen wavelengths across the spectrum.The normalized responsivity of the spectrum for the AS7265x triad chipset is depicted in Figure 1, sourced from the manufacturer's datasheet [50].Additionally, the sensors are furnished with integrated programmable constant current-led drivers, facilitating light intensity adjustment.The reflections from the target date fruit are applied, to obtain the fruit MC, pH, TSSs, S, and TC.The wavelengths employed in the AS7265x optical sensors align with the specific absorption peaks relevant to the fresh date maturity analysis from the Khalal to the Tamr.
The fruit quality criteria, i.e., the moisture content (MC), total soluble solids (TSSs), total sugar (TS), pH, and tannin content (TC) were assessed within the fruit quality laboratories of the DPRC.The MC of the fruit was determined through the vacuum drying of a 50 g sample at 70 °C, using a vacuum-drying oven model LVO-2041P, Daihan Labtech Co., Ltd., Namyangju-si, Gyeonggi-do, Korea.The weight of the sample was then measured after 48 h, in accordance with the recognized analysis protocols of the Association of Official Analytical Chemists International (AOAC) [47].The portable aw device model (aqualab, 3Series 3, Decagon Devices, Inc., Pullman, WA, USA) was used to determine the fruit aw, according to the standard analysis methods of the AOAC [47].The digital laboratory refractometer (model RFM 840, Richmond Scientific Ltd.Unit 9, Lancashire, UK) was used to determine the TSSs of the date fruits.The anthrone-sulfuric acid colorimetry method was used to determine the TS of the date fruits.This method was described in [4,36,48].The absorbance at 630 nm wavelength was determined using a spectrophotometer (model Genesys 20, Thermo Scientific, Waltham, MA, USA).A portable pH meter (model S400, Mettler-Toledo LLC, Columbus, OH, USA) was used to measure the fruit pH.A spectrophotometer (model Genesys 20, Thermo Scientific, Waltham, MA, USA) was used to measure the TC of the fruits at 750 nm wavelength.The TC was quantified through the employment of a calibration curve derived from the measurement of the absorbance of predetermined concentrations of gallic acid [49].

Multispectral Sensor Description
A multispectral sensor (AMS -OSRAM AG, Tobelbader Straße, Premstaetten, Austria) was used to measure the spectral reflectance of the tested date fruits.This sensor consists of the AS7265x chipset that incorporates three chips, i.e., AS72651, AS72652, and AS72653, to deliver an 18-channel VIS to the Vis-SWNIR sensing array, covering wavelengths from 410 nm to 940 nm, to detect fresh dates' physicochemical properties.This chipset is equipped with on-device optical filters, characterized by on-device Gaussian band pass filters that exhibit a 20 nm full width.The chipset incorporates three sensors, each featuring six distinct wavelengths, totaling eighteen wavelengths across the spectrum.The normalized responsivity of the spectrum for the AS7265x triad chipset is depicted in Figure 1, sourced from the manufacturer's datasheet [50].Additionally, the sensors are furnished with integrated programmable constant current-led drivers, facilitating light intensity adjustment.The reflections from the target date fruit are applied, to obtain the fruit MC, pH, TSSs, S, and TC.The wavelengths employed in the AS7265x optical sensors align with the specific absorption peaks relevant to the fresh date maturity analysis from the Khalal to the Tamr.

TinyML Prediction Models
The prediction models for shelf life and quality parameter estimation were developed using TinyML, supported by the Edge Impulse Cloud MLOPs engine.The developed models were targeted to a microcontroller of Arduino Nano33 BLEsense-Cortex M4 that can run the prediction neural network (NN) models.The Nano33 BLE sense board hosts several sensors that facilitate TinyML wide-range purposes.The workflow of the TinyML model typically consists of five stages, as illustrated in Figure 2    The values of the reflectance readings obtained from samples using the 18-channel spectral sensor were captured, utilizing a 12.5 mA current source drive, and a receiver gain set at 64x.The 18-channel spectral filters were systematically adjusted in increments of 20 nm, spanning from 410 nm to 940 nm, for each specified configuration of current and

TinyML Prediction Models
The prediction models for shelf life and quality parameter estimation were developed using TinyML, supported by the Edge Impulse Cloud MLOPs engine.The developed models were targeted to a microcontroller of Arduino Nano33 BLEsense-Cortex M4 that can run the prediction neural network (NN) models.The Nano33 BLE sense board hosts several sensors that facilitate TinyML wide-range purposes.The workflow of the TinyML model typically consists of five stages, as illustrated in Figure 2

TinyML Prediction Models
The prediction models for shelf life and quality parameter estimation were developed using TinyML, supported by the Edge Impulse Cloud MLOPs engine.The developed models were targeted to a microcontroller of Arduino Nano33 BLEsense-Cortex M4 that can run the prediction neural network (NN) models.The Nano33 BLE sense board hosts several sensors that facilitate TinyML wide-range purposes.The workflow of the TinyML model typically consists of five stages, as illustrated in Figure 2    The values of the reflectance readings obtained from samples using the 18-channel spectral sensor were captured, utilizing a 12.5 mA current source drive, and a receiver gain set at 64x.The 18-channel spectral filters were systematically adjusted in increments of 20 nm, spanning from 410 nm to 940 nm, for each specified configuration of current and gain outlined above.These spectral measurements were carried out on the exact storage  days when laboratory analyses were conducted on the identical samples, tracking their progression through the distinct maturity stages from Fresh to Tamr.Furthermore, all samples underwent testing under consistent environmental light conditions (300 Lux), and maintained a uniform distance of 3 cm between the spectral sensor and the sample.TinyML has experienced remarkable advancements, leading to the emergence of numerous tools for the development and testing of ML algorithms.In this study, artificial N architectures have been employed for the deployment of the TinyML prediction model on the microcontroller, to predict the packaged date fruit's shelf life and quality parameters.The reflected light corresponding to the major quality parameters of pH, TSSs, SC, MC, TC, and the shelf life of dates as carried as an input variable for the prediction NN-based model.
The input variables were derived from the AS7265x sensor, using the I2C port of the microcontroller (serving as the Edge Device).The sample architecture of the NN model is depicted in Figure 4.The hidden layers are responsible for data processing, while the output layer provides the predicted values for a specific target, either the shelf life or a quality parameter.The values of the reflectance readings obtained from samples using the 18-channel spectral sensor were captured, utilizing a 12.5 mA current source drive, and a receiver gain set at 64x.The 18-channel spectral filters were systematically adjusted in increments of 20 nm, spanning from 410 nm to 940 nm, for each specified configuration of current and gain outlined above.These spectral measurements were carried out on the exact storage days when laboratory analyses were conducted on the identical samples, tracking their progression through the distinct maturity stages from Fresh to Tamr.Furthermore, all samples underwent testing under consistent environmental light conditions (300 Lux), and maintained a uniform distance of 3 cm between the spectral sensor and the sample.
TinyML has experienced remarkable advancements, leading to the emergence of numerous tools for the development and testing of ML algorithms.In this study, artificial N architectures have been employed for the deployment of the TinyML prediction model on the microcontroller, to predict the packaged date fruit's shelf life and quality parameters.The reflected light corresponding to the major quality parameters of pH, TSSs, SC, MC, TC, and the shelf life of dates as carried as an input variable for the prediction NN-based model.
The input variables were derived from the AS7265x sensor, using the I2C port of the microcontroller (serving as the Edge Device).The sample architecture of the NN model is depicted in Figure 4.The hidden layers are responsible for data processing, while the output layer provides the predicted values for a specific target, either the shelf life or a quality parameter.
The values obtained from the input layer are combined with those of a hidden node, and then multiplied by their designated weights as preset values.As a result, the outcomes of this operation are added up, to fashion a new value.This newly spawned value is steered toward a mathematical function, followed by an activation function, to complete the process (ReLu-rectified linear unit) to predict fresh date fruits' shelf life and quality parameters, until they reach the date stage.The accumulation of weighted inputs entering a neural network node labeled "j" is combined with the output activation function, which transforms the neuron's weighted value into its rectified linear unit (ReLU) output activation function, as illustrated in Figure 5.
In this research, the development of TinyML prediction models was accomplished using the Edge Impulse.The training of the multilayer perceptron module NN employed a backpropagation learning algorithm, along with an optimizer (Adam).This optimizer was utilized to adjust the weights in a manner that reduced the error function.Adam optimization is a stochastic gradient descent algorithm that relies on the adaptable estimation of first-and second-order moments.The data were arranged randomly, wherein 80% were allocated for training, and the remaining 20% were used for testing.While the training dataset was utilized for weight determination and model construction, the testing data were leveraged to identify errors and prevent overtraining during the training process.The values obtained from the input layer are combined with those of a hidden node, and then multiplied by their designated weights as preset values.As a result, the outcomes of this operation are added up, to fashion a new value.This newly spawned value is steered toward a mathematical function, followed by an activation function, to complete the process (ReLu-rectified linear unit) to predict fresh date fruits' shelf life and quality parameters, until they reach the date stage.The accumulation of weighted inputs entering a neural network node labeled "j" is combined with the output activation function, which transforms the neuron's weighted value into its rectified linear unit (ReLU) output activation function, as illustrated in Figure 5.In this research, the development of TinyML prediction models was accomplished using the Edge Impulse.The training of the multilayer perceptron module NN employed a backpropagation learning algorithm, along with an optimizer (Adam).This optimizer was utilized to adjust the weights in a manner that reduced the error function.Adam optimization is a stochastic gradient descent algorithm that relies on the adaptable estimation of first-and second-order moments.The data were arranged randomly, wherein 80% were allocated for training, and the remaining 20% were used for testing.While the training dataset was utilized for weight determination and model construction, the testing data were leveraged to identify errors and prevent overtraining during the training process.
The parameters of the NN regression model utilized in the implementation of predictions are outlined in Table 1.Given that the model's objective is to predict continuous  The values obtained from the input layer are combined with those of a hidden node and then multiplied by their designated weights as preset values.As a result, the outcome of this operation are added up, to fashion a new value.This newly spawned value i steered toward a mathematical function, followed by an activation function, to complet the process (ReLu-rectified linear unit) to predict fresh date fruits' shelf life and qualit parameters, until they reach the date stage.The accumulation of weighted inputs enterin a neural network node labeled "j" is combined with the output activation function, whic transforms the neuron's weighted value into its rectified linear unit (ReLU) output activa tion function, as illustrated in Figure 5.In this research, the development of TinyML prediction models was accomplishe using the Edge Impulse.The training of the multilayer perceptron module NN employe a backpropagation learning algorithm, along with an optimizer (Adam).This optimize was utilized to adjust the weights in a manner that reduced the error function.Adam op timization is a stochastic gradient descent algorithm that relies on the adaptable estima tion of first-and second-order moments.The data were arranged randomly, wherein 80% were allocated for training, and the remaining 20% were used for testing.While the train ing dataset was utilized for weight determination and model construction, the testing dat were leveraged to identify errors and prevent overtraining during the training process.
The parameters of the NN regression model utilized in the implementation of pre dictions are outlined in Table 1.Given that the model's objective is to predict continuou values for the quality parameters and shelf life of fruits, regression models were selected Furthermore, the edge device is constrained by memory limitations, leading to a prefer ence for lightweight regression models in this context.Every 10 days, there was a need t collect samples for laboratory analysis to validate the quality parameters of dates durin The parameters of the NN regression model utilized in the implementation of predictions are outlined in Table 1.Given that the model's objective is to predict continuous values for the quality parameters and shelf life of fruits, regression models were selected.Furthermore, the edge device is constrained by memory limitations, leading to a preference for lightweight regression models in this context.Every 10 days, there was a need to collect samples for laboratory analysis to validate the quality parameters of dates during the storage days.Therefore, 10 fruit samples at 0, 10, 20, 30, 40, 50, and 60 days of storage were taken for each packaging type, under each storage temperature.
Consequently, the total sample number was 70, which was sufficient for training.The total required sample number was 168, sufficient for training to predict the quality parameters of packaged fruits in all packaging types and at all storage temperatures.A batch size of 32 was opted for, to mitigate memory usage during both the training and inference stages.A learning rate of 0.005 was selected, considering the batch size, and aiming for improved merging.The ADAM optimizer was employed, due to its rapid convergence capabilities.
Table 1.Network information for the NN Block to predict the quality parameters and shelf life of packaged date fruits under each packaging type and storage temperature condition, and to predict the quality parameters of packaged fruits at all packaging types and storage temperatures.A, B, C, D, E, F, G, H, I, J, K, L, R The developed NN prediction models were deployed, to authenticate their accuracy using the external validation dataset.The Edge Impulse cloud platform is purpose-built for the deployment of models on edge devices for real-time applications.Considering the hyperparameters employed for the NN model, to predict the quality parameters of packaged fruit under various atmosphere and temperature conditions, the inference time stands at 1 millisecond, and the RAM usage amounts to 1.8 kilobytes out of the available 256 kilobytes for the storing model parameters.Furthermore, the NN regression model utilizes just 10.9 kilobytes out of the 1 megabyte flash available.These statistics underscore the optimization of this model for real-time inference using the implemented TinyML predictions models.

Statistical Analysis and TinyMl Models Evaluation
The analysis of variance (ANOVA) at p < 0.05 using IBM SPSS Software version 26 (SPSS Inc., Chicago, IL, USA) was used to perform the statistical analysis.The coefficient of determination (R 2 ), mean absolute error (MAE), and the root-mean-square error (RMSE) were used as statistical measures to evaluate the performance of the developed TinyML prediction models, using the following formulas: where O j is the observed value, P j is the predicted values of the target parameter data j, and n is the number of the measure values.R 2 is an essential statistical measure that determines how well the modeled data fit the observation data, to describe the strength of a linear relationship between the observed and predicted values.The absolute error is the absolute value of the difference between the predicted and the observed values over the test sample, where all individual differences have equal weight.The MAE evaluates the precision of the continuous variables by computing the average magnitude of errors generated by a given set of predictions, without considering their direction.The RMSE measures the error between two datasets, by measuring the difference between the predicted values from the developed model, and the observed values from the modeled measurements.The RMSE aggregates these residuals into a single measure of predictive effectiveness.Therefore, the RMSE was used to compare the predicted and observed values.

Influence of Storage Conditions on Fresh Dates
The influence of modified atmosphere packaging (MAP) on Khalal-stage dates (cv.Khalas) stored for 0, 10, 20, 30, 40, 50, and 60 days, at 5 and 22 • C, showed a statistically significant (p ≤ 0.05) difference (Figure 6A-H).The results of the unsealed control treatment indicated that the fruit percentage of Khalal-stage fruits linearly decreased after 8 days of storage (DOS) when kept at 5 • C (Figure 6A).However, an immediate decline was observed when same-stage fruits were stored at 22 • C (Figure 6B).Similarly, 55% of Khalal fruits were converted to the Rutab stage after 30 DOS at both temperatures; after that, the percentage declined.The fruit was changed to Tamr after 30 DOS at 5 • C, and attained the highest percentage (60%) after 60 DOS.However, fruits stored at 22 • C changed to Tamr after 25 DOS, and 90% Tamr fruits were recorded after 53 DOS.Fruit spoilage was started after 20 DOS at 5 • C, and the maximum percentage of spoiled fruits (40%) was noted after 60 DOS.It increased by 15% from 50 to 60 DOS, when fruit were stored at 22 • C. Figure 6C indicates that 100% of Khalal fruits stored at 5 • C in VSBs remained fresh up to 30 DOS.However, these were counted for 24 days stored at 22 • C (Figure 6D).Similarly, fruits were starting to convert into Rutab after 30 DOS at both temperatures, and gained the highest Rutab fruit percentage after 60 DOS (50%).Fruits stored in VSBs at both temperatures did not convert to the Tamr stage.However, only 5% of fruits were spoiled at 5 • C, and 35% at 22 • C, after 60 DOS.Khalal fruits stored at 5 • C in MAP trays sealed with 20% CO 2 and N balance remained fresh up to 28 DOS (Figure 6E), 23 days at 22 • C (Figure 6F), and declined afterward.However, Khalal fruits converted to the Rutab stage after 33 DOS at 5 • C, and 25 DOS at 22 • C, and had the highest percentage (60 and 50%, respectively) after 60 DOS.None of the Tamr fruits were observed in MAP trays sealed with 20% CO 2 and N at both temperatures.Only 8% of spoiled fruits were counted at 5 • C, whereas it was 40% at 22 • C after 60 DOS.The data presented in Figure 6G show that the Khalal fruits stored at 5 • C in MAP trays sealed with 10% O 2 , 20% CO 2 , and N balance persisted fresh up to 23 DOS, which were counted for 21 days at 22 • C (Figure 6H).The stored fruits started to convert to the Rutab stage after 27 DOS at 5 • C, and the highest Rutab fruit percentage (72%) was recorded after 60 DOS.On the other hand, the fruits stored at 5 • C converted to Rutab stage after 25 DOS and achieved the highest Rutab fruit percentage (46%) after 60 DOS.Fruits kept at either temperature in MAP trays sealed with 10% O 2 , 20% CO 2 , and N balance did not reach the Tamr stage.The percentage of spoiled fruits was lowest (19%) at 5 • C, and highest (59%) at 22 • C after 60 DOS.The fruit spoilage stage started at 24 DOS and 25 DOS, at 5 and 22 • C, respectively.
Figure 7 shows the impact of the various packaging atmosphere conditions on the shelf life of fresh date fruits at 5 • C and 22 • C. At 5 • C, the shelf life of the fresh date fruits packaged in natural air was 15 ±1.05 days.However, the VSBs significantly increased the shelf life of the fruits, to 43 ± 2.39 days.This is due to the vacuum packaging creating a low-oxygen environment that helps to preserve the freshness and extend the shelf life of the fruits.The MAP also positively impacted the shelf life of fresh dates.MAP1, which involved modifying the atmosphere by adjusting the N and CO 2 levels, resulted in a shelf life of 39 ± 3.34 days at 5 • C. MAP2, which involved modifying the atmosphere by adjusting the O 2 , N, and CO 2 levels, extended the shelf life to only 29 ± 1.18 days, at the same temperature.At 22 • C, the fresh date fruits' shelf life in natural air decreased to 11 ± 1.05 days.However, the VSBs proved highly effective, increasing the shelf life to 34 ± 2.21 days.This indicates that VSBs can help to save fresh dates' quality, and extend their shelf life, even at higher temperatures.Similarly, the MAP options also demonstrated their effectiveness at 22 • C. MAP1 resulted in a shelf life of 31± 2.92 days, while MAP2 extended the shelf life to 25 ± 1.18 days.The stored fruits started to convert to the Rutab stage after 27 DOS at 5 °C, and the highest Rutab fruit percentage (72%) was recorded after 60 DOS.On the other hand, the fruits stored at 5 °C converted to Rutab stage after 25 DOS and achieved the highest Rutab fruit percentage (46%) after 60 DOS.Fruits kept at either temperature in MAP trays sealed with 10% O2, 20% CO2, and N balance did not reach the Tamr stage.The percentage of spoiled fruits was lowest (19%) at 5 °C, and highest (59%) at 22 °C after 60 DOS.The fruit spoilage stage started at 24 DOS and 25 DOS, at 5 and 22 °C, respectively.
Figure 7 shows the impact of the various packaging atmosphere conditions on the shelf life of fresh date fruits at 5 °C and 22 °C.At 5 °C, the shelf life of the fresh date fruits packaged in natural air was 15 ±1.05 days.However, the VSBs significantly increased the shelf life of the fruits, to 43 ± 2.39 days.This is due to the vacuum packaging creating a low-oxygen environment that helps to preserve the freshness and extend the shelf life of the fruits.The MAP also positively impacted the shelf life of fresh dates.MAP1, which involved modifying the atmosphere by adjusting the N and CO2 levels, resulted in a shelf life of 39 ± 3.34 days at 5 °C.MAP2, which involved modifying the atmosphere by adjusting the O2, N, and CO2 levels, extended the shelf life to only 29 ± 1.18 days, at the same temperature.At 22 °C, the fresh date fruits' shelf life in natural air decreased to 11 ± 1.05 days.However, the VSBs proved highly effective, increasing the shelf life to 34 ± 2.21 days.This indicates that VSBs can help to save fresh dates' quality, and extend their shelf life, even at higher temperatures.Similarly, the MAP options also demonstrated their effectiveness at 22 °C.MAP1 resulted in a shelf life of 31± 2.92 days, while MAP2 extended the shelf life to 25 ± 1.18 days.

Quality Parameters of Dates
Table 2 provides a detailed overview of the mean values of quality attributes of dates at the different ripening stages, namely Fresh (Khalal), Rutab, and Tamr.This table indicates the highest pH, TSSs, and sugar content, and lowest MC and tannin content in Tamr fruit, followed by Rutab-stage fruits.The fresh fruits at the Khalal stage had the lowest pH, TSSs, and sugar content, and the highest MC and tannin content.Some physicochemical studies on date palm fruit also reported that the MC and tannin content is decreased

Quality Parameters of Dates
Table 2 provides a detailed overview of the mean values of quality attributes of dates at the different ripening stages, namely Fresh (Khalal), Rutab, and Tamr.This table indicates the highest pH, TSSs, and sugar content, and lowest MC and tannin content in Tamr fruit, followed by Rutab-stage fruits.The fresh fruits at the Khalal stage had the lowest pH, TSSs, and sugar content, and the highest MC and tannin content.Some physicochemical studies on date palm fruit also reported that the MC and tannin content is decreased from the Khalal stage to the Rutab and Tamr stages, whereas the fruit pH, TSSs, and sugar content behaved oppositely, and gradually increased from the Khalal to Rutab, and Tamr stage.Khalal stage dates have higher levels of moisture and tannin than dates at the Rutab and Tamr stages of ripening.The mean (n = 56 and n total = 168) ± standard deviation is presented.The means with the same letters within each column are not significantly different at p ≤ 0.05.

Spectral Reflectance Data
Table 3 shows the spectral reflectance data for eighteen different bands at various frequencies of light, ranging from 410 nm to 940 nm, for the three ripening stages of date fruits: Fresh, Rutab, and Tamr.The reflectance is significantly (p ≤ 0.05) decreased with the change in fruit ripening stage from Khalal to Rutab and Tamr.The data show that the reflectance values vary across different wavelengths and ripening stages.There are significant differences in reflectance values between the ripening stages for some wavelengths, while the differences are not substantial for others.The reflectance was higher when the AS72653 sensor was used at a 535 nm wavelength, whereas it was lower at 485 nm at all three fruit development stages.The values are the mean (n = 20) ± standard deviation.The means with the same letters within each row are not significantly different at p ≤ 0.05.
Similarly, it was at its maximum at 585 nm, and its minimum at 940 nm, when the sensor AS72652 was used.Using the sensor AS72652, the highest reflectance values were recorded at a 610 nm wavelength, whereas they were lowest at 760 nm.Therefore, the reflectance data of the date fruits at different ripening stages and wavelengths allow for a comprehensive analysis of the spectral characteristics of the fruits during their storage.
Figure 8 displays the mean reflectance values for packaged date fruit samples under modified atmospheres, using the three spectral sensors (As72651, As72652, and AS72653), per storage day point.The mean reflected intensity is reported on the y-axis as an arbitrary unit against the different wavelength settings of the sensor.The data in this curve were obtained via the calculation of the spectral sensor's mean reflectance value at each wavelength.Each curve in this Figure represents the mean reflectance values of the fruits at different storage conditions for each storage day.In measurements wherein the absolute values cannot be obtained, arbitrary units (au) can be frequently used [51].The values are the mean (n = 20) ± standard deviation.The means with the same letters within each row are not significantly different at p ≤ 0.05.

Figure 8.
The mean reflectance values at 18 wavelengths for the packaged date fruit samples under modified atmospheres, using the three spectral sensors (As72651, As72652, and AS72653), per storage interval.

Correlation between Quality and Spectroscopy Data
Table 4 shows the coefficients of correlation between the spectroscopy reflectance data of the As72651, As72652, and AS72653 sensors at different frequencies of light, ranging from 410 nm to 940 nm, and the shelf life parameters of date fruits.This table shows significant correlations (p ≤ 0.01) between the reflectance data and the shelf life parameters of the stored dates.The reflectance data at various wavelengths show moderate to strong positive correlations with the shelf life duration (SLD), MC, and TC of the date fruits.On the contrary, the reflectance data at various wavelengths show moderate to strong negative correlations with the pH, TSSs, and SC of the date fruits.These correlations indicate that the reflectance data can be used as indicators of the quality attributes of date fruits.
Furthermore, Table 4 also indicates strong positive correlations among the shelf life parameters.For example, a strong positive correlation between TSSs and SC indicates that the total soluble solids also increase as the sugar content increases.Similarly, a strong positive correlation between MC and TC suggests that the total carbohydrates also increase as the moisture content increases.
The Edge Impulse platform's feature explorer option, with color codes for the data according to the label, was used to validate whether the acquired data separated well.For example, the reflectance value concerning the spectral sensor AS7261's output at W: 860 nm, and its AS7262 output at H: 585 nm, and shelf life is plotted for optimum data visualization for packaged samples in VSBs (Figure 9A) and MAB2 at a 5 °C storage temperature (Figure 9B).

Correlation between Quality and Spectroscopy Data
Table 4 shows the coefficients of correlation between the spectroscopy reflectance data of the As72651, As72652, and AS72653 sensors at different frequencies of light, ranging from 410 nm to 940 nm, and the shelf life parameters of date fruits.This table shows significant correlations (p ≤ 0.01) between the reflectance data and the shelf life parameters of the stored dates.The reflectance data at various wavelengths show moderate to strong positive correlations with the shelf life duration (SLD), MC, and TC of the date fruits.On the contrary, the reflectance data at various wavelengths show moderate to strong negative correlations with the pH, TSSs, and SC of the date fruits.These correlations indicate that the reflectance data can be used as indicators of the quality attributes of date fruits.
Furthermore, Table 4 also indicates strong positive correlations among the shelf life parameters.For example, a strong positive correlation between TSSs and SC indicates that the total soluble solids also increase as the sugar content increases.Similarly, a strong positive correlation between MC and TC suggests that the total carbohydrates also increase as the moisture content increases.
The Edge Impulse platform's feature explorer option, with color codes for the data according to the label, was used to validate whether the acquired data separated well.For example, the reflectance value concerning the spectral sensor AS7261's output at W: 860 nm, and its AS7262 output at H: 585 nm, and shelf life is plotted for optimum data visualization for packaged samples in VSBs (Figure 9A) and MAB2 at a 5 • C storage temperature (Figure 9B).Through examining the various graphs, it becomes evident that there are linear correlations between the reflectance values captured by the spectral sensor, and the shelf life duration.This observation validates the dataset's strength in being suitable for training the model.Across all subsequent graphs, the x-axis consistently represents the shelf life values.A zero shelf-life value means that the fresh (Khalal) fruits have started turning to Rutab, or spoiled.The fruit becomes half-ripe, softens in texture, and turns light brown.The colors given for the tested samples in Figure 9 were arbitrary, and informed by the Edge Impulse studio application for appropriate visualization.The value of reflectance (au) AS7262 at H: 585 nm is marked as "Re H"; the value of reflectance (au) AS7261 at W: 650 nm is marked as "Ref W".The results indicated that the TinyML models showed a promising performance in predicting the fresh fruit shelf life parameters under different packaging types and storage temperatures.The high R 2 values and low MAE and RMSE values indicate the accuracy and reliability of the models in predicting the target parameters.
The validation of the developed TinyML models indicated that the obtained results showed promise in predicting the fresh fruit shelf life and quality during the ripening process, as they are experimentally verified for their robustness through validation against the lab results.Figure 10 displays the scatter plots for the predicted values of the shelf life period (Figure 10A), pH (Figure 10B), TSSs (Figure 10C), SC (Figure 10D), MC (Figure 10E), and TC (Figure 10F) of the packaged date fruits under the modified atmosphere and storage temperature conditions versus the values observed by the TinyML models in the evaluation phase, based on the measured reflectance spectroscopy for 18 channels of the spectral sensor.The network structure of the model was two hidden layers with 20 and 12 neurons, respectively, which presented the highest level of accuracy.The results indicated the effectiveness of TinyML models in predicting the quality parameters, and estimating the shelf life of fresh dates packaged under different modified atmospheres.Therefore, a low-cost handheld spectral sensor integrated with a used microcontroller can efficiently predict the quality and shelf life of fresh dates under different packaging conditions.

Influence of Storage Conditions on Fresh Dates
Fresh dates are perishable products that can quickly deteriorate if not stored properly.This can lead to waste and financial losses for producers, and pose a health risk to consumers.Large losses are incurred between the cultivator and the consumer in the food product supply chain, predominantly in fruit.Substantial amounts of fruit are produced but not eaten by humans, due to supply chain losses, a component of postharvest losses [52].Therefore, a suitable preservation method is required during storage, handling, and transport throughout the supply chain, to ensure fruits' safety and quality [53,54].Accordingly, this study investigated the influence of different storage conditions on the quality parameters and the shelf life of fresh dates.
The findings of the current study indicated that, although packaging treatments showed a significant positive impact on the fresh fruit percentage at both the temperatures of 5 and 23 • C, compared to the unsealed control treatment, Khalal fruit stored at 5 • C in NAP1 and VSBs remained fresh for up to 30 DOS, compared to other packaging treatments.This treatment had a minimum percentage of Rutab and Tamr fruits after 60 DOS.Khalal fruits stored at both temperatures in VSBs and MAP showed no signs of fruit spoilage.On the other hand, fruits stored at 5 • C in unsealed control bags retained their freshness up to 8 DOS, when it immediately declined to 22 • C. In the unsealed control fruits, the water loss was high, due to which the time taken to reach the fruit development phases (Rutab and Tamr) was reduced, and the fruit spoilage percentage was increased at both temperatures.It might be because the vacuum-sealed and MAP-treated dates were packaged in closed containers to prevent water loss, limiting fruit enzymatic processes and microbial activities [15,[55][56][57][58].
Fruits have a high water content, and are metabolically active at the Khalal stage.This makes them more susceptible to unfavorable conditions, causing evaporation from fruits that increases weight loss if they are not properly stored in sealed bags [59,60].A shift in the fruit's developmental stage responds to the rise in temperature, as this triggers many of the fruit's metabolic processes [61].According to Mortazavi et al. [62], fruits in MAP and vacuum-sealed containers showed the least weight loss and lowest percentage of Rutab and spoilage fruits, whereas, in contrast, these attributes were highest in the unsealed control fruits.Similarly, Khalal fruits of cv.Khalas retained moisture content in a sealed MAP at 0 • C, and showed a negligible weight loss (<1%), compared to the control treatment (14%) after 27 DOS [14].According to Pesis et al. [63], the oxygen level that remained in the bag after the vacuum packaging of bananas depended on the permeability of the plastic film.In another study, a low amount of O 2 and CO 2 was estimated in vacuum-sealed banana containers, whereas MAP caused a decrease in O 2 and an increase in CO 2 concentrations; however, the ethylene did not gather to levels that would induce ripening [64].The findings of the current study are in line with these investigations.The increase in the shelf life of fresh Khalal fruits stored in vacuum-sealed or MAP bags might be due to the dramatic retardation of the respiration rate because of low oxygen brought about through the modification of the atmosphere.Hence, CO 2 , a product of respiration, did not accumulate in the VSBs or MAP bags, enhancing the fruit shelf life, and delaying the fruit development phases to Rutab and Tamr [63][64][65].Generally, fruit characteristics decline as the dates mature.This occurs because the date palm fruit's cells are disintegrating, and the sugars and TSSs are becoming more concentrated [62,66].In addition, biochemical changes, enzyme activities, and changes in the membrane permeability can also contribute to the increased TSS levels during fruit ripening.Enzymes lead to the release of glucose and fructose during fruit ripening, and are associated with increased cell wall hydrolyzing enzymes during ripening [67].

Non-Destructive Estimation of Shelf Life and Quality of Dates
Accurately estimating and predicting fruit quality and shelf life have become pivotal in reducing waste and optimizing supply chain management.Non-destructive evaluation methods, such as imaging and spectroscopic techniques, are used effectively to respond to food quality control challenges, as these analytical methods offer several advantages, such as the rapidity of obtaining results, non-destruction of samples, and the possibility of evaluating the products during the production process [68].In the current study, a low-cost and fast-inference multispectral sensor-based detector for the reflectance spectroscopy data acquisition of dates during storage was developed.In addition, Edge Impulse was used to develop regression models to estimate the quality and shelf life of packaged dates based on reflectance spectroscopy.The reflectance values indicated the amount of light reflected by the date fruit samples at each wavelength.Higher reflectance values suggest a higher amount of light being reflected, while lower reflectance values indicate a lower amount of light being reflected.As the storage days progressed, the reflectance values at different wavelengths changed, showing the changes in the quality parameters of the date fruit samples.As fruits ripen, their physical and chemical properties change, which affects their reflectance spectra, which can be determined using non-destructive measurement techniques, using sensors [69].The spectral reflectance results correlated with the quality parameters data, were very realistic, and proved the robustness of the triad spectroscopy sensor used in the testing.Having verified the matching/correctness of the spectral data with the measurement results for all the major quality parameters during the days of storage that affect fruit maturity, the dataset was appropriate for labeling, to train the NN models.
The Edge Impulse platform provided a good structure to build a model.It allowed us to upload the preprocessed data.Therefore, in this experiment, the acquired data were uploaded and indicated as time series data, using the Edge Impulse platform.The dataset assembly comprised separate files (csv) for all data of reflectance value from the three spectral sensors (As72651, As72652, and AS72653) and the quality parameters and shelf life of packaged samples under natural air, VSBs, MAP1, and MAP2 as a numeric value.Then, the dataset was uploaded to the Edge Impulse cloud training platform, to train the regression model.The data were treated as time series data, because it is important to consider the temporal relationships between the data points [35].The shelf life of a date fruit is not just determined by its moisture content, sugar level, and pH at a single point in time.It is also determined by how these values change over time.For example, a date fruit with a high moisture content and a low sugar level may have a shorter shelf life than a date fruit with a lower moisture content and a higher sugar level.This is because the date fruit with a higher moisture content will lose water more quickly, reducing its sugar level.By treating the data as time series data, we can consider these temporal relationships, and build a more accurate model for predicting the shelf life of date fruits.The Edge Impulse platform allows users to upload diverse types of preprocessed data, including time series data.This makes it easy to use the platform to build models for time series data, such as the model built in this experiment.
The features of TinyML allowed us to deploy the prediction on the microcontroller of Arduino Nano 33 BLE Sense for the non-destructive and real-time prediction of date fruit quality and shelf life, using a spectral sensor and the Edge Impulse platform.With its low power consumption, TinyML supported the applications for battery-powered devices, making it a fitting solution for achieving the objectives of the current study.Furthermore, the identical cost and efficiency advantages create an opportunity to deploy collaborative TinyML systems at the periphery of the cloud-computing network, making it a suitable choice for our proposed research [45,46].Several ML frameworks support TinyML applications, i.e., TensorFlow Lite for the mobile-based application PyTorch Mobile.and Tensor Flow Lite for Microcontrollers (TFLM).Although it is feasible to construct ML models for mobile devices (by employing TensorFlow Lite) or the web (using TensorFlow.js) using high-level programming languages such as Python or JavaScript, respectively, these languages happen to be more accessible and simpler than C/C++, which is microcontroller friendly and, hence, can be more challenging to learn for users.However, although frameworks such as TensorFlow Lite for Microcontrollers (TFLM) [46] are commonly used for optimizing and compressing neural networks for embedded devices, the adoption rate tends to be slow, due to a set of inimitable challenges unique to embedded ML ecosystem, including data collection, data processing, development, deployment, and monitoring.In response to these challenges, Edge Impulse, an internet-based platform, has been developed, with the aim of streamlining the processes of data collection and deep learning model training, and their subsequent deployment onto embedded and edge computing devices.
A fruit's spectral signature measurement enables a more precise pigmentation analysis, and is more promising for non-destructive fruit maturity stage evaluation [70].The diffuse light reflectance of apple fruit in the 400-800 nm wavelength range was examined by Merzlyak et al. [71].During the storage period, Merzlyak et al. [71] used five apple cultivars, all harvested when fully ripe.They found a significant correlation between various reflectance indices and the chlorophyll content of fruit.However, Zude-Sasse et al. [72] and Zude [73] noted that the correlation between partial transmittance measurements and the maturity stages of apples was stronger, compared to the correlation observed with reflectance measurements in the spectral range spanning 600 to 750 nm.The internal and external quality of citrus fruit can be measured using different wavelength band selections [22].For tomatoes, an LED-based sensor with a 400-758 nm reflectance spectrum is utilized, to estimate the amount of lycopene [74,75].

Conclusions
The current study developed a fast and cost-effective non-destructive technique using TinyML and multispectral sensors to predict/estimate packaged fresh dates' quality parameters and shelf life under modified atmospheres.The results showed that vacuum and MAP packaging methods could extend the shelf life of fresh dates.The multispectral sensor accurately measured the reflectance spectrum of fresh dates.The TinyML prediction models were trained, using the Edge Impulse platform, to predict the essential quality parameters of the date fruit, including the pH, total soluble solids, sugar content, moisture content, tannin content, and shelf life.The TinyML prediction models accurately predicted fresh dates' quality and shelf life.The optimal neural network regression model consisted of the input layer with 20 nodes, two hidden layers with 20 and 12 nodes, and an output layer with one neuron for the target quality parameter or shelf life.The models are deployed on microcontrollers, leveraging edge computing to enable real-time inference and decision-making at the data collection point.The models were validated against the observed laboratory results; the findings indicated a strong correlation and a high accuracy.Adopting TinyML technology in the food supply chain offers numerous benefits, including a reduced inference time, and reduced food waste.TinyML technology is considered a cost-effective and efficient solution for estimating the shelf life of fresh dates.The current study's findings can contribute to advancing sustainable practices in the food and agriculture industry, and reducing food waste.However, it is essential to note that the study's limitation stems from its focus on a specific cultivar of dates (cv.Khalas) as a case study.The generalizability of these findings to other date cultivars may be limited.Therefore, further study is needed to address this limitation and expand knowledge in the field.In addition, integrating TinyML technology with IoT devices and cloud platforms can enhance data collection, analysis, decision-making capabilities, and the remote monitoring of multiple storage facilities or supply chains.
of the flow diagram.

Figure 3
Figure 3 illustrates a schematic representation of the estimation models based on Ti-nyML, devised for the estimation of shelf life and quality parameters in fresh fruits.The 18-channel spectral sensor captures the parameters as reflectance values, which are then transmitted to the Edge Impulse via Arduino CLI, using the acting as the Edge Device.Once trained, Edge Impulse deploys the model back to the Edge device.Consequently, the Nano 33 BLE performs real-time inference to estimate the quality parameters and fruit shelf life.The values of the reflectance readings obtained from samples using the 18-channel spectral sensor were captured, utilizing a 12.5 mA current source drive, and a receiver gain set at 64x.The 18-channel spectral filters were systematically adjusted in increments of 20 nm, spanning from 410 nm to 940 nm, for each specified configuration of current and
of the flow diagram.

Figure 3
Figure 3 illustrates a schematic representation of the estimation models based on Ti-nyML, devised for the estimation of shelf life and quality parameters in fresh fruits.The 18-channel spectral sensor captures the parameters as reflectance values, which are then transmitted to the Edge Impulse via Arduino CLI, using the acting as the Edge Device.Once trained, Edge Impulse deploys the model back to the Edge device.Consequently, the Nano 33 BLE performs real-time inference to estimate the quality parameters and fruit shelf life.The values of the reflectance readings obtained from samples using the 18-channel spectral sensor were captured, utilizing a 12.5 mA current source drive, and a receiver gain set at 64x.The 18-channel spectral filters were systematically adjusted in increments of 20 nm, spanning from 410 nm to 940 nm, for each specified configuration of current and gain outlined above.These spectral measurements were carried out on the exact storage

Figure 3
Figure 3 illustrates a schematic representation of the estimation models based on TinyML, devised for the estimation of shelf life and quality parameters in fresh fruits.The 18-channel spectral sensor captures the parameters as reflectance values, which are then transmitted to the Edge Impulse via Arduino CLI, using the acting as the Edge Device.Once trained, Edge Impulse deploys the model back to the Edge device.Consequently, the Nano 33 BLE performs real-time inference to estimate the quality parameters and fruit shelf life.

Figure 3 .
Figure 3.The TinyML-based prediction models' block diagram uses the spectral sensor to estimate date fruit shelf life and quality parameters.

Figure 3 .
Figure 3.The TinyML-based prediction models' block diagram uses the spectral sensor to estimate date fruit shelf life and quality parameters.

25 Figure 4 .
Figure 4.A sample diagram for the applied neural network architecture.

Figure 5 .
Figure 5.The active unit of artificial neural networks.

Figure 4 .
Figure 4.A sample diagram for the applied neural network architecture.

Figure 4 .
Figure 4.A sample diagram for the applied neural network architecture.

Figure 5 .
Figure 5.The active unit of artificial neural networks.

Figure 5 .
Figure 5.The active unit of artificial neural networks.

Sustainability 2023 ,
15,  x FOR PEER REVIEW 11 of 25 at 5 °C in MAP trays sealed with 10% O2, 20% CO2, and N balance persisted fresh up to 23 DOS, which were counted for 21 days at 22 °C (Figure6H).

Figure 6 .
Figure 6.Impact of the packaging type on the stored fresh date fruits.(A,B) Unsealed trays (Control) at 5 and 22 • C, (C,D) VSBs at 5 and 22 • C, (E,F) modified atmosphere packaging (MAP) trays sealed with 20% CO 2 and N balance, at 5 and 22 • C. (G,H) MAP trays sealed with 10% O 2 , 20% CO 2 , and N balance, at 5 and 22 • C.

Figure 7 .
Figure 7. Impact of the various packaging atmosphere conditions on the shelf life of fresh date fruits at different storage temperatures.

Figure 7 .
Figure 7. Impact of the various packaging atmosphere conditions on the shelf life of fresh date fruits at different storage temperatures.

Figure 8 .
Figure 8.The mean reflectance values at 18 wavelengths for the packaged date fruit samples under modified atmospheres, using the three spectral sensors (As72651, As72652, and AS72653), per storage interval.

Figure 10 .
Figure 10.The plot of the predicted versus observed values of the shelf life (A), pH (B), total soluble solids (C), sugar content (D), moisture content (E), and tannin content (F) of date palm fruits based on data from samples collected during packaging under different modified atmosphere and temperature conditions, showing data points (circles) and the y = x line (solid line).

Figure 10 .
Figure 10.The plot of the predicted versus observed values of the shelf life (A), pH (B), total soluble solids (C), sugar content (D), moisture content (E), and tannin content (F) of date palm fruits based on data from samples collected during packaging under different modified atmosphere and temperature conditions, showing data points (circles) and the y = x line (solid line).

Table 2 .
Mean values of quality attributes of the dates during the ripening stages.

Table 3 .
The sensors' reflectance data of the eighteen bands at different frequencies of light ranging from 410 nm to 940 nm at the different date fruit ripening stages.

Table 4 .
The correlation among the three sensors' reflectance data of the eighteen bands at different frequencies of light, ranging from 410 nm to 940 nm, and the date fruits' shelf life and their quality attributes.* Correlation is significant at the level of 0.01 and * correlation is significant at the level of 0.05. *

Table 5 .
Evaluation metrics for the TinyML model predicting the date fruit shelf life and quality parameters under different packaging types and storage temperatures.