Rice detection system for face recognition (Part 2)

Tram Ho

In part 1 , we built the server AI system. In part 2, we will build the server for the problem. Let’s create the file:

  • config.py
  • utils.py
  • main.py
  • Dockerfile

Before going into specific coding, I want to explain through my logical solutions at the server. Every day, when the system boots up, it will create a folder of that day, inside each district folder to store the face of people who come to get rice. The reason that I do not use the database is because in this we only need to store the image only. If you want to “fancy” more can consider storage like Minio, …

Coding

First, let’s write the config.py file. In this file we will have the necessary values ​​for the server instead of each where you configure 1 bit.

On top of that, we configure the parameters for the 2 classes that we have written in part 1. Next is the geographical locations such as districts and wards. The separate data store like this can help you deploy additional examples both a statistical system of local shoppers Goa happen … And data_path : root bridge location to store photos. Next is the file utils.py :

The above function works to create folders of that day in the following format:

struct

Now we will build the FLASK server above main.py :

  • Initialize the Flask app and variables:

We will initialize variables such as face recognition model and search graph, etc. All are initiated in the init function. After initializing, we will add all the correct images for that day into the graph, merge the server to shut down and reboot.
The extra functions, everyone looks at it and it doesn’t work.

And API image processing function:

Here I will save the entire image to be queryed. If correct will be in the directory true, false, then it will be in the directory false. I think this is a good habit to save all data even if it is wrong, because the data can transfer teams to other problems. (Or sold 😈 )
Now initialize and run:

You can use flask instead of writing main to run python like that. But I only note you to host is 0.0.0.0 instead of the default, because by default localhost, when using docker, it will not expose the port.

Writing Dockerfile :

  • Install pipreqs to create a reuirements.txt file containing the necessary libraries, then run the pipreqs command.
  • Write the content Dockerfile as below

Result

Here are some of the results you will have after you have built the server:
api / district

api / wards

api / face

So we have completed the server part, the last part we will build the Frontend system with ReactJS.

Share the news now

Source : Viblo