Overview • Dataset Preparation • Training and Data Cleaning • Model Deployment • API integration • Build from Source • Contact
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 |
- 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: 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, reaching79.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.
The model is deployed to HuggingFace Spaces. The implementation can be found in deployment folder or here.
The deployed model is integrated with HuggingFace API here in GitHub Pages Website. Implementation and other details can be found in docs folder.
git clone https://github.com/zzarif/Pasta-Shape-Recognizer.git
cd Pasta-Shape-Recognizer/
- 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.
virtualenv --no-site-packages venv
source venv/Scripts/activate
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
).
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.
pip3 install fastai fastbook nbdev gradio