-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c54611
commit 6d5353c
Showing
21 changed files
with
336 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<Authors>Takuya Takeuchi</Authors> | ||
<Description>Example of FaceRecognitionDotNet</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* This sample program is ported by C# from https://github.com/ageitgey/face_recognition/blob/master/examples/benchmark.py. | ||
*/ | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using FaceRecognitionDotNet; | ||
using Microsoft.Extensions.CommandLineUtils; | ||
|
||
namespace BenchmarkEndToEnd | ||
{ | ||
|
||
internal class Program | ||
{ | ||
|
||
#region Fields | ||
|
||
private static FaceRecognition _FaceRecognition; | ||
|
||
private static bool _UseCnn = false; | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
private static void Main(string[] args) | ||
{ | ||
var app = new CommandLineApplication(false); | ||
app.Name = nameof(BenchmarkEndToEnd); | ||
app.Description = "The program for measure face encoding performance"; | ||
app.HelpOption("-h|--help"); | ||
|
||
var modelsOption = app.Option("-m|--model", "model files directory path", CommandOptionType.SingleValue); | ||
var cnnOption = app.Option("-c|--cnn", "use cnn", CommandOptionType.NoValue); | ||
|
||
app.OnExecute(() => | ||
{ | ||
if (!modelsOption.HasValue()) | ||
{ | ||
app.ShowHelp(); | ||
return -1; | ||
} | ||
|
||
var directory = modelsOption.Value(); | ||
if (!Directory.Exists(directory)) | ||
{ | ||
app.ShowHelp(); | ||
return -1; | ||
} | ||
|
||
_UseCnn = cnnOption.HasValue(); | ||
|
||
_FaceRecognition = FaceRecognition.Create(directory); | ||
|
||
var testImages = new[] | ||
{ | ||
"obama-240p.jpg", | ||
"obama-480p.jpg", | ||
"obama-720p.jpg", | ||
"obama-1080p.jpg" | ||
}; | ||
|
||
Console.WriteLine("Benchmarks"); | ||
Console.WriteLine(); | ||
|
||
foreach (var image in testImages) | ||
{ | ||
var size = image.Split('-')[1].Split('.')[0]; | ||
Console.WriteLine($"Timings at {size}:"); | ||
|
||
var faceLocations = RunTest(image, SetupLocateFaces, TestEndToEnd); | ||
Console.WriteLine($" - Face locations, landmark, encoding, distance: {faceLocations.Item1:F4}s ({faceLocations.Item2:F2} fps)"); | ||
Console.WriteLine(); | ||
} | ||
|
||
return 0; | ||
}); | ||
|
||
app.Execute(args); | ||
} | ||
|
||
#region Helpers | ||
|
||
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) | ||
{ | ||
var image = setup(path); | ||
|
||
var iteration = new Func<double>(() => | ||
{ | ||
var sw = new Stopwatch(); | ||
sw.Start(); | ||
for (var count = 0; count < iterationsPerTest; count++) | ||
test(image); | ||
sw.Stop(); | ||
|
||
return sw.ElapsedMilliseconds; | ||
}); | ||
|
||
var fastestExecution = Enumerable.Repeat(0, testsToRun).Select(i => iteration()).Min(); | ||
var executionTime = fastestExecution / 1000 / iterationsPerTest; | ||
var fps = 1.0 / executionTime; | ||
|
||
(image as IDisposable)?.Dispose(); | ||
|
||
return new Tuple<double, double>(executionTime, fps); | ||
} | ||
|
||
private static Image SetupLocateFaces(string path) | ||
{ | ||
return FaceRecognition.LoadImageFile(path); | ||
} | ||
|
||
private static void TestEndToEnd(Image image) | ||
{ | ||
var model = _UseCnn ? Model.Cnn : Model.Hog; | ||
var faceLocations = _FaceRecognition.FaceLocations(image, model: model); | ||
var faceLocationCount = faceLocations.Count(); | ||
|
||
var faceLandmarks = _FaceRecognition.FaceLandmark(image, faceLocations, model: model); | ||
var faceLandmarkCount = faceLandmarks.Count(); | ||
|
||
var encoding = _FaceRecognition.FaceEncodings(image, faceLocations, model: model); | ||
var faceEncodingCount = encoding.Count(); | ||
|
||
// it could do matching for 1 time | ||
foreach (var faceEncoding in encoding) | ||
FaceRecognition.FaceDistance(faceEncoding, faceEncoding); | ||
|
||
foreach (var faceEncoding in encoding) | ||
faceEncoding.Dispose(); | ||
} | ||
|
||
#endregion | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Benchmark | ||
|
||
This example measures performance of calculating for face encodings. | ||
This sample program is ported by C# from https://github.com/ageitgey/face_recognition/blob/master/examples/benchmark.py. | ||
|
||
## How to use? | ||
|
||
## 1. Preparation | ||
|
||
This sample requires test image and model files. | ||
|
||
## 2. Build | ||
|
||
1. Open command prompt and change to <Benchmark_dir> | ||
1. Type the following command | ||
```` | ||
$ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj | ||
$ dotnet add package FaceRecognitionDotNet | ||
$ dotnet build -c Release | ||
```` | ||
2. Copy ***DlibDotNet.dll***, ***DlibDotNet.Native.dll*** and ***DlibDotNet.Dnn.dll*** to output directory; <Benchmark_dir>\bin\Release\netcoreapp2.0. | ||
* if you use FaceRecognitionDotNet with CUDA, you must copy also cuda libraries. | ||
|
||
## 3. Run | ||
|
||
1. Open command prompt and change to <Benchmark_dir> | ||
1. Type the following sample command | ||
```` | ||
$ dotnet run -c Release -- "-m=models" | ||
Benchmarks | ||
Timings at 240p: | ||
- Face locations: 0.0268s (37.31 fps) | ||
- Face landmarks: 0.0014s (714.29 fps) | ||
- Encode face (inc. landmarks): 0.0210s (47.62 fps) | ||
- End-to-end: 0.0484s (20.66 fps) | ||
Timings at 480p: | ||
- Face locations: 0.1068s (9.36 fps) | ||
- Face landmarks: 0.0014s (714.29 fps) | ||
- Encode face (inc. landmarks): 0.0202s (49.50 fps) | ||
- End-to-end: 0.1308s (7.65 fps) | ||
Timings at 720p: | ||
- Face locations: 0.2416s (4.14 fps) | ||
- Face landmarks: 0.0014s (714.29 fps) | ||
- Encode face (inc. landmarks): 0.0206s (48.54 fps) | ||
- End-to-end: 0.2700s (3.70 fps) | ||
Timings at 1080p: | ||
- Face locations: 0.5430s (1.84 fps) | ||
- Face landmarks: 0.0016s (625.00 fps) | ||
- Encode face (inc. landmarks): 0.0206s (48.54 fps) | ||
- End-to-end: 0.5774s (1.73 fps) | ||
```` | ||
|
||
## 4. Parameters | ||
|
||
This program support the following argument and option. | ||
|
||
### Argument | ||
|
||
|Argument|Description| | ||
|:---|:---| | ||
|-m\|--model|Directory path includes model files| | ||
|-c\|--cnn|Use Cnn| | ||
|
||
## 5. Other | ||
|
||
### Why is Encode face too slow? | ||
|
||
The reason ***face_recognition*** can achieve high performance is using ***Intel Math Kernel Library***. | ||
If you can use Intel Math Kernel Library, you can build ***DlibDotNet.Native.Dnn*** by linking Intel Math Kernel Library. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#*************************************** | ||
#Arguments | ||
#%1: Version of Release (1.2.3.0) | ||
#*************************************** | ||
Param([Parameter( | ||
Mandatory=$True, | ||
Position = 1 | ||
)][string] | ||
$Version | ||
) | ||
|
||
$PublishTargets = @{ "FaceRecognitionDotNet"="cpu"; | ||
"FaceRecognitionDotNet.CUDA92"="cuda-92"; | ||
"FaceRecognitionDotNet.CUDA100"="cuda-100"; | ||
"FaceRecognitionDotNet.CUDA101"="cuda-101"; | ||
"FaceRecognitionDotNet.CUDA102"="cuda-102"; | ||
"FaceRecognitionDotNet.CUDA110"="cuda-110"; | ||
"FaceRecognitionDotNet.CUDA111"="cuda-111"; | ||
"FaceRecognitionDotNet.CUDA112"="cuda-112"; | ||
"FaceRecognitionDotNet.MKL"="mkl"; | ||
} | ||
|
||
$Token = $env:FaceRecognitionDotNetNugetToken | ||
if ([string]::IsNullOrWhitespace($Token)) | ||
{ | ||
Write-Host "nuget token is missing" -ForegroundColor Red | ||
exit | ||
} | ||
|
||
# Precheck whether all package is present | ||
foreach ($key in $PublishTargets.keys) | ||
{ | ||
$value = $PublishTargets[$key] | ||
|
||
$Package = Join-Path $PSScriptRoot "${key}.${Version}.nupkg" | ||
if (!(Test-Path ${Package})) | ||
{ | ||
Write-Host "${Package} is missing" -ForegroundColor Red | ||
exit | ||
} | ||
|
||
Expand-Archive -Path "${Package}" -DestinationPath tmp | ||
$runtime = Join-Path tmp runtimes | ||
$artifacts = Join-Path artifacts ${value} | ` | ||
Join-Path -ChildPath runtimes | ||
Copy-Item "${runtime}/*" "${artifacts}" -Recurse -Force | ||
Remove-Item tmp -Recurse -Force | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.