/mlzoomcamp-capstone1

MLZoomcamp capstone-1

Primary LanguageJupyter Notebook

DataTalksClub Kitchenware Classification Competition

Using Convolution Neural Network (CNN) with data augmentation techniques and transfer learning to classifiy kitchenware images to 6 classes:

  • cups
  • glasses
  • plates
  • spoons
  • forks
  • knives

Dataset

This project uses a dataset with more than 9300 images.

Overview

This dataset contains images of different kitchenware. https://www.kaggle.com/competitions/kitchenware-classification/data

Files

  • train.csv - the training set (Image IDs and classes)
  • test.csv - the test set (Just image IDs)
  • sample_submission.csv - a sample submission file in the correct format
  • images/ - the images in the JPEG format

Contents of the folder

tree

Exploratory Data Analysis

See the Kitchenware_EDA.ipynb for this task.

Image sizes statistics

sizes
The images have various and varied sizes, ranging from 39 Kilopixels to 976 Kilopixels, also more than half of the images are concentrated at 750 Kpixels. This is bad news since the tensors must imperatively have the same size.

The width to height ratio (lx/ly)

lxy_ratio
Most images are vertical.

By width (lx)

width
The width varies from 233 to 1000, and it is concentrated on 1000.

By height (ly)

heigth
The height varies from 174 to 1000, and it is concentrated on 750.

Labels statistics

labels
Not all labels are representend equaly.

Models

See the kaggle_zoomcamp_competition_1.ipynb and kaggle_zoomcamp_competition_2.ipynb for this task.

Summary of the models ✖️: without_ | ✔️: with_

Model Data Augmentation Transfer Learning Epochs Losss Accuracy %
model 1 ✖️ ✖️ 25 0.8718 67.0266
model 2 ✖️ ✖️ 10 1.0553 66.7387
model 3 ✖️ ✖️ 10 0.7926 71.7063
model 4 ✔️ ✖️ 25 0.7995 68.8265
model 5 ✔️ vgg16 ✔️ 25 0.7966 92.1526
model 6 ✔️ vgg 16 ✔️ 10 ✖️ ✖️
model 7 ✔️ vgg 16 ✔️ 10 0.4065 91.3607
model 8 ✔️ efficientnet0 ✔️ 10 0.4896 91.2887
model 9 ✔️ efficientnet0 ✔️ 10 0.4793 90.9287
model 10 ✔️ efficientnetB7 ✔️ 10 0.2978 92.0806
model 10 bis ✔️ efficientnetB7 ✔️ 10 0.2990 93.5925
model 11 ✔️ efficientnetB7 ✔️ 20 0.2830 93.9525
model 12 ✔️ efficientnetB7 ✔️ 25 0.2534 93.6645
model 13 ✔️ resnet50 ✔️ 10 1.5776 39.7408

I tried a multitude of models first, without data augmentation or transfer learning, it had a bad impact and I couldn't exceed an accuracy of 72%. Then, thanks to data augmentation and transfer learning, I was able to increase accuracy. the best accuracy was obtained with model 12 with a lost function which dropped to 0.2534 thanks to transfer learning via the base model EfficientNetB7 as shown in the graph below. best-model
We see that the test loss continues to drop, while the test accuracy continues to increase. I stopped at 25 epochs but I think the model can give better results by increasing the number of epochs, especially since the overfitting is minimal.
Note: The ResNet50 was the worst model.

Deployment of model

I am using Streamlit on linux ubuntu, in order to deploy the model. To deploy this model with Sreamlit, please use:

pipenv run streamlit run predict.py

Virtual Environment/venv

I used pipenv for the virtual environment. In order to use the same venv as me, do use:

pip install pipenv

To replicate the environment, on your command line, use

pipenv install tensorflow streamlit efficientnet

Note: I don't have a GPU installed on my laptop for this I only installed tensorflow without GPU configuration. If you have a GPU, try to configure tensorflow with NVIDIA, CUDA and cuDNN.

Docker

Note:
To perform the following steps you should logon to your DockerHub Account ( Login & Password)

I have built the model and pushed it to dajebbar/kitchenware-model:v.1.0. To use it just

docker pull dajebbar/kitchenware-model:v.1.0

Or in order to take the model from the docker container I built, just replace

FROM python:3.9-slim 

#with 

FROM dajebbar/kitchenware-model:v.1.0 

in the dockerfile.

If you choose to build a docker file locally instead, here are the steps to do so:

  1. Create a Dockerfile as such:
FROM python:3.9-slim

ENV PYTHONUNBUFFERED=TRUE

RUN pip --no-cache-dir install pipenv

WORKDIR /app

COPY ["Pipfile", "Pipfile.lock", "./"]

RUN pipenv install --deploy --system && rm -rf /root/.cache

COPY ["predict.py", "kitchenwareModel.h5", "banner.png", "./"]

EXPOSE 8501

ENTRYPOINT [ "streamlit", "run" ]

CMD ["predict.py"]

This allows us to install python, run pipenv and its dependencies, run our predict script and our model itself and deploys our model using streamlit.

Similarly, you can just use the dockerfile in this repository.

  1. Build the Docker Container with :
 docker build -t kitchenware-model .
  1. Run the Docker container with:
Docker run --rm --name kitchenware -p 8501:8501 kitchenware-model
  1. tag the docker container with:
docker tag kitchenware-model dajebbar/kitchenware-model:v.1.0
  1. Push it to Docker registry with :
docker push dajebbar/kitchenware-model:v.1.0

Test the project

Here are some screen shots showing the interaction with the application, which represents the final product. cmd cup fork plate

A quick demo of app can be found here.

Want to Contribute?

  • Fork 🍴 the repository and send PRs.
  • Do ⭐ this repository if you like the content.

Connect with me:

https://ma.linkedin.com/in/abdeljebbar-boubekri-656b30192 https://www.twitter.com/marokart/ https://www.kaggle.com/dajebbar