運用Python 3.8.1版本,爬取網絡數據,基於卷積神經網絡(CNN)The principle of image processing,Build a mask recognition technology training set,構建人臉識別系統,Finally, establish a management system for the whereabouts of teachers and students in colleges and universities.
Collect from the web,得到3073Zhang different gender、Age and photos of people wearing masks in different scenes,And the pictures of faces without masks are selected from3249張圖片.This is the dataset for this study,By preprocessing the dataset,to train a model for face mask detection.
二、確定The overall operation process of face and mask recognition
圖1
(1)Detect and align faces in a dataset
Because the proportion of face and mask in some photos is relatively small,other parts such as hands、Shoulders etc take up a lot of space,These are all noise to the model,會增加CPUis computationally expensive and interferes with the model.So we need to process the obtained photos,crop out the face.我們利用OpenCv和dlibFace detection and alignment on the dataset,for subsequent training of the model.Face detection refers to circle the faces in a picture,That is to find the location of the face,Face alignment is based on detected faces,Automatically find landmark features such as face contours and eyes, nose and mouth.我們使用dlibFaces on the dataset68個特征點的檢測,and align faces,Finally, print the number of faces on each photo and the number of aligned faces.
圖2 檢測人臉68個特征點
圖3 Number of faces and aligned faces
Because there is a certain error in the identification,So you need to filter the cropped photos,Manually delete very few photos with inaccurate alignment,and rename the photos of the dataset,Facilitates the creation of subsequent dataset paths.Finally got a photo of wearing a mask1010張,as a positive sample for the model,Photos without masks3030張,as a negative sample for the model,正負樣本的比例為1:3.
圖4 Cropped positive and negative sample set
(2)Positive and negative sample data set grayscale processing and pixel processing
Grayscale processing of datasets can enhance image contrast,Increase the dynamic range of the picture,讓圖像更清晰,特征更明顯,Can better train the model.除此之外,It is also necessary to set the respective photo pixels of the positive and negative samples to the same value,The pixels of the positive sample dataset are optimally set to20x20,Such a model has higher training accuracy,The negative sample dataset pixels should be no lower than50x50,This can speed up model training,Here we adjust the dataset pixels of negative samples to80 x80.最後通過cmdcommand to generate image paths with and without masks, respectivelytxt文件.
圖5 灰度、Positive and negative samples after pixel processing
(3) Train a face mask dataset model
The cascade classifier is trained usingopencv3.4.1版中的opencv_createsamples.exe和opencv_traincascade.exe兩個程序.opencv_traincascade Support not only support HaarFeatures also support LBP特征,Other features can also be enhanced.The accuracy of the above two features during detection depends on the training parameters during training and the quality of the training data.This time, when we trained the mask recognition model, we extractedHaar特征,Its main advantage lies in its computing relatively quickly.可以用opencv_createsamplesto prepare test data and positive sample data for training, These data can beopencv_traincascade 程序支持.
在測試時,We also added the recognition of the face and nose,If also namely when recognition to face recognition to the nose,show as not wearing a mask,Whether the wearing of masks can be more effectively standardized.
圖6 Practical rendering of mask recognition system
(4)Mask recognition training model evaluation
The results of running the training set are as follows:
===== TRAINING 4-stage =====
<BEGIN
POS count : consumed 800 : 813
NEG count : acceptanceRatio 2600 : 0.00584079
Precalculation time: 25.945
如圖所示,執行該命令時,Some parameter information is output by the terminal first.Then output the training information of each strong classifier in the cascade classifier,我們設置的numStages為10,So a total of10個強分類器:0-stage至9-stage.The picture is the4Information about strong classifiers.We analyze this information separately as follows:
===== TRAINING 4-stage =====
<BEGIN
Indicates the start of training4Strong Classifier.
【POS count : consumed800: 813】
When training this level strong classifier,能夠使用的800The positive sample images are from813selected from a set of positive sample images,It means that the positive samples that have not been identified at this time have13個.The recognition rate at this time is98.4%(800/813=0.984).
【NEG count : acceptanceRatio 2600 : 0.00584079】
可用2600negative sample images to train this level strong classifier,該數是opencv_traincascade.exe命令中參數numNeg指定的數量,後面的0.00584079Indicates that those predicted by the current cascade classifier are predicted to be positive samples and are actually negative samples2600how many negative sample images the image is obtained from.currently received4個強分類器:O-stage、1-stage、2-stage、3-stage.when the first training5個強分類器4-stage運行結束後,這5The maximum error rate of a cascade of strong classifiers is:0.25x0.25x0.25x0.25=0.000976,requirements have been met,無需繼續訓練,系統會停止運行.
【Precalculation time: 25.945】
這表示,Before building a strong classifier,We have calculated some eigenvalues,The time consumed by the pre-computed eigenvalues at this time.該值由opencv_traincascade.exe命令中的參數precalcValBufSize和precalcldxBufSize決定,If we set a larger memory here,more eigenvalues can be stored,At the same time the longer it takes.
Indicates that the strong classifier of this level has been obtained at this time,Because the recognition rate and error rate both meet the requirements,So the strong classifier training session.
【Training until now has taken 0 days 0 hours 39 minutes 53 seconds】
表示到目前為止,When training cascaded classifiers39分53秒.此時,The training gets the cascaded classifier data we need,We can use it to recognize faces.
The main work of this project can be summarized as the following points:
一、基於卷積神經網絡的人臉識別.達到以下效果:
1、Identify faces from video,並實時標出面部特征點.2、建cv2攝像頭對象,We use the computer's own camera(If installing an external camera,則自動切換到外部攝像頭).3、Multi-frame continuous comparison recognition for high-definition video、Decode video data from surveillance equipment,and separate the dataframe、Image data forming each frame of video,Thereby, the face recognition rate has been greatly improved exponentially..4、Set the data delay per frame to1ms,Use the face detector to detect the face in each frame of the image and do grayscale processing,and output the number of faces.5、Draw boxes for each face location,顯示識別結果.6、Add shortcut functions and add button descriptions on the identification page:按下s鍵截圖保存,按下q鍵退出.
二、口罩識別
Based on the recognition of the convolutional neural network mask.For the three detected cases:①戴口罩(捂住口鼻)②戴口罩(not covering mouth and nose)③Made without a maskno mask ;no mask; have mask的判斷.
三、Established an epidemic prevention and control platform for teachers and students,Real-time query of personal access to public places on campus and access to and from the campus.Provides a platform for verification and oversight.
在此對Yuling Zhang對本文所作的貢獻表示誠摯感謝,She specializes in deep learning、數據采集、回歸預測.
最受歡迎的見解
1.R語言實現CNN(卷積神經網絡)模型進行回歸
2.r語言實現擬合神經網絡預測和結果可視化
3.python用遺傳算法-神經網絡-模糊邏輯控制算法對樂透分析
4.R語言結合新冠疫情COVID-19股票價格預測:ARIMA,KNN和神經網絡時間序列分析
5.Python TensorFlow循環神經網絡RNN-LSTM神經網絡預測股票市場價格時間序列和MSE評估准確性
6.Matlab用深度學習長短期記憶(LSTM)神經網絡對文本數據進行分類
7.用於NLP的seq2seq模型實例用Keras實現神經機器翻譯
8.R語言用FNN-LSTM假近鄰長短期記憶人工神經網絡模型進行時間序列深度學習預測
9.Python用RNN循環神經網絡:LSTM長期記憶、GRU門循環單元、回歸和ARIMA對COVID-19新冠疫情新增人數時間序列預測