Skip to content

Commit 6d5353c

Browse files
1.3.0.5
1 parent 0c54611 commit 6d5353c

21 files changed

+336
-25
lines changed

FaceRecognitionDotNet.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadPoseTraining", "tools\H
4343
EndProject
4444
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadPoseEstimationDemo", "examples\HeadPoseEstimationDemo\HeadPoseEstimationDemo.csproj", "{8540B212-5605-4402-BAE4-BEFEBAAD9F97}"
4545
EndProject
46+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkEndToEnd", "examples\BenchmarkEndToEnd\BenchmarkEndToEnd.csproj", "{F26A2088-EB8B-43F0-8F78-9A2BCE514367}"
47+
EndProject
4648
Global
4749
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4850
Debug|Any CPU = Debug|Any CPU
@@ -113,6 +115,10 @@ Global
113115
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Debug|Any CPU.Build.0 = Debug|Any CPU
114116
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Release|Any CPU.ActiveCfg = Release|Any CPU
115117
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Release|Any CPU.Build.0 = Release|Any CPU
118+
{F26A2088-EB8B-43F0-8F78-9A2BCE514367}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
119+
{F26A2088-EB8B-43F0-8F78-9A2BCE514367}.Debug|Any CPU.Build.0 = Debug|Any CPU
120+
{F26A2088-EB8B-43F0-8F78-9A2BCE514367}.Release|Any CPU.ActiveCfg = Release|Any CPU
121+
{F26A2088-EB8B-43F0-8F78-9A2BCE514367}.Release|Any CPU.Build.0 = Release|Any CPU
116122
EndGlobalSection
117123
GlobalSection(SolutionProperties) = preSolution
118124
HideSolutionNode = FALSE
@@ -134,6 +140,7 @@ Global
134140
{13DDB1E7-EF71-48BA-A1E7-365C94783709} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
135141
{BB6A1F98-DEF9-475C-A69A-82FE518D1E9E} = {8C8838E0-B002-426F-9B25-4C1F65A6D33D}
136142
{8540B212-5605-4402-BAE4-BEFEBAAD9F97} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
143+
{F26A2088-EB8B-43F0-8F78-9A2BCE514367} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
137144
EndGlobalSection
138145
GlobalSection(ExtensibilityGlobals) = postSolution
139146
SolutionGuid = {4D44C572-D749-4A76-A199-8C598A08AE8A}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.0</TargetFramework>
6+
<Authors>Takuya Takeuchi</Authors>
7+
<Description>Example of FaceRecognitionDotNet</Description>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\..\src\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
* This sample program is ported by C# from https://github.com/ageitgey/face_recognition/blob/master/examples/benchmark.py.
3+
*/
4+
5+
using System;
6+
using System.Diagnostics;
7+
using System.IO;
8+
using System.Linq;
9+
using FaceRecognitionDotNet;
10+
using Microsoft.Extensions.CommandLineUtils;
11+
12+
namespace BenchmarkEndToEnd
13+
{
14+
15+
internal class Program
16+
{
17+
18+
#region Fields
19+
20+
private static FaceRecognition _FaceRecognition;
21+
22+
private static bool _UseCnn = false;
23+
24+
#endregion
25+
26+
#region Methods
27+
28+
private static void Main(string[] args)
29+
{
30+
var app = new CommandLineApplication(false);
31+
app.Name = nameof(BenchmarkEndToEnd);
32+
app.Description = "The program for measure face encoding performance";
33+
app.HelpOption("-h|--help");
34+
35+
var modelsOption = app.Option("-m|--model", "model files directory path", CommandOptionType.SingleValue);
36+
var cnnOption = app.Option("-c|--cnn", "use cnn", CommandOptionType.NoValue);
37+
38+
app.OnExecute(() =>
39+
{
40+
if (!modelsOption.HasValue())
41+
{
42+
app.ShowHelp();
43+
return -1;
44+
}
45+
46+
var directory = modelsOption.Value();
47+
if (!Directory.Exists(directory))
48+
{
49+
app.ShowHelp();
50+
return -1;
51+
}
52+
53+
_UseCnn = cnnOption.HasValue();
54+
55+
_FaceRecognition = FaceRecognition.Create(directory);
56+
57+
var testImages = new[]
58+
{
59+
"obama-240p.jpg",
60+
"obama-480p.jpg",
61+
"obama-720p.jpg",
62+
"obama-1080p.jpg"
63+
};
64+
65+
Console.WriteLine("Benchmarks");
66+
Console.WriteLine();
67+
68+
foreach (var image in testImages)
69+
{
70+
var size = image.Split('-')[1].Split('.')[0];
71+
Console.WriteLine($"Timings at {size}:");
72+
73+
var faceLocations = RunTest(image, SetupLocateFaces, TestEndToEnd);
74+
Console.WriteLine($" - Face locations, landmark, encoding, distance: {faceLocations.Item1:F4}s ({faceLocations.Item2:F2} fps)");
75+
Console.WriteLine();
76+
}
77+
78+
return 0;
79+
});
80+
81+
app.Execute(args);
82+
}
83+
84+
#region Helpers
85+
86+
private static Tuple<double, double> RunTest<T>(string path, Func<string, T> setup, Action<T> test, int iterationsPerTest = 5, int testsToRun = 10, bool useCnn = false)
87+
{
88+
var image = setup(path);
89+
90+
var iteration = new Func<double>(() =>
91+
{
92+
var sw = new Stopwatch();
93+
sw.Start();
94+
for (var count = 0; count < iterationsPerTest; count++)
95+
test(image);
96+
sw.Stop();
97+
98+
return sw.ElapsedMilliseconds;
99+
});
100+
101+
var fastestExecution = Enumerable.Repeat(0, testsToRun).Select(i => iteration()).Min();
102+
var executionTime = fastestExecution / 1000 / iterationsPerTest;
103+
var fps = 1.0 / executionTime;
104+
105+
(image as IDisposable)?.Dispose();
106+
107+
return new Tuple<double, double>(executionTime, fps);
108+
}
109+
110+
private static Image SetupLocateFaces(string path)
111+
{
112+
return FaceRecognition.LoadImageFile(path);
113+
}
114+
115+
private static void TestEndToEnd(Image image)
116+
{
117+
var model = _UseCnn ? Model.Cnn : Model.Hog;
118+
var faceLocations = _FaceRecognition.FaceLocations(image, model: model);
119+
var faceLocationCount = faceLocations.Count();
120+
121+
var faceLandmarks = _FaceRecognition.FaceLandmark(image, faceLocations, model: model);
122+
var faceLandmarkCount = faceLandmarks.Count();
123+
124+
var encoding = _FaceRecognition.FaceEncodings(image, faceLocations, model: model);
125+
var faceEncodingCount = encoding.Count();
126+
127+
// it could do matching for 1 time
128+
foreach (var faceEncoding in encoding)
129+
FaceRecognition.FaceDistance(faceEncoding, faceEncoding);
130+
131+
foreach (var faceEncoding in encoding)
132+
faceEncoding.Dispose();
133+
}
134+
135+
#endregion
136+
137+
#endregion
138+
139+
}
140+
141+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Benchmark
2+
3+
This example measures performance of calculating for face encodings.
4+
This sample program is ported by C# from https://github.com/ageitgey/face_recognition/blob/master/examples/benchmark.py.
5+
6+
## How to use?
7+
8+
## 1. Preparation
9+
10+
This sample requires test image and model files.
11+
12+
## 2. Build
13+
14+
1. Open command prompt and change to &lt;Benchmark_dir&gt;
15+
1. Type the following command
16+
````
17+
$ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj
18+
$ dotnet add package FaceRecognitionDotNet
19+
$ dotnet build -c Release
20+
````
21+
2. Copy ***DlibDotNet.dll***, ***DlibDotNet.Native.dll*** and ***DlibDotNet.Dnn.dll*** to output directory; &lt;Benchmark_dir&gt;\bin\Release\netcoreapp2.0.
22+
* if you use FaceRecognitionDotNet with CUDA, you must copy also cuda libraries.
23+
24+
## 3. Run
25+
26+
1. Open command prompt and change to &lt;Benchmark_dir&gt;
27+
1. Type the following sample command
28+
````
29+
$ dotnet run -c Release -- "-m=models"
30+
Benchmarks
31+
32+
Timings at 240p:
33+
- Face locations: 0.0268s (37.31 fps)
34+
- Face landmarks: 0.0014s (714.29 fps)
35+
- Encode face (inc. landmarks): 0.0210s (47.62 fps)
36+
- End-to-end: 0.0484s (20.66 fps)
37+
38+
Timings at 480p:
39+
- Face locations: 0.1068s (9.36 fps)
40+
- Face landmarks: 0.0014s (714.29 fps)
41+
- Encode face (inc. landmarks): 0.0202s (49.50 fps)
42+
- End-to-end: 0.1308s (7.65 fps)
43+
44+
Timings at 720p:
45+
- Face locations: 0.2416s (4.14 fps)
46+
- Face landmarks: 0.0014s (714.29 fps)
47+
- Encode face (inc. landmarks): 0.0206s (48.54 fps)
48+
- End-to-end: 0.2700s (3.70 fps)
49+
50+
Timings at 1080p:
51+
- Face locations: 0.5430s (1.84 fps)
52+
- Face landmarks: 0.0016s (625.00 fps)
53+
- Encode face (inc. landmarks): 0.0206s (48.54 fps)
54+
- End-to-end: 0.5774s (1.73 fps)
55+
````
56+
57+
## 4. Parameters
58+
59+
This program support the following argument and option.
60+
61+
### Argument
62+
63+
|Argument|Description|
64+
|:---|:---|
65+
|-m\|--model|Directory path includes model files|
66+
|-c\|--cnn|Use Cnn|
67+
68+
## 5. Other
69+
70+
### Why is Encode face too slow?
71+
72+
The reason ***face_recognition*** can achieve high performance is using ***Intel Math Kernel Library***.
73+
If you can use Intel Math Kernel Library, you can build ***DlibDotNet.Native.Dnn*** by linking Intel Math Kernel Library.
378 KB
Loading
36.4 KB
Loading
100 KB
Loading
197 KB
Loading

nuget/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmp

nuget/ExtractNupkgToArtifacts.ps1

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#***************************************
2+
#Arguments
3+
#%1: Version of Release (1.2.3.0)
4+
#***************************************
5+
Param([Parameter(
6+
Mandatory=$True,
7+
Position = 1
8+
)][string]
9+
$Version
10+
)
11+
12+
$PublishTargets = @{ "FaceRecognitionDotNet"="cpu";
13+
"FaceRecognitionDotNet.CUDA92"="cuda-92";
14+
"FaceRecognitionDotNet.CUDA100"="cuda-100";
15+
"FaceRecognitionDotNet.CUDA101"="cuda-101";
16+
"FaceRecognitionDotNet.CUDA102"="cuda-102";
17+
"FaceRecognitionDotNet.CUDA110"="cuda-110";
18+
"FaceRecognitionDotNet.CUDA111"="cuda-111";
19+
"FaceRecognitionDotNet.CUDA112"="cuda-112";
20+
"FaceRecognitionDotNet.MKL"="mkl";
21+
}
22+
23+
$Token = $env:FaceRecognitionDotNetNugetToken
24+
if ([string]::IsNullOrWhitespace($Token))
25+
{
26+
Write-Host "nuget token is missing" -ForegroundColor Red
27+
exit
28+
}
29+
30+
# Precheck whether all package is present
31+
foreach ($key in $PublishTargets.keys)
32+
{
33+
$value = $PublishTargets[$key]
34+
35+
$Package = Join-Path $PSScriptRoot "${key}.${Version}.nupkg"
36+
if (!(Test-Path ${Package}))
37+
{
38+
Write-Host "${Package} is missing" -ForegroundColor Red
39+
exit
40+
}
41+
42+
Expand-Archive -Path "${Package}" -DestinationPath tmp
43+
$runtime = Join-Path tmp runtimes
44+
$artifacts = Join-Path artifacts ${value} | `
45+
Join-Path -ChildPath runtimes
46+
Copy-Item "${runtime}/*" "${artifacts}" -Recurse -Force
47+
Remove-Item tmp -Recurse -Force
48+
}

0 commit comments

Comments
 (0)