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
This project uses a dataset with more than 9300
images.
This dataset contains images of different kitchenware. https://www.kaggle.com/competitions/kitchenware-classification/data
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 formatimages/
- the images in the JPEG format
See the Kitchenware_EDA.ipynb for this task.
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 varies from 233 to 1000, and it is concentrated on 1000.
The height varies from 174 to 1000, and it is concentrated on 750.
Not all labels are representend equaly.
See the kaggle_zoomcamp_competition_1.ipynb and kaggle_zoomcamp_competition_2.ipynb for this task.
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.
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.
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
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.
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:
- 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.
- Build the Docker Container with :
docker build -t kitchenware-model .
- Run the Docker container with:
Docker run --rm --name kitchenware -p 8501:8501 kitchenware-model
- tag the docker container with:
docker tag kitchenware-model dajebbar/kitchenware-model:v.1.0
- Push it to Docker registry with :
docker push dajebbar/kitchenware-model:v.1.0
Here are some screen shots showing the interaction with the application, which represents the final product.
A quick demo of app can be found here.
- Fork 🍴 the repository and send PRs.
- Do ⭐ this repository if you like the content.
Connect with me: