Skip to content

Commit 9729426

Browse files
author
Wanbin Song
committed
Initial commit
0 parents  commit 9729426

File tree

81 files changed

+458
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+458
-0
lines changed

AnchorMask.mat

957 Bytes
Binary file not shown.

COVID19_LabelMaskAutomation.mlx

977 KB
Binary file not shown.

COVID19_LiveWebcamMask.mlx

5.03 KB
Binary file not shown.

COVID19_Mask_SSD.mat

42.5 MB
Binary file not shown.

COVID19_Mask_yolo.mat

97.6 MB
Binary file not shown.

COVID19_TestStillImage.mlx

758 KB
Binary file not shown.

COVID19_TrainMaskDetection.mlx

10.7 KB
Binary file not shown.

COVID19_VideoRunning.mlx

4.19 KB
Binary file not shown.

FaceMaskDetection.m

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<MATLABProject xmlns="http://www.mathworks.com/MATLABProjectFile" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"/>

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+

README.md

+87

SampleMaskData/a01.jpg

1.63 MB

SampleMaskData/a02.jpg

1.53 MB

SampleMaskData/a03.jpg

1.73 MB

SampleMaskData/mw_wanbin2.jpg

479 KB

SampleMaskData/mw_wanbin3.jpg

35.1 KB

SampleMaskData/mw_wanbin7.jpg

24 KB

SampleMaskData/mw_wanbin9.jpg

24.1 KB

SampleMaskData/zz.jpg

1.37 MB

images/.gitkeep

Whitespace-only changes.

images/image1.png

172 KB

images/image2.png

214 KB

images/image3.png

722 KB

images/image4.png

673 KB

predictFace.m

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info MetadataType="distributed" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info Name="gitSubmission" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info ReadOnly="1" SingleValued="1" DataType="None" Name="분류" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info ReadOnly="READ_ONLY" Name="아티팩트" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info ReadOnly="READ_ONLY" Name="편의" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info ReadOnly="READ_ONLY" Name="파생" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info ReadOnly="READ_ONLY" Name="설계" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info ReadOnly="READ_ONLY" Name="없음" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info ReadOnly="READ_ONLY" Name="기타" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info ReadOnly="READ_ONLY" Name="테스트" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version='1.0' encoding='UTF-8'?>
2+
<Info>
3+
<Category UUID="FileClassCategory">
4+
<Label UUID="design" />
5+
</Category>
6+
</Info>

0 commit comments

Comments
 (0)