Classifying pasta types with Convolutional Neural Networks (CNNs)
Master’s Degree in Data Science — University of Milano-Bicocca (A.Y. 2023/2024)
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.
- 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.
- data/ # (see Data & Model section for download)
- models/pasta_model_M4.4.keras
- notebooks/pasta_classification_notebook.ipynb
- slides_pasta_classification.pdf
- README.md
-
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.
-
Model iterations
- M1: Baseline CNN + BatchNorm + Dropout, RMSprop.
- M2: + Data Augmentation.
- M3: + L2 Regularization.
- M4: Switch to Adam → final model saved as
pasta_model_M4.4.keras.
-
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.
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
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")
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).
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).
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.
Slides: docs/slides_pasta_classification.pdf
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!