This is a project for Advanced image processing course on PUT. It is an image classification using BoVW model ( Bag of Visual Words)
If something is unclear just ask :)
The BoVW is implemented as a python class (DataDescriber) which is compatible witch sklearn Pipeline which make it super easy to use parameters searching.
The target is to make image classification for five classes which are building in Poznań city:
- Hotel Bałtyk
- Katedra on Ostrów Tumski
- Okrąglak
- Teatr Wielki
- Uniwerystet Adama Mickiwicza
If you need the dataset for training just contact me.
Algorithm summary:
- Creating image features using OpenCV SIFT detector and descriptor, but using only 500 best features for each photo.
- After all features are collected I'm making a clustering using sklearn MiniBatchKMeans algorithm (2000 clusters) to create a vocabulary model.
- Transform image features into a histogram of "words" occurring in each photo using trained vocabulary model.
- Final step is to train a classifier where X is a histogram of words appearing on an image and y are labels for image.
- SIFT detector/descriptor - https://en.wikipedia.org/wiki/Scale-invariant_feature_transform
- MiniBatch K-Means algorithm - https://en.wikipedia.org/wiki/K-means_clustering
- LinearSVC classifier - https://en.wikipedia.org/wiki/Support_vector_machine#Linear_SVM
Best way is just to run your IDE and let it install requirements.txt
but if you want to do it manually you need:
pip3 install -Iv opencv-contrib-python==4.4.0.46
pip3 install -Iv numpy==1.19.4
pip3 install -Iv colorama==0.4.4
pip3 install -Iv scikit-learn==0.23.2
pip3 install -Iv tqdm==4.54.1
pip3 install -Iv scipy==1.5.4
pip3 install -Iv pandas==1.1.5
pip3 install -Iv sklearn==0.0
make_classification is the function where all magic does. As I said earlier the BoVW is in python class called DataDescriber you can use it in your project as an image transformer.
To train your classifier you need to specify path to directory with images in calsses
data_path = Path('train/') # You can change the path here
List of features ready and TODOs for future development
- Can do classification with accuracy about 90%
- Training do not take a while
To-do list:
- Cut down size of classifier (probably with enter exit statement)
- Add prediction function to DataDescriber
- TODO: as in Features To Do. Feel free to ask and pull requests.
- Finished: General concept
Project is inspired by Dominik Pieczyński, the course leader:)