Skip to content

Commit 861882a

Browse files
committed
Adding demo files
0 parents  commit 861882a

50 files changed

Lines changed: 1609 additions & 0 deletions

File tree

Some content is hidden

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

LICENSE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 2019-2020, The MathWorks, Inc.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
10+
* Redistributions in binary form must reproduce the above copyright notice,
11+
this list of conditions and the following disclaimer in the documentation
12+
and/or other materials provided with the distribution.
13+
* In all cases, the software is, and all modifications and derivatives of the
14+
software shall be, licensed to you solely for use in conjunction with
15+
MathWorks products and service offerings.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# FaceGenderAgeEmotionDetection
2+
Demo for face, gender, age and emotion detection (all using Deep Learning), together with some Computer Vision features to enhance detection and tracking.
3+
4+
Note all these networks have their origins in research. **Use preferably with a GPU.**
5+
6+
## Requirements:
7+
### In MATLAB
8+
* [Deep Learning Toolbox Importer for Caffe Models](https://www.mathworks.com/matlabcentral/fileexchange/61735-deep-learning-toolbox-importer-for-caffe-models)
9+
* [MATLAB Support Package for USB Webcams](https://www.mathworks.com/matlabcentral/fileexchange/45182-matlab-support-package-for-usb-webcams)
10+
11+
### Deployed on a Jetson
12+
* [Deep Learning Toolbox Importer for Caffe Models](https://www.mathworks.com/matlabcentral/fileexchange/61735-deep-learning-toolbox-importer-for-caffe-models)
13+
* [MATLAB Support Package for USB Webcams](https://www.mathworks.com/matlabcentral/fileexchange/45182-matlab-support-package-for-usb-webcams)
14+
* [GPU Coder Support Package for NVIDIA GPUs](https://mathworks.com/matlabcentral/fileexchange/68644-gpu-coder-support-package-for-nvidia-gpus)
15+
* [GPU Coder Interface for Deep Learning Libraries](https://mathworks.com/matlabcentral/fileexchange/68642-gpu-coder-interface-for-deep-learning-libraries)
16+
17+
## Installation
18+
This demo uses pre-trained models in Caffe (requires downloading ~1.16GB).
19+
20+
Add folder to search path and check for Add-on requirements by running:
21+
```matlab
22+
>> install
23+
```
24+
25+
For downloading the models, run:
26+
```matlab
27+
>> downloadAndSetupNetworks
28+
```
29+
30+
## Usage
31+
### In MATLAB
32+
You may run face, age and emotion detection by running (gender detection is disabled by default):
33+
```matlab
34+
>> faceGenderAgeEmotionDetection
35+
```
36+
![Test Image](testImage.png)
37+
38+
or choose which of the available models to use. For instance:
39+
```matlab
40+
>> faceGenderAgeEmotionDetection(true,true,true)
41+
```
42+
which runs gender, age and emotion detection. The demo uses binary gender detection, which may be consider inappropriate. Its use is not recommended in a public setting.
43+
44+
You may also speed up perfomance by generating MEX files using GPU Coder for each of the predict functions:
45+
1. Make sure that your computer is setup correctly:
46+
```matlab
47+
>> coder.checkGpuInstall
48+
```
49+
2. Generate mex files:
50+
```matlab
51+
>> generateCode
52+
```
53+
54+
### Deployed on a Jetson
55+
1. Make sure that your environment is setup correctly:
56+
```matlab
57+
>> coder.checkGpuInstall('tx2');
58+
```
59+
2. Open the codegen script
60+
```matlab
61+
>> edit generateCodeForJetson
62+
```
63+
3. Modify it to reflect your current configuration (e.g. IP address).
64+
4. Run the first section to generate CUDA code on the host, transfer it to the Jetson and compile it.
65+
5. Run the second section to launch the executable on the jetson. Please note that you can change the clock speed to maximise the performance.
66+
67+
## References
68+
69+
[1] Abars, Face Search VGG16, (2018). GitHub repository, https://github.com/abars/FaceSearchVGG16
70+
71+
[2] Rasmus Rothe, Radu Timofte and Luc Van Gool, (2016). Deep expectation of real and apparent age from a single image without facial landmarks. International Journal of Computer Vision (IJCV)
72+
73+
[3] Jia, Yangqing, et al., (2014). "Caffe: Convolutional architecture for fast feature embedding." Proceedings of the 22nd ACM international conference on Multimedia. ACM.
74+
75+
[4] Gil Levi and Tal Hassner, (2015). Emotion Recognition in the Wild via Convolutional Neural Networks and Mapped Binary Patterns. Proc. ACM International Conference on Multimodal Interaction (ICMI). https://osnathassner.github.io/talhassner/projects/cnn_emotions/project.html

install.m

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
% Copyright 2019 The MathWorks, Inc.
2+
function install()
3+
thisPath = fileparts(mfilename('fullpath'));
4+
5+
% Add folders to search path
6+
addpath(fullfile(thisPath, 'src'));
7+
8+
requiredAddOns = ["MATLAB Support Package for USB Webcams",...
9+
"Deep Learning Toolbox Importer for Caffe Models",...
10+
"GPU Coder Support Package for NVIDIA GPUs",...
11+
"GPU Coder Interface for Deep Learning Libraries"];
12+
13+
% Checking for missing Add-Ons
14+
missingAddOns = true(size(requiredAddOns));
15+
installedAddOns = matlab.addons.installedAddons;
16+
17+
addOnIdx = 1;
18+
dashRepeats = 52;
19+
while addOnIdx <= length(requiredAddOns)
20+
if ~any(installedAddOns.Name == requiredAddOns(addOnIdx))
21+
missingAddOns(addOnIdx) = true;
22+
else
23+
missingAddOns(addOnIdx) = false;
24+
end
25+
addOnIdx = addOnIdx + 1;
26+
end
27+
28+
if all(~missingAddOns)
29+
fprintf(1,[repmat('-',1,dashRepeats),'\n']);
30+
fprintf(1,'All the required Add-Ons are successfully installed.\n');
31+
fprintf(1,[repmat('-',1,dashRepeats),'\n']);
32+
else
33+
fprintf(1,[repmat('-',1,dashRepeats),'\n']);
34+
fprintf(1,'The following support packages are missing.\nPlease, visit the Add-On Explorer from your HOME tab \nand install the following:\n');
35+
for missingIdx = find(missingAddOns)
36+
if ~(missingIdx == 3 || missingIdx == 4)
37+
fprintf(1,' - %s\n',requiredAddOns(missingIdx))
38+
else
39+
fprintf(1,' - %s (*)\n',requiredAddOns(missingIdx))
40+
end
41+
end
42+
if ismember([3,4],find(missingAddOns))
43+
fprintf(1,'(*) only if using GPU Coder\n');
44+
end
45+
fprintf(1,[repmat('-',1,dashRepeats),'\n']);
46+
end
47+
48+
fprintf(1,'You may now download and configure the models \n(if you haven''t already).\n')
49+
fprintf(1,'To do so, run the script:\n''downloadAndSetupNetworks.m''.\n');
50+
fprintf(1,[repmat('-',1,dashRepeats),'\n']);
51+
fprintf(1,'Also, you may speed up detection by running:\n''generateCode.m''.\n(NVIDIA GPU and GPU support packages required).\n');
52+
fprintf(1,[repmat('-',1,dashRepeats),'\n']);
53+
54+
cd('src')
55+
end

0 commit comments

Comments
 (0)