{"id":19989188,"url":"https://github.com/clamytoe/kitchenware_classifier","last_synced_at":"2025-05-04T09:32:45.454Z","repository":{"id":64965416,"uuid":"569250187","full_name":"clamytoe/kitchenware_classifier","owner":"clamytoe","description":"Classifies kitchen stuff items into 6 categories: cups, glasses, plates, spoons, forks and knives","archived":false,"fork":false,"pushed_at":"2023-02-01T12:27:38.000Z","size":65872,"stargazers_count":19,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-16T01:53:23.880Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/clamytoe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-22T12:15:33.000Z","updated_at":"2023-10-18T11:05:17.000Z","dependencies_parsed_at":"2023-02-17T05:30:31.094Z","dependency_job_id":null,"html_url":"https://github.com/clamytoe/kitchenware_classifier","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fkitchenware_classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fkitchenware_classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fkitchenware_classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/clamytoe%2Fkitchenware_classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/clamytoe","download_url":"https://codeload.github.com/clamytoe/kitchenware_classifier/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224391418,"owners_count":17303609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T04:45:46.411Z","updated_at":"2024-11-13T04:45:47.083Z","avatar_url":"https://github.com/clamytoe.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kitchenware Classification (*kitchenware_classifier*)\n\n\u003e *Classifies kitchen stuff items into 6 categories: cups, glasses, plates, spoons, forks and knives*\n\n![Python version][python-version]\n![Latest version][latest-version]\n[![GitHub issues][issues-image]][issues-url]\n[![GitHub forks][fork-image]][fork-url]\n[![GitHub Stars][stars-image]][stars-url]\n[![License][license-image]][license-url]\n\nNOTE: This project was generated with [Cookiecutter](https://github.com/audreyr/cookiecutter) along with [@clamytoe's](https://github.com/clamytoe) [toepack](https://github.com/clamytoe/toepack) project template.\n\nThis repo is the result of my capstone project for the Machine Learning Zoomcamp 2022 course. I used the model for a [Kitchenware Classification](https://www.kaggle.com/competitions/kitchenware-classification) competition that was hosted by the [DataTalks.Club](https://datatalks.club/) over at [Kaggle](https://www.kaggle.com).\n\nThe model will take an image of a kitchenware item and try to classify it into one of the following classes:\n\n* cups\n* forks\n* glasses\n* knives\n* plates\n* spoons\n\nI was able to score a `0.97674` with it and am currently in the 13th place as a member of Team **Penumbra**!\n\nMy fellow team mebers were:\n\n* Roman Zabolotin - Junior Data Scientist\n* Tatiana Ankudo - Analyst\n\n## The data\n\nThe dataset is pretty big so I did not include it here. You can download it from the competition page.\n\nIn order to get things to work right the first time, extract it's contents into the `kitchenware_classifier/data/` folder.\n\n\u003e **NOTE:** I've added the [extra images](https://www.kaggle.com/datasets/agrigorev/kitchenware-extra-images) that were given to the community by Walukagga Patrick.\n\nMy tree structure looks like this:\n\n```zsh\n├── Dockerfile\n├── LICENSE\n├── Pipfile\n├── Pipfile.lock\n├── README.md\n├── api.py\n├── fastai_model.pkl\n├── favicon.ico\n├── images\n│   ├── coffe.jpg\n│   ├── deployment.png\n│   ├── docs.png\n│   ├── mogenius-welcome.png\n│   ├── mogenius.png\n│   ├── post.png\n│   ├── result.png\n│   ├── selected.png\n│   ├── settings.png\n│   └── upload.png\n├── kitchenware_classifier\n│   ├── data\n│   │   ├── extra.csv\n│   │   ├── images\n│   │   ├── models\n│   │   ├── sample_submission.csv\n│   │   ├── test.csv\n│   │   └── train.csv\n│   ├── extra-images.zip\n│   └── kitchenware-classification.zip\n├── kw_router.py\n├── notebook.ipynb\n├── predict.py\n├── requirements.txt\n├── sample.jpg\n├── sample2.jpg\n├── send_multiple_images.py\n├── send_single_image.py\n├── submission.csv\n├── test_model.py\n└── train.py\n```\n\n## Initial setup\n\nFirst thing to do is to create or change directories into wherever you keep all of your projects.\nFor me, it's the `Projects` folder.\nOnce there clone this repo.\n\n```zsh\n(py310) ➜ cd Projects\n(py310) ➜ git clone \u003chttps://github.com/clamytoe/kitchenware_classifier.git\u003e\n(py310) ➜ cd kitchenware_classifier\n```\n\n## Anaconda setup\n\nIf you are an Anaconda user, this command will get you up to speed with the base installation.\n\n```zsh\n(py310) ➜ conda create --name kws -file requirements.txt\n(py310) ➜ conda activate kwc\n```\n\n## Regular Python setup\n\nIf you are just using normal Python, this will get you ready.\nFirst thing is to create a virtual environment. There are many ways to do this, but the simplest is using `venv`.\n\n```zsh\n(py310) ➜ python3 -m venv venv\n(py310) ➜ source venv/bin/activate\n(venv) ➜ pip install -r requirements.txt\n```\n\n## Generating the model\n\n\u003e **NOTE:** I've included the model, `fastai_model.pkl`, but due to it's size, GitHub complained about it. If I have to remove it, you will have to build your own, or use the provided Docker [image](https://hub.docker.com/r/clamytoe/kitchenware-clf), which has it.\n\nOnce you have your local virtual environment setup,\nyou just need to run the `train.py` script and some coffee to generate it.\n\n```zsh\n(kwc) ➜ python train.py\nFinding best learning rate...\nlrs=SuggestedLRs(minimum=0.004786301031708717, steep=1.4454397387453355e-05, valley=0.0005754399462603033, slide=0.0014454397605732083)\nTraining the Model...\nepoch     train_loss  valid_loss  error_rate  accuracy  time\n0         0.319466    0.125656    0.040504    0.959496  01:28\nBetter model found at epoch 0 with valid_loss value: 0.12565582990646362.\n1         0.247616    0.090624    0.034203    0.965797  01:29\nBetter model found at epoch 1 with valid_loss value: 0.09062422811985016.\n2         0.201797    0.092758    0.030603    0.969397  01:29\n3         0.163881    0.100454    0.034203    0.965797  01:29\n4         0.152107    0.092587    0.033303    0.966697  01:29\nNo improvement since epoch 1: early stopping\nModel validation: [0.09062422811985016, 0.0342034213244915, 0.9657965898513794]\nSaving model as: fastai_model.pkl...\nTraining completed!\n```\n\n## Start the server\n\nOnce your environment is setup, this one command will start the server:\n\n```zsh\n(kwc) ➜ uvicorn api:app --reload\n```\n\n## Usage\n\nWith the server up and running, you can now send it images to classify for you. I have included two sample images:\n\n\u003cimg src=\"sample.jpg\" alt=\"sample 1\" width=\"200\" /\u003e\n\nand\n\n\u003cimg src=\"sample2.jpg\" alt=\"sample 2\" width=\"200\" /\u003e\n\nI have provided two sample scripts:\n\n* `send_simgle_image.py`\n* `send_multiple_images.py`\n\nWith the server running, you can run either of the scripts to test out the server.\n\n*send_simgle_image.py:*\n\n```zsh\n(kwc) ➜ python send_single_image.py\n{'predicted': 'fork', 'probabilities': {'cup': 2.682557351363357e-05, 'fork': 0.9998975992202759, 'glass': 2.706188070078497e-06, 'knife': 5.796951882075518e-06, 'plate': 6.11106152064167e-05, 'spoon': 5.840373432874912e-06}}\n```\n\n*send_multiple_images.py:*\n\n```zsh\n(kwc) ➜ python python send_multiple_images.py\n{'image': 'sample2.jpg', 'predicted': 'plate', 'probabilities': {'cup': 0.00012867810437455773, 'fork': 5.518031230167253e-06, 'glass': 1.5953222828102298e-05, 'knife': 1.3917076557845576e-07, 'plate': 0.9998399019241333, 'spoon': 9.731486898090225e-06}}\n{'image': 'sample.jpg', 'predicted': 'fork', 'probabilities': {'cup': 2.682557351363357e-05, 'fork': 0.9998975992202759, 'glass': 2.706188070078497e-06, 'knife': 5.796951882075518e-06, 'plate': 6.11106152064167e-05, 'spoon': 5.840373432874912e-06}}\n```\n\n\u003e **NOTE:** By default the scripts submit the images to my cloud service. To test locally, just change the url setting from `url[\"cloud\"]` to `url[\"local\"]`.\n\n## A much easier way\n\nThe benefit of using [FasAPI](https://fastapi.tiangolo.com/) is that it makes things much easier and faster.\nFor instance, if you nagivate to: [http://localhost:8000/docs](http://localhost:8000/docs) you will be able to interact with the application.\n\n![docs](images/docs.png)\n\n### GET / Welcome\n\nThis entrypoint just returns some information about me and the project.\n\n### POST /classify_image Classify Image\n\nThis is where you get to play with the model and see how well/bad it works.\nFeed it an image of a kitchenware item and see how it does.\n\nTo use it, simply click on the **POST** button to expand it:\n\n![post](images/post.png)\n\nThen click on the **Try it out** button.\n\n![upload](images/upload.png)\n\nThis will reveal a **Choose File** button that will allow you to navigate your filesystem and choose and image.\n\nHere, I've randomly chosen a tricky one from the [Internet](https://static.turbosquid.com/Preview/2014/07/07__23_41_37/coffe_cup_preview_02.jpgc89daf5f-e0b8-46f7-929d-8c618f1b09fcLarge.jpg) to see what the model picks up:\n\n\u003cimg src=\"images/coffee.jpg\" alt=\"coffee\" width=\"200\" /\u003e\n\nWith the image loaded:\n\n![selected](images/selected.png)\n\nSimply click on the big **Execute** button to process the image.\n\nIf you scroll down a bit, you will see your results:\n\n![results](images/result.png)\n\nAs you can see, it picked up on the cup!\n\n## Docker image\n\nIf you would rather not have to download this repo, create an environmet, download the dataset, etc, you can run this as a docker container.\nSimply download an already compiled version from [Docker Hub](https://hub.docker.com): [Kitchenware Classifier](https://hub.docker.com/r/clamytoe/kitchenware-clf)\n\n```zsh\n(kwc) ➜ docker pull clamytoe/kitchenware-clf\n```\n\nOnce you have the image you can run it as so:\n\n```zsh\n(kwc) ➜ docker run -it --rm -p 8000:8000 clamytoe/kitchenware-clf\n```\n\n\u003e **NOTE:** The image is 3.77GB but expands to 6.06GB.\n\n## Build your own\n\nIf you would rather build the docker image yourself, I have included the `Dockerfile` just for that purpose.\nJust run the following command from the directory where you cloned this repo to:\n\n```zsh\n(kwc) ➜ docker build -t kitchenware-clf .\n```\n\nOnce you have the image you can run it as so:\n\n```zsh\n(kwc) ➜ docker run -it --rm -p 8000:8000 kitchenware-clf\n```\n\n## Cloud deployment\n\nI've been really impressed with the ease of use of [Mogenius](https://mogenius.com/) so I went ahead and deployed the model there.\n\n![mogenius-welcome](images/mogenius-welcome.png)\n\nGive it a try: [Kitchenware Classifier on Mogenius](https://kitchenware-cl-prod-kitchenware-classifier-7f8cze.mo1.mogenius.io/docs)\n\nHere is what the dashboard looks like after classifying an image.\n\n![mogenius](images/mogenius.png)\n\n\u003e The free tier is a bit slow, but for free and extreme ease of use, it's perfect!\n\n### Prepare model for cloud deployment\n\nBefore I could even think about getting my model on the cloud, I first had to tag my image and push it to docker hub.\n\n```zsh\n(kwc) ➜ docker tag kitchenware-clf clamytoe/kitchenware-clf:latest\n```\n\n\u003e **NOTE:** Make sure to use your own docker hub user name.\n\nOnce the image has been properly named, it can now be push.\n\n```zsh\n(kwc) ➜ docker push clamytoe/kitchenware-clf:latest\n```\n\n\u003e Mogenius allows you to deploy from an existing image but it can also just build it from yoru GitHub repo, as long as you have a `Dockerfile`.\n\nOnce the image has been uploaded to Docker Hub, it was relatively easy to set it up.\n\n![settings](images/settings.png)\n\n\u003e **NOTE:** Just remember to expose the correct port.\n\n*Deployment from docker hub image in progress...*\n\n![deployment](images/deployment.png)\n\nMore detailed instructions can be found in their [Quickstart Guide](https://docs.mogenius.com/getting-started/quickstart).\n\n## License\n\nDistributed under the terms of the [MIT](https://opensource.org/licenses/MIT) license, \"kitchenware_classifier\" is free and open source software.\n\n## Issues\n\nIf you encounter any problems, please [file an issue](https://github.com/clamytoe/toepack/issues) along with a detailed description.\n\n[python-version]:https://img.shields.io/badge/python-3.10.6-brightgreen.svg\n[latest-version]:https://img.shields.io/badge/version-1.0.0-blue.svg\n[issues-image]:https://img.shields.io/github/issues/clamytoe/kitchenware_classifier.svg\n[issues-url]:https://github.com/clamytoe/kitchenware_classifier/issues\n[fork-image]:https://img.shields.io/github/forks/clamytoe/kitchenware_classifier.svg\n[fork-url]:https://github.com/clamytoe/kitchenware_classifier/network\n[stars-image]:https://img.shields.io/github/stars/clamytoe/kitchenware_classifier.svg\n[stars-url]:https://github.com/clamytoe/kitchenware_classifier/stargazers\n[license-image]:https://img.shields.io/github/license/clamytoe/kitchenware_classifier.svg\n[license-url]:https://github.com/clamytoe/kitchenware_classifier/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclamytoe%2Fkitchenware_classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclamytoe%2Fkitchenware_classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclamytoe%2Fkitchenware_classifier/lists"}