Trusted Scholarly Publisher
Serving Researchers Since 2012

From Fresh to Waste: Deep Learning-Driven Food Spoilage Classification Using CNN

DOI : 10.17577/IJERTCONV14IS010061
Download Full-Text PDF Cite this Publication

Text Only Version

From Fresh to Waste: Deep Learning-Driven Food Spoilage Classification Using CNN

Shreya M D

Student, St Joseph Engineering College, Managalore Dr. Hareesh B

Head of Department, Assistant Professor, St Joseph Engineering College, Managalore

Abstract – The majority of present detection techniques are time- consuming, laboratory-based, and inaccessible to the general population, even if they do exist. A significant portion of the world's food waste comes from the deterioration of loose fruits and vegetables. Furthermore, the majority of contemporary AI solutions focus on packaged foods that have expiration dates printed on them, ignoring the real challenge of visually assessing unpacked goods. In order to address this need, this study proposes a deep learning-based technique dubbed "From Fresh to Waste: Deep Learning-Driven Food Spoilage Classification Using CNN". Using image data, a Convolutional Neural Network (CNN) model was created to differentiate between fresh or rotten non-packed fruits and vegetables with 96.76% accuracy. The system recognizes indicators of deterioration such as bruising, discoloration, and fungal development. Users receive practical recommendations after categorization: use it, donate it, or use it as fertilizer. This clever system helps people reduce food waste in their homes and encourages eco-friendly eating. By combining artificial intelligence with caring for the environment, The research promotes the rapid and efficient detection of contaminated food in accordance with the objectives of a circular economy.

Keywords – Food spoilage Prediction, non-packed food, fruits and vegetables, convolutional neural network, image classification, food waste reduction, sustainable agriculture.

  1. INTRODUCTION

    Food spoilage is a serious world problem that contributes significantly to economic loss, environmental contamination, and expanding food insecurity. Of the different types of perishable goods, unpacked food like fruits and vegetables is especially prone to speedy spoilage through microbial growth, physical injury, and variations in environmental conditions such as temperature and humidity during transportation and storage. The conventional techniques of spoilage identification, such as physical examination, chemical or microbiological testing, are generally time-consuming, labor-intensive, and unavailable for everyday consumer application.

    With advancements in Artificial Intelligence (AI) and Computer Vision, smart systems are now capable of performing high-efficiency, real-time visual inspections. In particular, Convolutional Neural Networks (CNNs) have demonstrated exceptional performance in image classification by detecting subtle visual indicators such as discoloration, mold, bruising, and texture changesall of which are key signs of food spoilage. However, most existing AI-based solutions

    are primarily designed for packaged food products, relying heavily on printed expiration dates to estimate freshness. This creates a significant gap in addressing unpackaged food items, which lack such metadata and require more sophisticated visual analysis techniques for spoilage detection.

    To fill this gap, this study introduces a CNN-based image classification system that can automatically identify whether non-packed fruits and vegetables are fresh or spoiled on the basis

    of visual information. After establishing the condition of the food, the system suggests context-aware actions:

    • Fresh items can be consumed ("Use It") or donated ("Donate

    It") to reduce waste and support food redistribution initiatives.

  2. LIERATURE SURVEY

    This research [1] employs a CNN-trained model from an image dataset of Kaggle for real-time identification of spoiled fruits. The system consists of a detection system, microcontrollers, and alert systems. It notifies users via SMS or an app and attained accuracy of 95%, with the goal of reducing food waste.

    In the paper [2], CNNs for visual classification were compared with RNNs (LSTM) for time-series spoilage risk. The role of CNNs was seen in detecting visual spoilage more efficiently, whereas environmental data patterns were dealt with by RNNs. IoT integration and Explainable (XAI) was suggested. This research [3] on post-harvest spoilage prediction in apples utilizes GANs to produce synthetic VNIR images from RGB, and Mask R-CNN for spoilage segmentation. It attained F1- scores of 58.861 (rot), 40.968 (fungus), and 94.800 (overall). This approach shows promise for high-accuracy spoilage prediction in apples using state-of-the-art image generation.

    The work [4] suggests a CNNIoTK-Means clustering and 3D visual feature reconstruction hybrid system for spoilage detection. It highlights spectral and grayscale pheromone analysis. However, it is too complex for industrial application and lacks user-level deployment capabilities.

    This research [5] combines CNN with IoT sensors (temperature, humidity, gas) to identify spoilage levels. Hardware control is achieved using a Raspberry Pi and Arduino, based on the Fruit360 dataset. Users are alerted via a cloud-based application to aid in shelf life extension and waste reduction.

    In this paper [6], it is estimated that 1.3 billion tons of food is lost annually through spoilage, making it imperative to predict shelf life with high accuracy. This review discusses different models adopted for tracking food quality, outlining their composition, use, and mathematical foundation. It also reviews their application in forecasting freshness, shelf life, maturity, and damage. The research further proposes employing multivariate analysis and real-time monitoring to save food and improve preservation.

    This study [7] focuses on improving postharvest food quality control using deep learning and computer vision techniques. It introduces a method that combines Generative Adversarial Networks (Pix2PixHD) and Convolutional Neural Networks (Mask R-CNN) to analyze artificially generated VNIR images of apples for early decay and fungal detection. The models achieved high accuracy in segmenting decayed and fungal zones, with promising F1-scores. The method's potential for real-time agricultural monitoring was demonstrated using a a one-of-a-kind collection of apple photos in RGB and VNIR formats for training and testing.

    This review [8] highlights the effectiveness of hyperspectral imaging (HSI) as a fast, nondestructive method for detecting microbial, chemical, and physical contaminants in food. It summarizes two decades of research, emphasizing the challenges of complex food matrices and how machine learning models help improve detection accuracy. The paper compares HSI with traditional culture-based methods, noting HSI's advantages in speed and minimal sample preparation. It also details modeling techniques used to overcome background noise and data complexity in detecting foodborne pathogens like bacteria, fungi, and viruses.

    In this Work [9] highlights the need to monitor perishable food products to ascertain their quality and safety prior to consumption. It suggests a smart system that involves the integration of Internet of Things (IoT) technology and Machine Learning (ML) technology to remotely monitor environmental conditions that influence food. Through the integration of IoT sensors and ML algorithms, The system is capable of properly monitoring and guaranteeing food quality, which leads to less waste and spoilage. Such an approach provides a sound solution for intelligent food preservation and safety management.

    This study [10] presents a real-time food spoilage detection system based on IoT that integrates sensor data with machine learnin to track parameters such as temperature, humidity, and gas concentration. The system facilitates the early detection of spoilage with a high performance rate of 0.92 and minimizes food waste considerably. It is a proactive and sustainable method of managing food quality throughout the supply chain.

    This paper [11] suggests an AI-based approach that employs cutting-edge computer vision models like CNN, ResNet50, VGG16, and InceptionV3 to determine the freshness of fruits and vegetables. By automating quality evaluation, it enhances food safety, reduces waste, and replaces traditional, subjective methods with accurate and efficient detection.

    This review [12] highlights the role of machine learning in enhancing food safety and HACCP monitoring for animal- source foods, enabling real-time risk assessment through advanced, non-destructive techniques. It emphasizes the

    potential of AI to automate inspections and improve predictive accuracy in food quality control.

    This study [13] introduces a fusion network model combining TMKFF with 1DCNN-LSTM to improve gas concentration prediction using a portable electronic nose. The model significantly outperforms traditional CNN and LSTM, achieving high R² values and low error rates, making it effective for detecting gases like SO, NO, and CO in complex environments.

    This paper [14] presents a deep learning approach using an electronic nose and GMEGAN-generated data to predict potato decay levels, achieving up to 90.28% accuracy with feature-optimized CNN models. The method enhances classification performance and robustness, offering areliable solution for non-invasive agricultural quality assessment.

    This work [15] proposes a CNN-Attention and SMA-GPR hybrid model for accurately predicting the remaining useful life (RUL) of lithium-ion batteries, achieving prediction errors within 1% across various battery types and aging conditions. The approach effectively handles data nonlinearity and capacity regeneration for improved safety and maintenance.

    Ref.No

    Methodology

    performance

    [1]

    CNN model trained on Kaggle fruit images with real-time detection,

    microcontrollers, and alert system

    Accuracy: 95%

    [2]

    Comparison of CNN (visual)and

    RNN (LSTM for environmental data), with XAI and IoT integration.

    CNN for

    visual; RNN for time-series

    [3]

    GAN (VNIR image generation) + Mask R-CNN for spoilage segmentation in apples.

    F1-score: 94.8%

    [4]

    Hybrid: CNN + IoT + K-Means

    + 3D feature reconstruction;

    industrial-grade spectral analysis

    Complex detection;

    lacks user- level features

    [7]

    GAN (Pix2PixHD) + Mask R- CNN on RGB and VNIR for fungal zone segmentation in apples

    High F1- score; potential for real-time

    monitoring

    [10]

    IoT + ML system analyzing gas/temp/humidity in real time

    Accuracy: 92%

    [13]

    TMKFF + 1D CNN-LSTM for

    predicting gas concentrations via e-nose

    High R² values; outperforms basic

    CNN/LSTM

    [14]

    CNN with e-nose data and

    GMEGAN for potato decay prediction

    Accuracy: 90.28%

    [15]

    CNN-Attention + SMA-GPR hybrid for battery RUL prediction

    Error < 1%; non-food domain

    [5]

    CNN + IoT sensors (gas, temp, humidity) with Raspberry Pi,

    Arduino, and Fruit360 dataset

    Real-time alerts

  3. METHODOLOGY

    This paper suggests a system based on deep learning that classifies unpacked fruits and vegetables as fresh or spoiled using Convolutional Neural Networks (CNNs). The complete methodology includes several key steps: data preparation, preprocessing, model design, training, evaluation, and actionable recommendation. Dataset Collection

    1. Dataset

      A specialized dataset was developed by gathering and categorizing images of different non-packed fruits and vegetables into two classes: Fresh and Spoiled. The dataset was organized into train/ and test/ directories, with subdirectories having the class labels as their names. All images are real-world samples taken under different lighting and background conditions to enhance the generalizability.

    2. Data Preprocessing

      images were resized to 150×150 pixels and normalized using an ImageDataGenerator by rescaling pixel values to the range 0.0 to 1.0. Standardization enables the model to learn more effectively. The dataset was also augmented, when necessary, using techniques such as rotation, zooming, and flipping to minimize overfitting

    3. CNN Model Architecture

      The CNN model was built using the Keras Sequential API. It includes two Conv2D layers with ReLU activation and MaxPooling for effective feature extraction, followed by a Flatten layer to convert the 2D feature maps into a 1D vector. A Dense layer with ReLU activation is then used to process the extracted features, and a final Dense layer with Softmax activation performs multi-class classification.

    4. Model Compilation and Training

      The model was trained with the Adam optimizer and categorical cross-entropy loss function, appropriate for multi-class classification. The model was trained for 10 epochs with validation on the test set to track accuracy and loss.

    5. Model Evaluation

      Once training was completed, the model was tested with the unseen test data. The system had high classification accuracy, and performance measures like precision, recall, F1-score, and confusion matrix were computed to cross-check the results further..

    6. Post-Classification Action Recommendation

    Once the classification process is complete, the system offers actionable suggestions based on the condition of the food. If the product is fresh, consumers are encouraged to either use it ("Use It") or donate it ("Donate It") to help minimize food waste and support community food programs. For spoiled items, the system suggests composting ("Use as Manure") as an environmentally friendly disposal method. These smart suggestions not only help the model identify spoilage but also promote sustainable and socially responsible choices.

  4. RESULTS AND DISCUSSION

    The Convolutional Neural Network (CNN) model trained in this research was trained and tested using a dataset of non- packed fruits and vegetables, which were classified as fresh and spoiled classes. The model attained a test accuracy of 96.76% after 10 epochs of training, proving highly reliable in discriminating between spoiled and fresh produce using visual features. The learning process of the model, monitored via training and validation accuracy curves, was stable and improved with good convergence, suggesting reliable generalization and little overfitting.

    A confusion matrix was also used to further evaluate performance, and it was found that most test samples were classified correctly by the model while only a minority of misclassifications occurred, mostly due to images taken under low lighting, overlapping products, or obscure spoilage indicators. The classification report indicated high precision, recall, and F1-scores, especially for the "fresh" class, indicating that the CNN had succeeded in extracting meaningful visual features like discoloration, bruising, and presence of fungi. These findings verify the efficacy of the CNN-based method in real-life applications where conventional spoilage detection fails. In contrast to manual checks or chemical analysis, themodel offers a quicker, automated, and user-friendly solution. Furthermore, incorporating post-classification actions such as "Use It," "Donate It," or "Use as Manure" presents pragmatic value by leading users toward sustainable and responsible food handling practices.

    In total, the system not only offers top-notch classification performance but also makes a valuable contribution to food wastage mitigation and circular economy objectives. In terms of usability, the model introduced can be implemented in real- time application scenarios like mobile apps or intelligent kitchens to enable consumers to make informed choices about food quality. The efficiency of the CNN architecture guarantees low computational cost, making it suitable for embedded or edge devices.

    In addition, incorporating user behavior after classification (e.g., use, donate, or compost) provides relevant context and resonates with worldwide sustainability initiatives, particularly food reduction at the consumer level.

  5. CONCLUSION

In this study, a Convolutional Neural Network (CNN) model was created and trained to predict spoilage in unpacked food products, namely fruits and vegetables like apples and okra. The model efficiently distinguished between fresh and rotten classes of images based on image features obtained via deep learning. Color-based feature extraction and visualization methods, such as scatter plots and pie charts, were also employed to identify the visual attributes of spoilage and distribution in the dataset.

The experimental results clearly show that the designed CNN model attains high accuracy in real-time food spoilage

detection, confirming its validity in real-world applications. This method can prove highly effective in minimizing food waste by enabling users to take well-informed decisions whether to consume, donate, or compost perishable foods. The system is a step towards smart food monitoring solutions and shows promise for implementation in mobile or IoT-based applications for real-world deployment.

Subsequent work can include increasing the dataset, adding more food categories, and fine-tuning the model with complex architectures or hybrid approaches to enhance accuracy and generalizability in diverse environments.

V. REFERENCES

  1. Maruthi,L,Laxmi,V Durga Devi. Monitoring Perishable Foods Using Machine Learning and Internet of Things. 2023 Second International Conference IEEE, 2023, pp. 158487, DOI.org(Crossref), ICAISS on Augmented Intelligence and Sustainable Systems. doi.org/10.1109/ICAISS58487.2023.10250646.

  2. Aswathi Soni, Yash Dixit. Hyperspectral Imaging and Machine Learning in Food Microbiology: Developments and Challenges in Detection of Bacterial, Fungal, and Viral Contaminants. Comprehensive Reviews in Food Science and Food Safety, vol. 21, no. 4, Jul. 2022, pp. 371745. DOI.org (Crossref),

    doi.org/10.1111/1541-4337.12983.

  3. Anusha, Kolli, kona uma. IoT Based Food Spoilage Detection Using Machine Learning Techniques. 2024 International Conference on IEEE, Advances in Computing, Communication, and Applied Informatics (ACCAI), 2024, pp.17..DOI.org(Crossref), doi.org/10.1109/ACCAI61061.2024.10602355.

  4. Rahman, Nabila, Mahira Arefin. Enhancing the Accuracy of Fruit Freshness Detection by Utilizing Transfer Learning and Customizing 2024 IEEE 3rd International Conference on Computing and Machine Intelligence (ICMI), IEEE, 2024, pp. 1-6.DOI.org(Crossref),

    Conventional Neural Network (CNN).

    doi.org/10.1109/ICMI60790.2024.10585689.

  5. Haixia Ding, Feature Extraction Algorithm of Food Spoilage Early Warning Data Based on Machine Learning and Internet of Things. Journal of Testing and Evaluation, vol. 52, no. 3, May 2024, pp. 158597. DOI.org (Crossref), doi.org/10.1520/JTE20230066.

  6. paper "Deep Learning in Precision Agriculture: Artificially Generated VNIR Images Segmentation for Early Postharvest Decay" by Islomjon Shukhratov and Nikita Stasenko uses deep learning to segment images generated by artificial VNIR for the purpose of detecting early postharvest decay. Prediction in Apples. Entropy, vol. 25, no.7,Jun.2023,p.987.DOI.org(Crossref), doi.org/10.3390/e25070987.

  7. Jilei Yang, Xuefeng Hu AI-Enabled Portable E-Nose Regression Predicting Harmful Molecules in a Gas Mixture. ACS Sensors, vol. 9, no. 6, Jun. 2024, pp. 292534.DOI.org(Crossref), doi.org/10.1021/acssensors.4c00050.

  8. Nikita Stasenko, Maxim Savino. Deep Learning for Postharvest Decay Prediction in Apples. IECON 2021 IEEE Industrial Electronics Society's 47th Annual Conference, IEEE, 2021, pp. 16. DOI.org (Crossref).

    doi.org/10.1109/IECON48115.2021.9589498.

  9. Haohan Ding ,David I. Wilson. Application of Convolutional Neural Networks and Recurrent Neural Networks in Food Safety. Foods, vol. 14, no. 2, Jan. 2025, p.247.DOI.org(Crossref), doi.org/10.3390/foods14020247.

  10. Sonwani, Ekta An Artificial Intelligence Approach Toward Food Spoilage Detection and Analysis. Frontiers in Public Health, vol. 9, Jan. 2022, p. 816226.DOI.org(Crossref), https://doi.org/10.3389/fpubh.2021.816226.

  11. Nirmaladevi, J., and V. R. Kiruthika. "Food Spoilage Alert System by Deploying Deep Learning Model." International Journal of Health Sciences, vol. 6, no. S1, 2022, pp. 8565-8575, doi:10.53730/ijhs.v6nS1.6874.

  12. Xudong Ren,Yadoung Wang A CNN-Based E-Nose Using Time Series Features for Food Freshness Classification. IEEE Sensors Journal, vol. 23, no. 6, Mar. 2023,pp.602738.DOI.org(Crossref), doi.org/10.1109/JSEN.2023.3241842.

  13. Onyeaka, Helen. Artificial Intelligence in Food System: Innovative Approach to Minimizing Food Spoilage and Food Waste. Journal of Agriculture and Food Research, vol. 21, Jun. 2025, p. 101895. DOI.org (Crossref), doi.org/10.1016/j.jafr.2025.101895.

  14. Jiayu Mai.Prediction of Potato Rot Level by Using Electronic Nose Based on Data Augmentation and Channel Attention Conditional Convolutional Neural Networks. Chemosensors, vol. 12, no. 12, Dec. 2024, p. 275.DOI.org(Crossref), doi.org/10.3390/chemosensors12120275.

  15. Shehzad, Khuram. Predictive AI Models for Food Spoilage and Shelf- Life Estimation. Global Trends in Science and Technology, vol. 1, no. 1, 2025, pp. 75

94.DOI.org(Crossref),doi.org/10.70445/gtst.1.1.2025.75-94.