├── AnchorMask.mat ├── COVID19_LabelMaskAutomation.mlx ├── COVID19_LiveWebcamMask.mlx ├── COVID19_Mask_SSD.mat ├── COVID19_Mask_yolo.mat ├── COVID19_TestStillImage.mlx ├── COVID19_TrainMaskDetection.mlx ├── COVID19_VideoRunning.mlx ├── FaceMaskDetection.m ├── GitSubmission.prj ├── LICENSE ├── MaskLabel.m ├── README.md ├── SampleMaskData ├── a01.jpg ├── a02.jpg ├── a03.jpg ├── mw_wanbin2.jpg ├── mw_wanbin3.jpg ├── mw_wanbin7.jpg ├── mw_wanbin9.jpg └── zz.jpg ├── images ├── .gitkeep ├── image1.png ├── image2.png ├── image3.png └── image4.png ├── predictFace.m ├── resources └── project │ ├── Project.xml │ ├── ProjectData.type.Info.xml │ ├── Root.type.Categories │ ├── FileClassCategory.type.Category.xml │ └── FileClassCategory.type.Category │ │ ├── artifact.type.Label.xml │ │ ├── convenience.type.Label.xml │ │ ├── derived.type.Label.xml │ │ ├── design.type.Label.xml │ │ ├── none.type.Label.xml │ │ ├── other.type.Label.xml │ │ └── test.type.Label.xml │ ├── Root.type.Files │ ├── AnchorMask.mat.type.File.xml │ ├── COVID19_LabelMaskAutomation.mlx.type.File.xml │ ├── COVID19_LiveWebcamMask.mlx.type.File.xml │ ├── COVID19_Mask_SSD.mat.type.File.xml │ ├── COVID19_Mask_yolo.mat.type.File.xml │ ├── COVID19_TestStillImage.mlx.type.File.xml │ ├── COVID19_TrainMaskDetection.mlx.type.File.xml │ ├── COVID19_VideoRunning.mlx.type.File.xml │ ├── FaceMaskDetection.m.type.File.xml │ ├── LICENSE.type.File.xml │ ├── MaskLabel.m.type.File.xml │ ├── README.md.type.File.xml │ ├── SampleMaskData.type.File.xml │ ├── SampleMaskData.type.File │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── a01.jpg.type.File.xml │ │ ├── a02.jpg.type.File.xml │ │ ├── a03.jpg.type.File.xml │ │ ├── mw_wanbin2.jpg.type.File.xml │ │ ├── mw_wanbin3.jpg.type.File.xml │ │ ├── mw_wanbin7.jpg.type.File.xml │ │ ├── mw_wanbin9.jpg.type.File.xml │ │ └── zz.jpg.type.File.xml │ ├── images.type.File.xml │ ├── images.type.File │ │ ├── .gitkeep.type.File.xml │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── image1.png.type.File.xml │ │ ├── image2.png.type.File.xml │ │ ├── image3.png.type.File.xml │ │ └── image4.png.type.File.xml │ ├── models.type.File.xml │ ├── models.type.File │ │ ├── 1.type.DIR_SIGNIFIER.xml │ │ ├── net_face_yolo.caffemodel.type.File.xml │ │ ├── net_face_yolo.mat.type.File.xml │ │ └── net_face_yolo_deploy.prototxt.type.File.xml │ ├── predictFace.m.type.File.xml │ ├── sample.jpg.type.File.xml │ ├── sample.mp4.type.File.xml │ ├── ssd_detect.m.type.File.xml │ └── yolov2_detect.m.type.File.xml │ └── uuid-46457eea-17e4-4898-91f2-7e65fb408e9f.xml ├── sample.jpg ├── sample.mp4 ├── ssd_detect.m └── yolov2_detect.m /AnchorMask.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/AnchorMask.mat -------------------------------------------------------------------------------- /COVID19_LabelMaskAutomation.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/COVID19_LabelMaskAutomation.mlx -------------------------------------------------------------------------------- /COVID19_LiveWebcamMask.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/COVID19_LiveWebcamMask.mlx -------------------------------------------------------------------------------- /COVID19_Mask_SSD.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/COVID19_Mask_SSD.mat -------------------------------------------------------------------------------- /COVID19_Mask_yolo.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/COVID19_Mask_yolo.mat -------------------------------------------------------------------------------- /COVID19_TestStillImage.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/COVID19_TestStillImage.mlx -------------------------------------------------------------------------------- /COVID19_TrainMaskDetection.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/COVID19_TrainMaskDetection.mlx -------------------------------------------------------------------------------- /COVID19_VideoRunning.mlx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/COVID19_VideoRunning.mlx -------------------------------------------------------------------------------- /FaceMaskDetection.m: -------------------------------------------------------------------------------- 1 | classdef FaceMaskDetection < vision.labeler.AutomationAlgorithm 2 | 3 | properties(Constant) 4 | 5 | Name = 'Face Mask Detection'; 6 | Description = 'This is a automatic Mask labeling algorithm.'; 7 | 8 | UserDirections = {... 9 | ['Automation algorithms are a way to automate manual labeling ' ... 10 | 'tasks. This AutomationAlgorithm is a template for creating ' ... 11 | 'user-defined automation algorithms. Below are typical steps' ... 12 | 'involved in running an automation algorithm.'], ... 13 | ['Run: Press RUN to run the automation algorithm. '], ... 14 | ['Review and Modify: Review automated labels over the interval ', ... 15 | 'using playback controls. Modify/delete/add ROIs that were not ' ... 16 | 'satisfactorily automated at this stage. If the results are ' ... 17 | 'satisfactory, click Accept to accept the automated labels.'], ... 18 | ['Change Settings and Rerun: If automated results are not ' ... 19 | 'satisfactory, you can try to re-run the algorithm with ' ... 20 | 'different settings. In order to do so, click Undo Run to undo ' ... 21 | 'current automation run, click Settings and make changes to ' ... 22 | 'Settings, and press Run again.'], ... 23 | ['Accept/Cancel: If results of automation are satisfactory, ' ... 24 | 'click Accept to accept all automated labels and return to ' ... 25 | 'manual labeling. If results of automation are not ' ... 26 | 'satisfactory, click Cancel to return to manual labeling ' ... 27 | 'without saving automated labels.']}; 28 | end 29 | 30 | properties 31 | 32 | AllCategories = {'background'}; 33 | FireName 34 | count 35 | 36 | 37 | end 38 | 39 | methods 40 | function isValid = checkLabelDefinition(algObj, labelDef) 41 | 42 | disp(['Executing checkLabelDefinition on label definition "' labelDef.Name '"']) 43 | 44 | if (strcmpi(labelDef.Name, 'Mask') && labelDef.Type == labelType.Rectangle) 45 | isValid = true; 46 | algObj.FireName = labelDef.Name; 47 | algObj.AllCategories{end+1} = labelDef.Name; 48 | end 49 | 50 | 51 | end 52 | 53 | function isReady = checkSetup(algObj) 54 | 55 | isReady = ~isempty(algObj); 56 | 57 | 58 | 59 | end 60 | 61 | function settingsDialog(algObj) 62 | 63 | disp('Executing settingsDialog') 64 | 65 | end 66 | end 67 | 68 | methods 69 | 70 | function initialize(algObj, I) 71 | 72 | disp('Executing initialize on the first image frame') 73 | 74 | end 75 | 76 | function autoLabels = run(algObj, I) 77 | 78 | disp('Executing run on image frame') 79 | 80 | [labelCord, label] = MaskLabel(I, algObj); 81 | autoLabels.Name = char(label); 82 | autoLabels.Type = labelType('Rectangle'); 83 | autoLabels.Position = labelCord; 84 | algObj.count = algObj.count+1; 85 | 86 | end 87 | 88 | function terminate(algObj) 89 | 90 | disp('Executing terminate') 91 | 92 | end 93 | end 94 | end 95 | % Copyright 2020 The MathWorks, Inc. -------------------------------------------------------------------------------- /GitSubmission.prj: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020, The MathWorks, Inc. 2 | All rights reserved. 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 5 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 6 | 3. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings. 7 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /MaskLabel.m: -------------------------------------------------------------------------------- 1 | function [labelCord, label] = MaskLabel(I, ~) 2 | ori_sz = size(I, [1 2]); 3 | re_sz = [448 448]; 4 | img = imresize(I, re_sz); 5 | scale = ori_sz./re_sz; 6 | 7 | bbox = predictFace(img, 'net_face_yolo.mat'); 8 | bbox(:,4) = bbox(:,4)./2+20; 9 | bbox(:,2) = bbox(:,2)+bbox(:,4)-20; 10 | bbox(:,3) = bbox(:,3)+10; 11 | labelCord = bboxresize(round(bbox),scale); 12 | label = 'Mask'; 13 | % Copyright 2020 The MathWorks, Inc. 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Mask Detection Demo using Deep Learning 2 | ============= 3 | Final Result
4 | 5 | **Note** 6 | The license for this package is available in the license.txt file. By running the COVID19_LabelMaskAutomation.mlx script, you will be downloading certain third party content which is licensed under separate license agreements. 7 | 8 | **Background** 9 | 10 | Coronavirus disease (COVID-19) is a new strain of disease in humans discovered in 2019 that has never been identified in the past. 11 | Coronavirus is a large family of viruses that causes illness in patients ranging from common cold to advanced respiratory syndromes such as Middle East Respiratory Syndrome (MERS-COV) and Severe Acute Respiratory Syndrome (SARS-COV). 12 | Many people are currently affected and are being treated across the world causing a global pandemic. 13 | Several countries have declared a national emergency and have quarantined millions of people. 14 | 15 | To be a part of the worldwide trend, I've created a CORONA mask detection deep learning model. 16 | It includes semi-auto data labeling, model training, and GPU code generation for real-time inference. 17 | Our MathWorks Korea staffs were willing to share their selfies(Non-distributable) with masks while working from home, so I can create the dataset easily. 18 | Unfortunately, the dataset is not distributable, so you need to create your own dataset for training your own model. I've included some of sample data in SampleMaskData folder. 19 | 20 | Demo Workflow 21 | ------------- 22 | Demo Workflow
23 | * Label image 24 | * Automated labeling with pretrained model 25 | * Use image Labeler for interactive process automation 26 | * Train Object detection model 27 | * SSD(Single-Shot Multibox Detector) 28 | * YOLOv2(You Only Look Once v2) 29 | * Generate CUDA mex for inference speed acceleration 30 | 31 | Part1 - Prepare Data 32 | ------------- 33 | Ground Truth Labeling
34 | 35 | #### COVID19_LabelMaskAutomation.mlx 36 | This file includes the basic of ground truth labeling and how we semi-automate the ground truth labeling with pretrained open source model. 37 | 38 | Part2 - Train Model 39 | ------------- 40 | #### COVID19_TrainMaskDetection.mlx 41 | This file includes the entire training process from data augmentation, architecture creation and evaluation. 42 | It includes high-level APIs for SSD(Single Shot Multibox Detector) and YOLOv2(You Only Look Once) network architecture for the comparison. 43 | 44 | If you complete the training, we need to test the trained model for still image, video and live webcam streaming data. 45 | For the each task instances, see below codes for the model running. 46 | #### COVID19_TestStillImage.mlx 47 | - Test trained model for still image. 48 | #### COVID19_VideoRunning.mlx 49 | - Test trained model for existing video. 50 | #### COVID19_LiveWebcamMask.mlx 51 | - Test trained model for live webcam object image. The example requires MATLAB Support Package for USB Webcams. If you do not have the required support packages installed, then the software provides a download link. 52 | 53 | Part3 - Deploy System 54 | ------------- 55 | Inference Speed Comparision
56 | 57 | ### COVID19_TrainMaskDetection.mlx 58 | In the training code, few lines of code is included for code generation. 59 | Prerequisites 60 | - CUDA enabled NVIDIA GPU with compute capability 3.2 or higher. 61 | - NVIDIA CUDA toolkit and driver. 62 | - NVIDIA cuDNN library. 63 | - Environment variables for the compilers and libraries. For information on the supported versions of the compilers and libraries, see [Third-party Products](https://www.mathworks.com/help/gpucoder/gs/install-prerequisites.html) (GPU Coder). For setting up the environment variables, see [Setting Up the Prerequisite Products](https://www.mathworks.com/help/gpucoder/gs/setting-up-the-toolchain.html) (GPU Coder). 64 | - GPU Coder Interface for Deep Learning Libraries support package. To install this support package, use the Add-On Explorer. 65 | 66 | Requires 67 | - [MATLAB](https://www.mathworks.com/products/matlab.html) 68 | - [Deep Learning Toolbox](https://www.mathworks.com/products/deep-learning.html) 69 | - [Image Processing Toolbox](https://www.mathworks.com/products/image.html) 70 | - [Computer Vision Toolbox](https://www.mathworks.com/products/computer-vision.html) 71 | - [Parallel Computing Toolbox](https://www.mathworks.com/products/parallel-computing.html) 72 | - [MATLAB Coder](https://www.mathworks.com/products/matlab-coder.html) 73 | - [GPU Coder](https://www.mathworks.com/products/gpu-coder.html) 74 | 75 | Support Packages 76 | - [Deep Learning Toolbox Importer for Caffe Models](https://www.mathworks.com/matlabcentral/fileexchange/61735-deep-learning-toolbox-importer-for-caffe-models) 77 | - [MATLAB Support Package for USB Webcams](https://www.mathworks.com/matlabcentral/fileexchange/45182-matlab-support-package-for-usb-webcams) 78 | - [GPU Coder Interface for Deep Learning Libraries](https://kr.mathworks.com/matlabcentral/fileexchange/68642-gpu-coder-interface-for-deep-learning-libraries) 79 | 80 | Note that this demo is developed based on Windows operating system, and few minor issues are expected with other OS. 81 | 82 | For more information on Deep Learning in MATLAB 83 | ------------- 84 | [![View COVID19-Face-Mask-Detection-using-deep-learning on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://kr.mathworks.com/matlabcentral/fileexchange/76758-covid19-face-mask-detection-using-deep-learning) 85 | 86 | **[Download a free MATLAB trial for Deep Learning](https://www.mathworks.com/products/deep-learning.html)** 87 | 88 | [View Webinar for the entire model development (Korean)](https://www.youtube.com/watch?v=EwCWgsjzR9E) 89 | 90 | Copyright 2020 The MathWorks, Inc. 91 | -------------------------------------------------------------------------------- /SampleMaskData/a01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/SampleMaskData/a01.jpg -------------------------------------------------------------------------------- /SampleMaskData/a02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/SampleMaskData/a02.jpg -------------------------------------------------------------------------------- /SampleMaskData/a03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/SampleMaskData/a03.jpg -------------------------------------------------------------------------------- /SampleMaskData/mw_wanbin2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/SampleMaskData/mw_wanbin2.jpg -------------------------------------------------------------------------------- /SampleMaskData/mw_wanbin3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/SampleMaskData/mw_wanbin3.jpg -------------------------------------------------------------------------------- /SampleMaskData/mw_wanbin7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/SampleMaskData/mw_wanbin7.jpg -------------------------------------------------------------------------------- /SampleMaskData/mw_wanbin9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/SampleMaskData/mw_wanbin9.jpg -------------------------------------------------------------------------------- /SampleMaskData/zz.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/SampleMaskData/zz.jpg -------------------------------------------------------------------------------- /images/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/images/.gitkeep -------------------------------------------------------------------------------- /images/image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/images/image1.png -------------------------------------------------------------------------------- /images/image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/images/image2.png -------------------------------------------------------------------------------- /images/image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/images/image3.png -------------------------------------------------------------------------------- /images/image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/images/image4.png -------------------------------------------------------------------------------- /predictFace.m: -------------------------------------------------------------------------------- 1 | function selectedBbox = predictFace(img_rz, matfile) 2 | %#codegen 3 | 4 | % This function detects the traffic signs in the image using Detection Network 5 | % (modified version of Yolo) and recognizes(classifies) using Recognition Network 6 | % 7 | % Inputs : 8 | % 9 | % im : Input test image 10 | % 11 | % Outputs : 12 | % 13 | % selectedBbox : Detected bounding boxes 14 | % idx : Corresponding classes 15 | 16 | % Copyright 2017-2018 The MathWorks, Inc. 17 | 18 | coder.gpu.kernelfun; 19 | 20 | % Converting into BGR format 21 | img_rz = img_rz(:,:,3:-1:1); 22 | img_rz = im2single(img_rz); 23 | 24 | %% TSD 25 | persistent detectionnet; 26 | if isempty(detectionnet) 27 | detectionnet = coder.loadDeepLearningNetwork(matfile,'Detection'); 28 | end 29 | 30 | predictions = detectionnet.predict(img_rz);%, 'executionenvironment', 'cpu'); 31 | 32 | %% Convert predictions to bounding box attributes 33 | classes = 1; 34 | num = 2; 35 | side = 11; 36 | thresh = 0.2; 37 | [h,w,~] = size(img_rz); 38 | 39 | boxes = single(zeros(0,4)); 40 | probs = single(zeros(0,1)); 41 | for i = 0:(side*side)-1 42 | for n = 0:num-1 43 | p_index = side*side*classes + i*num + n + 1; 44 | scale = predictions(p_index); 45 | prob = zeros(1,classes+1); 46 | for j = 0:classes 47 | class_index = i*classes + 1; 48 | tempProb = scale*predictions(class_index+j); 49 | if tempProb > thresh 50 | 51 | row = floor(i / side); 52 | col = mod(i,side); 53 | 54 | box_index = side*side*(classes + num) + (i*num + n)*4 + 1; 55 | bxX = (predictions(box_index + 0) + col) / side; 56 | bxY = (predictions(box_index + 1) + row) / side; 57 | 58 | bxW = (predictions(box_index + 2)^2); 59 | bxH = (predictions(box_index + 3)^2); 60 | 61 | prob(j+1) = tempProb; 62 | probs = [probs;tempProb]; 63 | 64 | boxX = (bxX-bxW/2)*w+1; 65 | boxY = (bxY-bxH/2)*h+1; 66 | boxW = bxW*w; 67 | boxH = bxH*h; 68 | boxes = [boxes; boxX,boxY,boxW,boxH]; 69 | end 70 | end 71 | end 72 | end 73 | 74 | %% Run Non-Maximal Suppression on the detected bounding boxess 75 | coder.varsize('selectedBbox',[98, 4],[1 0]); 76 | [selectedBbox,~] = selectStrongestBbox(round(boxes),probs); 77 | 78 | % Copyright 2020 The MathWorks, Inc. -------------------------------------------------------------------------------- /resources/project/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/ProjectData.type.Info.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/artifact.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/convenience.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/derived.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/design.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/none.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/other.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Categories/FileClassCategory.type.Category/test.type.Label.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/AnchorMask.mat.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/COVID19_LabelMaskAutomation.mlx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/COVID19_LiveWebcamMask.mlx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/COVID19_Mask_SSD.mat.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/COVID19_Mask_yolo.mat.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/COVID19_TestStillImage.mlx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/COVID19_TrainMaskDetection.mlx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/COVID19_VideoRunning.mlx.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/FaceMaskDetection.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/LICENSE.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/MaskLabel.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/README.md.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/a01.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/a02.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/a03.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/mw_wanbin2.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/mw_wanbin3.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/mw_wanbin7.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/mw_wanbin9.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/SampleMaskData.type.File/zz.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/images.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/images.type.File/.gitkeep.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/images.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/images.type.File/image1.png.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/images.type.File/image2.png.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/images.type.File/image3.png.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/images.type.File/image4.png.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/models.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/models.type.File/1.type.DIR_SIGNIFIER.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/models.type.File/net_face_yolo.caffemodel.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/models.type.File/net_face_yolo.mat.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/models.type.File/net_face_yolo_deploy.prototxt.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/predictFace.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/sample.jpg.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/sample.mp4.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/ssd_detect.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/Root.type.Files/yolov2_detect.m.type.File.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /resources/project/uuid-46457eea-17e4-4898-91f2-7e65fb408e9f.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /sample.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/sample.jpg -------------------------------------------------------------------------------- /sample.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matlab-deep-learning/COVID19-Face-Mask-Detection-using-deep-learning/5c50a1c19d51f64a799ce88cf6ab12aa7adbd523/sample.mp4 -------------------------------------------------------------------------------- /ssd_detect.m: -------------------------------------------------------------------------------- 1 | function [bbox,score, label] = ssd_detect(in, th) 2 | persistent ssdObj; 3 | 4 | if isempty(ssdObj) 5 | ssdObj = coder.loadDeepLearningNetwork('COVID19_Mask_SSD.mat'); 6 | end 7 | 8 | [bbox, score, label] = ssdObj.detect(in,'Threshold',th); 9 | %Copyright 2020 The MathWorks, Inc. 10 | -------------------------------------------------------------------------------- /yolov2_detect.m: -------------------------------------------------------------------------------- 1 | function [bbox,score, label] = yolov2_detect(in, th) 2 | persistent yolov2Obj; 3 | 4 | if isempty(yolov2Obj) 5 | yolov2Obj = coder.loadDeepLearningNetwork('COVID19_Mask_yolo.mat'); 6 | end 7 | 8 | [bbox, score, label] = yolov2Obj.detect(in,'Threshold',th); 9 | %Copyright 2020 The MathWorks, Inc. 10 | 11 | --------------------------------------------------------------------------------