This service classifies the images located in a folder name 'all' into specific classes. For example, assume the 'all' folder has images of people, cars, trucks and other stuff. The service is then invoked and instructed to classify the images into the classes ['people', 'trucks']. At the end of the classification job, the working directory will have two extra folders; 'people' and 'trucks' which will contain images of people and trucks respectively.
The service exposes two endpoints;
- POST '/classification-job' This endpoint takes a JSON object with an array of classes that images in the 'all' folder will be classified by. It returns a JSON object with data on the started classification jobs, including the job ids.
- GET '/classification-job/job-id' This endpoint is used for checking on the status of a classification job. It returns a JSON object that has details on how many images have been classified so far and how many are left.
- classifier.py Imports keras and tensorflow and then loads the ResNet50 image classification model. The top five predicted classes are concatenated into one string, For example 'car sports_car race_car truck boat'. The string is then checked to see if it has the name of the class being investigated (which is also a string).
- functions.py Contains helper functions for enumerating files in the 'all' folder and for moving a classified image to a different folder.
- responses.py Contains functions for constructing HTTP responses
- service.py The flask app that encapsulates all the functionality of this module and exposes it in the two HTTP endpoints described above.
- test_all.py Contains unit tests for all functions in the classifier.py and functions.py code files. Also contains tests of the two HTTP defined in service.py file. To run the tests install pytest then run 'pytest -v'
This service functions independently, but I built it to work in tandem with the downloader/uploader service available here. This classifier and the downloader/uploader can be combined and used as a cloud storage image classification system, such as this.