The project aims to build a Deep Learning based image classifier to distinguish chair, bed and sofa. Furthermore, it accompanies an API to receive the input image and return the result of classification.
In terms of the development stages, in the first step I made Classifier.ipynb that represents the neural network code. The program employs PyTorch framework wherein it has two convolutional layers (to extract features) following the two fully connected layers (to classify based on the features). It is noteworthy, in case of running the code on a certain machine, "root_dir" variable should be changed based on the path of the used machine. After introducing the network structure, the code aims to receive and preprocess the data to make it suitable for dataloader of PyTorch. Following that, Adam for the optimizer and CrossEntropyLoss for the loss are selected and the training phase commences. Finally, the train loss and test accuracy are measured. It should be noted the data consist of 100 images for each class (all made 300 images) and I allocated 80% to train and the rest to the test. As for the results, the test accuracy revolves around 78-83% as I ran the code multiple times, and the model that I saved for the API is the 80% version.
Considering API building, I made API.py along with html and css files (in templates and static folder). API.py is based on Flask web framework and it receives the input images, by virtue of html page, then loads the deep learning model, and shows the result of classification. As I analyzed the results, it works reliably for most of the images while as the inputted images become more similar to a combination of two classes (e.g. a sofa that has a similar design to a bed) it may fail to predict. I deployed the code on a web host to make it easier to be reached. The web host is pythonanywhere.com and flask_app.py is the code that is used by the web host. Basically, it is similar to API.py while it has minor changes like different the file name.
Furthermore, I appended a Dockerfile with aim of building a docker image. Respecting the docker file, it utilizes the requirements.txt file to provide the program dependencies, as it runs the pip install command. besides, it runs the application by CMD.
Last but not least, the action section of this GitHub repository is depicting a docker based workflow in which, as described in docker-image.yml, the workflow builds the docker image of the program then push it to the dockerhub account everytime based on CICD pipeline.