Nothing Special   »   [go: up one dir, main page]

Skip to content

zzarif/Pasta-Shape-Recognizer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Pasta Shape Recognizer

An image recognizer that recognizes 20 different shapes of Pasta.

OverviewDataset PreparationTraining and Data CleaningModel DeploymentAPI integrationBuild from SourceContact

📋 Overview

An image classification model that utilizes data collection, augmentation, model training, cleaning, deployment and API integration to classify 20 different types of pasta shapes. The types are following:

1. Spaghetti 2. Fettuccine 3. Penne 4. Rigatoni 5. Fusilli
6. Farfalle 7. Linguine 8. Tagliatelle 9. Lasagna 10. Ravioli
11. Tortellini 12. Orecchiette 13. Conchiglie 14. Rotini 15. Bucatini
16. Cannelloni 17. Macaroni 18. Orzo 19. Cavatappi 20. Gemelli

🗂️ Dataset Preparation

  • Data Collection: The code collects images for each pasta shape by searching for them using the DuckDuckGo search engine and downloading the images to corresponding folders in the data directory. It then verifies the downloaded images and removes any failed downloads.
  • DataLoader: The code creates a DataBlock, which defines the structure of the data, including the image and label blocks, data splitting strategy, and image transformations. It then creates a DataLoader (dls) using the DataBlock, specifying the path to the data and the batch size.
  • Data Augmentation: The code applies data augmentation techniques to the images using RandomResizedCrop, which randomly crops and resizes the images to a specified size (224x224) with a minimum scaling factor of 0.5. Additional augmentation transforms are applied using aug_transforms() to further enhance the variety of the training data.

The final dataset has 7.3K+ images of 20 different pasta shapes. Details can be found in data_prep.ipynb

💪 Training and Data Cleaning

  • Training: The model is trained using a ResNet34 architecture with a 90-10 train-validation split, and fine-tuned for 5 epochs initially, achieving ~75% accuracy. After data cleaning, the model is fine-tuned for 2 more epochs, reaching 79.5% accuracy, and then further fine-tuned for 2 epochs, achieving a satisfactory accuracy of ~85.6%.
  • Data Cleaning: The ImageClassifierCleaner is used to identify and remove irrelevant data points from the dataset. The data points that need to be relabeled are moved to the correct directories, ensuring the dataset's integrity and improving the model's performance.

Details can be found in training_and_data_cleaning.ipynb. Multiple models from timm (ResNet50, EfficientNet-B0, MobileNetV3-Large) were fine-tuned as well. Details of it can be found in this notebook. ResNet34 had the best result and this will be deployed in the next step.

Confusion Matrix

Confusion matrix for the final version of fine-tuned ResNet34 model

🤗 Model Deployment

The model is deployed to HuggingFace Spaces. The implementation can be found in deployment folder or here.

Classifying fusilli pasta

Pasta-Shape-Recognizer

Classifying spaghetti pasta

Pasta-Shape-Recognizer

Classifying conchiglie pasta

Pasta-Shape-Recognizer

🌐 API integration with GitHub Pages

The deployed model is integrated with HuggingFace API here in GitHub Pages Website. Implementation and other details can be found in docs folder.

Classifying fusilli pasta via API

Pasta-Shape-Recognizer

⚙️ Build from Source

Clone the repo

git clone https://github.com/zzarif/Pasta-Shape-Recognizer.git
cd Pasta-Shape-Recognizer/

Install CUDA Toolkit

  • Go to the NVIDIA CUDA Toolkit download page: https://developer.nvidia.com/cuda-downloads
  • Select "Windows" as the operating system and choose the appropriate version and installer type.
  • Download and run the installer, following the installation instructions.

Initialize and activate virtual environment

virtualenv --no-site-packages venv
source venv/Scripts/activate

Install PyTorch with CUDA support

Run the following command to install PyTorch with CUDA support using pip3:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121

Note: Replace cu121 with the appropriate CUDA version tag that matches your installed CUDA version (e.g., cu121 for CUDA 12.1).

Verify the installation

Run the following code to check if PyTorch is using the GPU:

import torch
print(torch.cuda.is_available())

If the output is True, then PyTorch is successfully set up to use the GPU. torch.cuda.get_device_name(0) should also show your GPU config.

Install Dependencies

pip3 install fastai fastbook nbdev gradio

✉️ Contact

LinkedIn Mail