Designing the web server

In this section, we will set up a Flask server to allow users to upload their images and set the correct label if our model is mistaken. We have provided the code needed in the production package. Implementing a Flask server with database support is beyond the scope of this chapter. In this section, we will describe all the main points about Flask so you can follow and understand better.

The main flow that allows users to upload and correct labels can be described in the following wireframe.

This flow is implemented with the following routes:

Route

Method

Description

/

GET

This route returns a web form for users to upload the image.

/upload_image

POST

This route gets the image from POST data, saves it to the upload directory, and calls process_image in our client.py to recognize the image and save the result to the database.

/results<result_id>

GET

This route returns the result of the corresponding row in the database.

/results<result_id>

POST

This route saves the label from, user to the database so that we can fine-tune the model later.

/user-labels

GET

This route returns a list of all the user-labeled images. In the fine-tune process, we will call this route to get the list of labeled images.

/model

POST

This route allows the fine-tune process from the training server to serve a new trained model. This route receives a link of the zipped model, a version number, a checkpoint name, and a model name.

/model

GET

This route returns the latest model in the database. The fine-tune process will call this to know which is the latest model and fine-tune from it.

We should run this server in a tmux session with the following command:

tmux new -s "flask"
python production/server.py
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.135.225