Skip to content

GaiaRighetti00/deep-learning-pasta-classification

Repository files navigation

🍝 Guess the Pasta — Deep Learning with CNNs

Python TensorFlow Keras Jupyter License: MIT

Classifying pasta types with Convolutional Neural Networks (CNNs)
Master’s Degree in Data Science — University of Milano-Bicocca (A.Y. 2023/2024)


📖 Overview

This project applies deep learning to the (delicious) challenge of recognizing pasta varieties from images.
We start from a small, noisy dataset and iteratively improve the model with data augmentation, regularization, and optimizer tuning to boost generalization and stability.


🎯 Goals

  • Build and train CNNs to classify pasta images.
  • Group images into short, long, filled, layered pasta.
  • Mitigate small-dataset issues using augmentation & L2 regularization.
  • Compare optimizers (RMSprop vs Adam) and report findings.

📂 Repository Structure

  • data/ # (see Data & Model section for download)
  • models/pasta_model_M4.4.keras
  • notebooks/pasta_classification_notebook.ipynb
  • slides_pasta_classification.pdf
  • README.md

🧭 Method & Models

  1. Dataset evolution

    • Start: 12 classes (~30 img/class) → cleaned duplicates/errors.
    • Reduced to 10 classes due to look-alike pairs (e.g., tagliatelle vs fettuccine).
    • Final consolidation into 4 macro-classes: short, long, filled, layered.
  2. Model iterations

    • M1: Baseline CNN + BatchNorm + Dropout, RMSprop.
    • M2: + Data Augmentation.
    • M3: + L2 Regularization.
    • M4: Switch to Adamfinal model saved as pasta_model_M4.4.keras.
  3. Key observations

    • Validation accuracy rises with augmentation & regularization.
    • Long pasta is hardest (shape changes; sauces/packaging can occlude pasta).
    • Data quality & size are the main bottlenecks.

Environment

python -m venv .venv source .venv/bin/activate # Windows: .venv\Scripts\activate pip install -r requirements.txt

If requirements.txt is missing, install minimally: pip install tensorflow keras numpy pandas matplotlib scikit-learn pillow jupyter


Run

Open the notebook and follow the cells: jupyter notebook notebooks/pasta_classification_notebook.ipynb

To load the pretrained model: from tensorflow import keras model = keras.models.load_model("models/pasta_model_M4.4.keras")


📦 Data & Model (large files)

GitHub’s web upload blocks files >100 MB. We provide large assets as Release attachments. Download model: models/pasta_model_M4.4.keras Download datasets (archives): data/raw/pasta_4.zip, pasta_10.zip, pasta_12.zip How to set up: Go to Releases → Latest → Assets and download the files. Place them under the paths shown above (create folders if needed).


📊 Results (high level)

Initial small dataset → ~0.20 validation accuracy. Augmentation + L2 reduced overfitting and improved stability. Misclassifications often occurred on long pasta and occluded images (sauces, packaging).


🚀 Future Work

Add more high-quality, standardized images per class. Distinguish raw vs cooked pasta explicitly. Try transfer learning (ResNet, EfficientNet, MobileNetV3). Add Grad-CAM visualizations for interpretability.


📑 Documentation

Slides: docs/slides_pasta_classification.pdf


⚖️ License

This repository is released under the MIT License. Data are used for educational purposes; check original sources’ terms before redistribution

✨ From spaghetti to lasagne, let deep learning guess your pasta!

About

Deep learning project for pasta image classification using CNNs, data augmentation, and regularization.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors