Awesome
Faulty Image API
This API combines the image classification models (i.e. empty, sticky notes, folded corner and writing type classifiers) trained in Dalai project. Using this API one can predict whether the document is empty, contains sticky notes or folded corners and the writing type of the document. This API is also used in Arkkiivi backend.
Installation
- Create and activate conda environment:
conda create -n faulty_api_env python=3.7
conda activate faulty_api_env
- Install poppler:
conda install -c conda-forge poppler
- Install required libraries:
pip install -r requirements.txt
How to use
- Open flask app:
flask --app api.py run
- Open flask app with debug:
flask --app api.py --debug run
The API assumes that the models are found in './models' folder. The models are named 'post_it_model.onnx', 'corner_model.onnx', 'empty_model_v4.onnx' ja 'writing_type_v1.onnx'.
The trained models are transformed into the ONNX format in order to speed up inference and to make the use of the model less dependent on specific frameworks and libraries.
-
The API has one endpoint called
/detect
. The desired models used in inference can be chosen with arguments in the POST http request. Argument 0 means that the model is not used and 1 means that it is used. -
An example of POST http request where all models are used:
/detect?postit=1"&"corner=1"&"empty=1"&"writing_type=1
. -
Default-port: 5000
-
The API expects that the image file of the document is attached to the POST request. One can test the API with request.py file or with for example curl command:
curl http://127.0.0.1:5000/detect?postit=1"&"corner=1"&"empty=1"&"writing_type=1 -F image=@/path/img.jpg
NB! Windows users might encounter following error Invoke-WebRequest : A parameter cannot be found that matches parameter name 'F'.
. This can be bypassed by running a command Remove-item alias:curl
.
How to interpret API responses
The API returns a Flask response that contains a list of dictionary.
With corner, empty and postit, 0 means that the model has not detected any flaws and 1 means that the model found a fault. In writing type model, the classification goes as followed: 0 means handwritten, 1 means type written and 2 means a combination of those two.