{"id":24380528,"url":"https://github.com/marcotallone/bow-classifier","last_synced_at":"2026-05-02T05:45:10.215Z","repository":{"id":271566764,"uuid":"908514130","full_name":"marcotallone/bow-classifier","owner":"marcotallone","description":"Implementing Bag of Visual Words (BoW) classifier for image classification and scene recognition ","archived":false,"fork":false,"pushed_at":"2025-01-08T14:44:35.000Z","size":98206,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-02T19:58:06.256Z","etag":null,"topics":["bag-of-visual-words","bag-of-words","bow","computer-vi","kernel-codebook","knn","opencv","opencv-python","sift","spatial-pyramid-matching","svm","svm-classifier"],"latest_commit_sha":null,"homepage":"","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/marcotallone.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-26T09:00:23.000Z","updated_at":"2025-03-05T06:16:16.000Z","dependencies_parsed_at":"2025-01-08T15:44:12.912Z","dependency_job_id":null,"html_url":"https://github.com/marcotallone/bow-classifier","commit_stats":null,"previous_names":["marcotallone/bow-classifier"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marcotallone/bow-classifier","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcotallone%2Fbow-classifier","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcotallone%2Fbow-classifier/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcotallone%2Fbow-classifier/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcotallone%2Fbow-classifier/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcotallone","download_url":"https://codeload.github.com/marcotallone/bow-classifier/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcotallone%2Fbow-classifier/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32524565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["bag-of-visual-words","bag-of-words","bow","computer-vi","kernel-codebook","knn","opencv","opencv-python","sift","spatial-pyramid-matching","svm","svm-classifier"],"created_at":"2025-01-19T08:19:53.897Z","updated_at":"2026-05-02T05:45:10.178Z","avatar_url":"https://github.com/marcotallone.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca name=\"readme-top\"\u003e\u003c/a\u003e\n\n\u003c!-- PROJECT SHIELDS --\u003e\n[![Forks][forks-shield]][forks-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Issues][issues-shield]][issues-url]\n[![MIT License][license-shield]][license-url]\n[![LinkedIn][linkedin-shield]][linkedin-url]\n[![Gmail][gmail-shield]][gmail-url]\n\n\u003c!-- PROJECT LOGO --\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://github.com/marcotallone/bow-classifier\"\u003e\n    \u003cimg src=\"report/images/shopping-bag.png\" alt=\"Logo\" width=\"150\" height=\"150\"\u003e\n  \u003c/a\u003e\n\n\u003ch2 align=\"center\"\u003eBag of Visual Words Classifier\u003c/h2\u003e\n\u003ch4 align=\"center\"\u003eComputer Vision and Pattern Recognition Course Exam Project\u003c/h4\u003e\n\u003ch4 align=\"center\"\u003eSDIC Master Degree, University of Trieste (UniTS)\u003c/h4\u003e\n\u003ch4 align=\"center\"\u003e2024-2025\u003c/h4\u003e\n\n  \u003cp align=\"center\"\u003e\n    Implementing Bag of Visual Words (BoW) classifier\u003cbr\u003efor image classification and scene recognition\n    \u003cbr /\u003e\n    \u003cbr /\u003e\n    \u003ctable\u003e\n      \u003ctr\u003e\n        \u003ctd\u003e\u003ca href=\"./report/main.pdf\"\u003e\u003cstrong\u003eReport\u003c/strong\u003e\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"./notebooks/bow-classifier.ipynb\"\u003e\u003cstrong\u003ePython Notebook\u003c/strong\u003e\u003c/a\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"./notebooks/bow-classifier.html\"\u003e\u003cstrong\u003eRendered Notebook\u003c/strong\u003e\u003c/a\u003e\u003c/td\u003e\n      \u003c/tr\u003e\n    \u003c/table\u003e\n\u003c/div\u003e\n\n\u003c!-- TABLE OF CONTENTS --\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003ctable\u003e\n      \u003ctr\u003e\u003ctd style=\"text-align: left;\"\u003e\n        \u003ch2\u003eTable of Contents\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003c/h2\u003e\n        \u003cdiv style=\"display: inline-block; text-align: left;\" align=\"left\"\u003e\n          \u003cp\u003e\n            \u0026nbsp;1. \u003ca href=\"#author-info\"\u003eAuthor Info\u003c/a\u003e\u003cbr\u003e\n            \u0026nbsp;2. \u003ca href=\"#about-the-project\"\u003eAbout The Project\u003c/a\u003e\u003cbr\u003e\n              \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;- \u003ca href=\"#quick-overview\"\u003eQuick Overview\u003c/a\u003e\u003cbr\u003e\n              \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;- \u003ca href=\"#built-with\"\u003eBuilt With\u003c/a\u003e\u003cbr\u003e\n              \u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;- \u003ca href=\"#project-structure\"\u003eProject Structure\u003c/a\u003e\u003cbr\u003e\n            \u0026nbsp;3. \u003ca href=\"#getting-started\"\u003eGetting Started\u003c/a\u003e\u003cbr\u003e\n            \u0026nbsp;4. \u003ca href=\"#usage-examples\"\u003eUsage Examples\u003c/a\u003e\u003cbr\u003e\n            \u0026nbsp;5. \u003ca href=\"#contributing\"\u003eContributing\u003c/a\u003e\u003cbr\u003e\n            \u0026nbsp;6. \u003ca href=\"#license\"\u003eLicense\u003c/a\u003e\u003cbr\u003e\n            \u0026nbsp;7. \u003ca href=\"#references\"\u003eReferences\u003c/a\u003e\u003cbr\u003e\n            \u0026nbsp;9. \u003ca href=\"#acknowledgments\"\u003eAcknowledgments\u003c/a\u003e\u003cbr\u003e\n          \u003c/p\u003e\n        \u003c/div\u003e\n      \u003c/td\u003e\u003c/tr\u003e\n  \u003c/table\u003e\n\u003c/div\u003e\n\n\u003c!-- AUTHOR INFO--\u003e\n## Author Info\n\n| Name | Surname | Student ID | UniTS mail | Google mail | Master |\n|:---:|:---:|:---:|:---:|:---:|:---:|\n| Marco | Tallone | SM3600002 | \u003cmarco.tallone@studenti.units.it\u003e | \u003cmarcotallone85@gmail.com\u003e | **SDIC** |\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- ABOUT THE PROJECT --\u003e\n## About The Project\n\n\u003e[!WARNING] \n\u003e**Generative Tools Notice**:\\\n\u003e Generative AI tools have been used as a support for the development of this project. In particular, the [Copilot](https://en.wikipedia.org/wiki/Microsoft_Copilot) generative tool based on [OpenAI GPT 4o](https://en.wikipedia.org/wiki/GPT-4) model has been used as assistance medium in performing the following tasks:\n\u003e - writing documentation and comments in [implemented functions](./notebooks/utils.py) by adehering to the [NumPy Style Guide](https://numpydoc.readthedocs.io/en/latest/format.html)\n\u003e - improving variable naming and code readability\n\u003e - minor bug fixing in [implemented functions](./notebooks/utils.py)\n\u003e - grammar and spelling check both in this README and in the [report](./report/main.pdf)\n\u003e - tweaking aesthetic improvements in [report](./report/main.pdf) plots\n\u003e - formatting table of results in [report](./report/main.pdf)\n\n### Quick Overview\n\nThe Bag of Visual Words (BoW) model is a popular computer vision technique used for image classification or retrieval. It is based on the idea of treating images as documents and representing them as histograms of visual words belonging to a visual vocabulary, which is obtained by clustering local features extracted from a set of images.\n\n\u003cdiv style=\"text-align: center;\"\u003e\n  \u003cimg src=\"./report/images/visual-words.jpg\" alt=\"Image\" width=\"400\"/\u003e\n\u003c/div\u003e\n\nThis project implements a BoW image classifier for scene recognition by first building a visual vocabulary from a set of test images and then performing multi-class classification using K-Nearest Neighbors (KNN) and Support Vector Machines (SVM) classifiers.\\\nIn particular, the visual vocabulary is built by clustering SIFT descriptors extracted from the test images and using the K-Means algorithm. Descriptors have been computed both from keypoints detected with the the SIFT algorithm and from dense sampling of the images with a fixed grid to compare the two approaches.\\\nIn the classification phase instead, the performance of a simple KNN classifier is compared with that of different SVM classifiers all adopting the ``*one-vs-all*'' strategy for multi-class classification. The SVM classifiers differ in the kernel used and in the kind of input features they are trained on.\\\nAdditionally, different ways to represent images as input feature vectors are tested. These include the classic representation as normalized histograms of visual words, the implementation of the *soft assignment* techniques proposed by *Van Gemert et al.* [\u003ca href=\"#ref3\"\u003e3\u003c/a\u003e] and the use of the *spatial pyramid feature representation* proposed by *Lazebnik et al.* [\u003ca href=\"#ref1\"\u003e1\u003c/a\u003e].\\\nThe objectives of this study are to compare the performance of the different classifiers and image representations and to reproduce the results obtained by *Van Gemert et al.* [\u003ca href=\"#ref3\"\u003e3\u003c/a\u003e] and *Lazebnik et al.* [\u003ca href=\"#ref1\"\u003e1\u003c/a\u003e] on the *15-Scenes* dataset.\nFor further details on the specific feature extraction techniques used and the machine learning algorithms implemented as well as the results with them obtained, please refer to the [official report](./report/main.pdf). For a description of the implementation of the BoW classifier, read instead the [dedicated notebook](./notebooks/bow-classifier.ipynb).\n\n### Project Structure\n\nThe project is structured as follows:\n\n```bash\n├── 🐍 cv-conda.yaml  # Conda environment\n├── 📁 datasets       # Datasets folder\n│   ├── test\n│   └── train\n├── 📁 doc            # Project assignment\n├── ⚜️ LICENSE        # License file\n├── 📓 notebooks      # Jupyter Notebooks \n│   ├── bow-classifier.ipynb\n│   ├── results-plots.ipynb\n│   └── utils.py\n├── 📜 README.md      # This README file\n└── 📁 report         # Report folder\n    ├── images\n    ├── main.tex\n    └── ...\n```\n\nIn particular the [notebooks/](./notebooks) folder contains the following notebooks:\n\n- [`bow-classifier.ipynb`](./notebooks/bow-classifier.ipynb): the main notebook containing a step-by-step description of the implementation of the BoW classifier\n- [`results-plots.ipynb`](./notebooks/results-plots.ipynb): a notebook containing the code to generate the plots and the final results presented in the [report](./report/main.pdf)\n- [`utils.py`](./notebooks/utils.py): a Python script containing the utility functions implemented for this project\n  \n### Built With\n\n![OpenCV](https://img.shields.io/badge/OpenCV-red?style=for-the-badge\u0026logo=opencv\u0026logoColor=white)\n![Jupyter](https://img.shields.io/badge/Jupyter-F37626?style=for-the-badge\u0026logo=jupyter\u0026logoColor=white)\n![Scikit-learn](https://img.shields.io/badge/Scikit--learn-F7931E?style=for-the-badge\u0026logo=scikit-learn\u0026logoColor=white)\n![Conda](https://img.shields.io/badge/Conda-44A833?style=for-the-badge\u0026logo=anaconda\u0026logoColor=white)\n![Python](https://img.shields.io/badge/Python-3776AB?style=for-the-badge\u0026logo=python\u0026logoColor=white)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- GETTING STARTED --\u003e\n## Getting Started\n\n### Requirements\n\nThe project is developed in `Python` and mostly requires the following libraries:\n\n- `numpy`, version `1.26.4`\n- [`opencv`](https://opencv.org/), version `4.10.0`\n- [`scikit-learn`](https://scikit-learn.org/stable/), version `1.5.2`\n- `tqdm`, version `4.67.0`\n\nAll the necessary libraries can be easily installed using the `pip` package manager.\\\nAdditionally a [conda environment `yaml` file](./cv-conda.yaml) containing all the necessary libraries for the project is provided in the root folder. To create the environment you need to have installed a working `conda` version and then create the environment with the following command:\n\n```bash\nconda env create -f cv-conda.yaml\n```\n\nAfter the environment has been created you can activate it with:\n\n```bash\nconda activate cv\n```\n\n\u003c!-- USAGE EXAMPLES --\u003e\n## Usage Examples\n\nFor a detailed step-by-step description of the main tasks performed for this project and the implementation of the BoW classifier, please refer to the [dedicated notebook](./notebooks/bow-classifier.ipynb).\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- CONTRIBUTING --\u003e\n## Contributing\n\nThe goal of this repository was to implement a classifier based on the Bag of Visual Words approach and reproduce the results presented in the referenced papers in the context of a university exam project. However, if you have a suggestion that would make this better or extend its functionalities and want to share it with me, please fork the repo and create a pull request. You can also simply open an issue with the tag \"enhancement\" or \"extension\".\\\nSuggested contribution procedure:\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- LICENSE --\u003e\n## License\n\nDistributed under the MIT License. See [`LICENSE`](./LICENSE) for more information.\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- REFERENCES --\u003e\n## References\n\n\u003ca id=\"ref1\"\u003e\u003c/a\u003e\n[1] S. Lazebnik, C. Schmid, J. Ponce, *\"Beyond Bags of Features: Spatial Pyramid Matching for Recognizing Natural Scene Categories\"*, 2006 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR'06), Volume 2, 2006, Pages 2169-2178, [https://doi.org/10.1109/CVPR.2006.68](https://ieeexplore.ieee.org/document/1641019)\n\n\u003ca id=\"ref2\"\u003e\u003c/a\u003e\n[2] L. Fei-Fei, P. Perona, *\"A Bayesian hierarchical model for learning natural scene categories\"*, 2005 IEEE Computer Society Conference on Computer Vision and Pattern Recognition (CVPR'05), Volume 2, 2005, Pages 524-531 vol. 2, [https://doi.org/10.1109/CVPR.2005.16](https://ieeexplore.ieee.org/document/1467326)\n\n\u003ca id=\"ref3\"\u003e\u003c/a\u003e\n[3] J.C. van Gemert, J.-M. Geusebroek, C.J. Veenman, A.W.M. Smeulders, *\"Kernel Codebooks for Scene Categorization\"*, Computer Vision -- ECCV 2008, 2008, Springer Berlin Heidelberg, Pages 696-709, [https://doi.org/10.1007/978-3-540-88693-8_52](https://link.springer.com/chapter/10.1007/978-3-540-88693-8_52)\n\n\u003ca id=\"ref4\"\u003e\u003c/a\u003e\n[4] C.-C. Chang, C.-J. Lin, *\"LIBSVM: A library for support vector machines\"*, ACM Transactions on Intelligent Systems and Technology (TIST), Volume 2, Number 3, 2011, Pages 1-27, [https://doi.org/10.1145/1961189.1961199](https://dl.acm.org/doi/10.1145/1961189.1961199)\n\n\u003ca id=\"ref5\"\u003e\u003c/a\u003e\n[5] P. J. Rousseeuw, *\"Silhouettes: A graphical aid to the interpretation and validation of cluster analysis\"*, Journal of Computational and Applied Mathematics, Volume 20, 1987, Pages 53-65, [https://doi.org/10.1016/0377-0427(87)90125-7](https://www.sciencedirect.com/science/article/pii/0377042787901257)\n\n\u003ca id=\"ref6\"\u003e\u003c/a\u003e\n[6] F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau, M. Brucher, M. Perrot, E. Duchesnay, *\"Scikit-learn: Machine learning in Python\"*, Journal of Machine Learning Research, Volume 12, 2011, Pages 2825-2830, [https://www.jmlr.org/papers/volume12/pedregosa11a/pedregosa11a.pdf](https://www.jmlr.org/papers/volume12/pedregosa11a/pedregosa11a.pdf)\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- ACKNOWLEDGMENTS --\u003e\n## Acknowledgments\n\n- [Computer Vision and Pattern Recognition course material (UniTS, Fall 2024)](https://moodle2.units.it/enrol/index.php?id=14024) (*access restricted to UniTS students and staff*)\n- [Best-README-Template](https://github.com/othneildrew/Best-README-Template?tab=readme-ov-file): for the README template\n- [Flaticon](https://www.flaticon.com/free-icon/shopping-bag_2413526?related_id=2413552\u0026origin=search): for the icons used in the README\n\n\u003cp align=\"right\"\u003e(\u003ca href=\"#readme-top\"\u003eback to top\u003c/a\u003e)\u003c/p\u003e\n\n\u003c!-- MARKDOWN LINKS \u0026 IMAGES --\u003e\n\u003c!-- https://www.markdownguide.org/basic-syntax/#reference-style-links --\u003e\n[forks-shield]: https://img.shields.io/github/forks/marcotallone/bow-classifier.svg?style=for-the-badge\n[forks-url]: https://github.com/marcotallone/bow-classifier/network/members\n[stars-shield]: https://img.shields.io/github/stars/marcotallone/bow-classifier.svg?style=for-the-badge\n[stars-url]: https://github.com/marcotallone/bow-classifier/stargazers\n[issues-shield]: https://img.shields.io/github/issues/marcotallone/bow-classifier.svg?style=for-the-badge\n[issues-url]: https://github.com/marcotallone/bow-classifier/issues\n[license-shield]: https://img.shields.io/github/license/marcotallone/bow-classifier.svg?style=for-the-badge\n[license-url]: https://github.com/marcotallone/bow-classifier/blob/master/LICENSE\n[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-blue?style=for-the-badge\u0026logo=linkedin\u0026logoColor=white\u0026colorB=0077B5\n[linkedin-url]: https://linkedin.com/in/marco-tallone-40312425b\n[gmail-shield]: https://img.shields.io/badge/-Gmail-red?style=for-the-badge\u0026logo=gmail\u0026logoColor=white\u0026colorB=red\n[gmail-url]: mailto:marcotallone85@gmail.com\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcotallone%2Fbow-classifier","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcotallone%2Fbow-classifier","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcotallone%2Fbow-classifier/lists"}