This repo explores simple CNNs from Keras applications, as well as larger and more powerful deep learning models such as image transformers to classify kitchenware and cutlery. Here we see exploratory data analysis (EDA), tuning different ML models, and hyperparameter search with Keras Tuner.
- Model is submitted to Kaggle as well as having a local and cloud deploy via BentoML
Dataset comes from Kitchenware Classification Kaggle competition
Includes of glasses, cups, plates, forks, knives and spoons.
If Kaggle CLI is configured, download and unzip with make dataset
- Python
- Anaconda
- Pipenv
- CUDA
- Pandas, NumPy
- Tensorflow/Keras
- CNN models:
- ConvNext
- ConvNextV2
- EfficientNet
- Image transformer models:
- MaxViT
- DaViT
- CAiT
- DEiT*
- BEiT**
- CNN models:
- BentoML
- Docker
- AWS ECR
- AWS ECS
* Final model used ** Used for Kaggle submission
Starter notebook keras-starter.ipynb from this GitHub repo for DataTalks.Club ML Zoomcamp.
- Setup environment with Pipenv/Anaconda
- Setup GPU support with CUDA toolkit in WSL2 (Ubuntu)
- EDA
- Visualize images
- Visualize class imbalance
- Visualize image sizes
- Hypothesis for image augmentation
- Prepare Dataset (80/20 train/validation split)
- Explore different models for fine-tuning
- Explore CNN models from Keras applications
- Explore larger CNN models and Image Transformer models from GitHub repo
See Setup instructions. Install Git LFS before pulling repo to pull model and weights.
Refer to Makefile.
0. (Optional) run make train to train model if you did not pull use Git LFS. Will take very long time if GPU is not configured.
- Run
make runto build BentoML Bento (Docker image and webserver/API) for model and run locally.- Can also run
make serveto serve model from Python
- Can also run
- After running Bento:
- Test from script:
- Evaluate with the image in
testing/withmake test
- Evaluate with the image in
- Test from web browser:
- Open http://localhost:3000/
- Select the first option, to POST
- Hit
Try it outin the top right - In the drop down box, change
application/postscripttoimage/jpeg - Upload the file
testing/0966.jpgor any other file from the dataset. - Hit
Execute, wait for your result
- Test from script:
Run make clean to delete anything generated (including model searches and Bentos)
See Walkthrough to see screenshots and step-by-step.
Note: As a Tensorflow image classification model, this is fairly large (~2.5GB image) and uses a decent amount of resources (~4GB memory).
Must be done after building Bento. This pulls from your AWS default profile. Can adjust settings in Makefile.
Run make aws to make ECR repo, push Docker image, create ECS cluster and service with cloudformation. May take 10 minutes.
- What this does:
- Creates AWS ECR repo in your local AWS region (
make repo) - Publishes docker image to ECR repo by tagging local Bento image and pushing
- Deploys 3 AWS Cloudformation stacks:
- Creates VPC and networking
- Creates ECS Cluster and service
- Creates ECS task definition to be run
- Creates AWS ECR repo in your local AWS region (
- Unfortunately, I could not figure this out in time, so this step is manual. The Walkthrough shows this with pictures.
- Navigate to the AWS console
- Navigate to AWS ECS from the top bar.
- Click on Amazon ECS > Task Definitions on the left navigation bar.
- Should see Task Definition like 'kitchenware-classification-app-ECSTaskDefinition'. Click on it.
- There should only be one Task Definition revision. Click on it or the latest.
- Click Actions > Run Task from the drop down menu. Make the following selections:
Launch type: FARGATEOperating system family: LinuxPlatform version: LATESTNumber of tasks: 1Cluster VPC: choose the one created bymake aws- On the Cloudformation console, the stack 'kitchenware-classification-vpc' should show the VPC Id in Outputs.
Subnets: pick either.Security groups: Click 'Edit' and add an inbound rule.- Specify rule type custom TCP and port 3000
Auto-assign public IP: ENABLED
- Hit button
Run Task - Click on the newly created task, note the Public IP, and wait for Container Status to become
RUNNING - Test model by:
- Test from script with the Public IP:
pipenv run python ./source/test/test_prediction.py ./source/test/0966.jpg "http://<public-ip>:3000
- Test by web browser:
- Open http://:3000/
- Select the first option, to POST
- Hit
Try it outin the top right - In the drop down box, change
application/postscripttoimage/jpeg - Upload the file
testing/0966.jpgor any other file from the dataset. - Hit
Execute, wait for your result
- Test from script with the Public IP:
- Hit
Stopin the top right to bring down model.
- To delete all AWS deploys, run
aws down. May take 10 minutes.
- EDA
- Model experimentation
- keras-starter-deit-cait.ipynb: explores the DEiT and CAiT transformer models
- keras-starter-efficientnet.ipynb: explores EfficientNet CNN models
- keras-starter-maxvit.ipynb: explores the MaxViT transformer model
- keras-starter-swin.ipynb: explores the Swin Transformer model
- model-testing.ipynb: performs a search over some transformer and CNN models
- Hyperparameter Search
- augmentation-test.ipynb: explores augmentation from ImageDataGenerator. None chosen
- randaug-testing.ipynb: explores augmentation using the RandAugment auto augmentation policy. Not chosen
- learning-rate-test.ipynb): searches for learning rate with large search space
- learning-rate-final.ipynb): searches for learning rate with narrower search space
- Training
- kaggle-submission.ipynb: submits trained BEiT model for Kaggle competition
- trainer.ipynb: training and bentoml capture of model for deployment (uses DEiT to save on space/time)
- trainer.py: training script made from above notebook
- Deploy
- service.py: BentoML service used for Docker/ECS
- test_prediction.py: Script for testing service
