This article is authorized by the machine mind (WeChat public number: almosthuman2014) to reprint two times.
How should all localities do a good job in epidemic prevention? AI technology is providing necessary help for the fight against the new crown pneumonia epidemic.
The outbreak of a new pneumonia outbreak in 2019 has changed people's travels a lot
Wearing a mask correctly to prevent the spread of the epidemic has been widely supported. But there are many challenges
In February 13th, Baidu PaddlePaddle announced the first open face mask and face detection model in the industry. Based on this model, a large number of faces can be detected in public scenes, and the faces with and without masks can be marked out, so as to quickly identify people who do not pay attention to or pay attention to virus protection, or even have a fluke mentality in various scenes, so as to reduce the security risks in public occasions. At the same time, we will build more public welfare applications for epidemic prevention.
In the face of the disaster, the technology company responded to the appeal of Chen Yueliang, director of the Ministry of Civil Affairs: "a useful public welfare software is more effective than donating 1 billion yuan!"! "
The industry's first open source face mask detection and classification model
Mask face detection and classification model consists of two functional units, which can respectively complete the detection and classification of mask face. After testing, the accuracy of the face detection part of the mask is 98%, and the accuracy of the face classification part of the mask is also 96.5%, and the performance is also the leading level in the industry.
At the same time, it achieves the ultimate lightweight of the model, and can realize real-time processing on most end-to-end cloud devices (Hisilicon 3559 chip takes only 17ms). The first mock exam will continue to update Baidu's model.
Baidu said that such a high accuracy rate is the result of a large number of data training. The new model uses training data of more than 100000 pictures to ensure that the sample size is sufficient and effective. On the other hand, the face detection model is based on the champion algorithm developed by Baidu itself, and the whole research and development process is based on the open-source deep learning platform of Baidu, which can carry out efficient and convenient model development, training and deployment.
We can first look at the effects of the mask face detection and classification model, in which the green border box is wearing a mask face and the red border box is not wearing a mask face. Baidu team also provided online demo page, we can upload their own pictures, and test the effect of the model:
Online demo address:Https://www.paddlepaddle.org.cn/hub/scene/maskdetect
Pre-training model, immediate deployment
If we have our own needs and data, then using the deep learning framework to start training from scratch is also a great option. But there is no doubt that the cost is high, and at the same time, baidu will train their own mask face detection and classification model, through the way of pre-training model open, can greatly help developers save resources and improve efficiency.
Through the pre training model management tool PaddleHub, Baidu PaddlePaddle opens the mask face detection and classification pre training model. As long as developers have basic python programming capabilities, they can quickly build local or serving service invocation models. If you have a certain mobile app development capability, you can also quickly deploy the model to the mobile terminal.
Top algorithms and data
In this scheme, the model for face recognition is developed based on Baidu's paper pyramid box at the international top computer vision conference ECCV 2018 in 2018. It is trained based on the self-developed open-source deep learning platform for flying oars, and the algorithm can run efficiently on some devices with limited computing power through model miniaturization technologies such as paddy slim.
The face detection and classification model of face masks can recognize and label the face with and without masks in the environment of high-density people flow in public places. Based on this pre training model, developers can quickly develop their own scene models with only a small amount of code.
The model can be widely used in different types of areas such as customs, railway station, entrance of park area, etc. Meanwhile, it can provide server and mobile version, so that developers can integrate into different types of hardware platforms to meet different scenarios. It is very suitable for the control of key areas, as well as the timely warning of people who do not wear masks.
If mask face detection and classification model are widely used, the statistical data of detection results can also provide a basis for more in-depth research. Baidu said the test results can play a greater role in epidemic analysis, smart city, smart community and other scenarios.
During this period, many technology companies have launched AI algorithms for body temperature detection, face recognition and other work. The method proposed by Baidu is the first open-source face detection and classification model for face masks. From the deep learning technology platform of the propeller, to the efficient and accurate face detection and recognition algorithm, to the hardware deployment scheme, the method proposed by Baidu can achieve complete and efficient overall cooperation with other tools.
How to use practice
The whole pre training model only requires the installation of paddlepaddle and paddehub, and only needs to understand the basic Python to run. The following short video shows our face detection model with masks:
As shown above, the simplest local inference is that with only five lines of code, we can process face mask detection on our own computer. To show the effect, we set each image to stay for 2 seconds. In fact, when we use CPU, the detection is basically real-time, and the inference speed is very fast. The following is the core code to call the pre training model, where we put a test image in the current folder:
Importpadlehub ashub # load model, this example is server-side model pyramidbox_lite_server_mask # mobile-side model parameters can be replaced by pyramidbox_lite_mobile_maskmodule=hub.Module (name=" pyramidbox_liteserver_mask ")#############################################################
Baidu provides an example code for face detection and classification of masks. Through the notebook file, we can more vividly understand the whole process of using the model:
More importantly, as a complete open source work, in addition to local inference, it also needs to consider how to deploy the model to servers or mobile devices. If it can be deployed to various platforms quickly, it really means that it can be used as the basic tool of "war epidemic".
At present, Baidu has provided two pre training models, namely, the server port mask face detection and classification model "pyreidbox ﹣ Lite ﹣ server ﹣ mask", and the mobile port mask face detection and classification model "pyreidbox ﹣ Lite ﹣ mobile ﹣ mask", which can meet various downstream tasks.
1. One step deployment of server
With the help of paddlehub, the deployment on the server side is also very simple. You can start face mask detection and classification model on the server directly with a command line:
hub serving start -m pyramidbox_lite_server_mask -p 8866
Yes, on the server side, it's all right. Compared with manually configuring various parameters or calling various frameworks, the paddlehub deployment server is very easy to use.
As long as the deployment is completed on the server side, the remaining calls on the client side will not have much problem. As follows, baidu shows an example of calling the server to make inference: making a list of images to be predicted, making inference requests, returning and saving inference results.
# coding: utf8 import requests import json import base64 import os # specifies the picture to be detected and generates a list [" image ", img_1],(" image ", img_2],... ] file_list =[" test.jpg "] files =[" image ",(" image "),(open (item," rb "))) foriteminfile_list ]# specify detection method as pyramidbox_lite_server_mask and send post request url =" http://127.0.0.1:8866/predict/image/pyramidbox_lite_server_mask "r = requests.post (url=, files=s) ults= eval (j.son [" results "]#)####]################################## ent =4, ensure_ascii = False)
It is believed that as long as there are some Python foundations, it is no problem to predict locally and deploy to the server. The paddlehub of the paddle has helped us do a variety of processing.
2. Deploy to mobile terminal
Paddy Lite is the end-to-side reasoning engine of the propeller, which is specially oriented to the model reasoning deployment of the mobile end. If we need to embed face detection and classification models of masks into mobile devices such as mobile phones, the end-to-side reasoning engine like paddy Lite can save us a lot of work.
There are only three steps to deploy the face detection and classification model of face masks on the mobile end: ① download the prediction database, and paddy Lite will provide the compiled prediction database; ② optimize the model, and use the model optimization tool to realize the model optimization; ③ realize the call through the prediction API.
Introduction to paddy Lite:https://github.com/PaddlePaddle/Paddle-Lite/releases/v2.2.0/
One of the most important is the mobile API call method. For the specific implementation, please refer to the example address of paddy Lite given below.
// read image cv:: Matimg=imread (img_path, cv: IMREAD_COLOR);// loading face detection or mask wearing discrimination model MobileConfig config; config.set _model_dir (model_dir); Paddle Preditor*Predicator=CreatePaddlePredicator
The example address of face recognition and mask wearing judgment deployed on the mobile terminal is:https://github.com/PaddlePaddle/Paddle-Lite/tree/develop/lite/demo/cxx
Help developers to fight the epidemic together
The R & D personnel of the face mask detection and classification model project introduced to heart of the machine that Baidu had been frequently exposed to the technical requirements fed back by the community and partners during the Spring Festival, and quickly launched the actions of docking and application development. To this end, Baidu has set up a technical R & D team for the new crown epidemic. After demonstration, developers agree that the final finished product should be open-source to enable more developers.
Baidu quickly organized a production and research team composed of multiple departments. With the cooperation of multiple departments, engineers quickly entered the stage of scheme implementation.
Due to the traffic control in many cities, most people participate in the development of the project in the form of remote development. Baidu R & D personnel said that thanks to the efficient collaborative office and development system within baidu, the overall R & D progress can maintain rapid iteration.
Previously, only a few manufacturers were able to provide landing solutions for face detection models of face masks, and the recognition effects of these technologies were not the same under dense flow of people. However, due to the lack of experience in data set and model development, many solutions are unable to start when faced with subdivision scenarios such as parks and gateways.
Face detection and classification model of mask can be the basis of many applications. In addition to the screening of wearing in public places, the application of detecting whether the mask is worn correctly and monitoring body temperature can be realized faster by using this ability. In addition to the open source model, baidu also provides a secondary development tool component. We can develop a more suitable model for ourselves.
In terms of supported hardware, the model can run efficiently on Baidu official and third-party certified hardware platform. In addition, the first mock exam also supports the mainstream hardware platforms in the market.
In addition to the just open source algorithm, Baidu's AI technology has played a role in many areas of fighting the new crown epidemic. The company actively cooperates with government departments to launch the official new pneumonia doctor consultation platform in Beijing, launch the "fever clinic map", open the channel of eliminating rumors of epidemic situation, and open the intelligent outbound call platform to the first-line epidemic prevention and control institutions in various regions to provide support for AI technology at the grassroots level.
During the Spring Festival novel coronavirus released a complete Baidu AI temperature measurement system and quickly put it into the prevention and control of the new coronavirus epidemic situation. In Beijing Qinghe railway station, since the deployment of Baidu AI temperature measurement system at the end of January, as of February 8, it has completed the rapid temperature detection of more than 32000 people, found more than 190 suspected cases of abnormal temperature, and the staff has conducted manual re inspection.
Baidu R & D personnel told us that from the current needs received, in the work of epidemic prevention and control, three key areas of computer vision, voice and natural language processing are all under development. Among them, automatic recognition of CT results for auxiliary diagnosis and other tools has played an important role in the work of confirmed cases.
Open source way, can let the whole community cooperate with the fastest speed. We hope that through the efforts of developers, this new technology can affect more people and enterprises, and make more contributions to the fight against the new crown epidemic.