Skip to content

Commit

Permalink
1.3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
takuya-takeuchi committed Sep 30, 2021
1 parent 0c54611 commit 6d5353c
Show file tree
Hide file tree
Showing 21 changed files with 336 additions and 25 deletions.
7 changes: 7 additions & 0 deletions FaceRecognitionDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadPoseTraining", "tools\H
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadPoseEstimationDemo", "examples\HeadPoseEstimationDemo\HeadPoseEstimationDemo.csproj", "{8540B212-5605-4402-BAE4-BEFEBAAD9F97}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkEndToEnd", "examples\BenchmarkEndToEnd\BenchmarkEndToEnd.csproj", "{F26A2088-EB8B-43F0-8F78-9A2BCE514367}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -113,6 +115,10 @@ Global
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Release|Any CPU.Build.0 = Release|Any CPU
{F26A2088-EB8B-43F0-8F78-9A2BCE514367}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F26A2088-EB8B-43F0-8F78-9A2BCE514367}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F26A2088-EB8B-43F0-8F78-9A2BCE514367}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F26A2088-EB8B-43F0-8F78-9A2BCE514367}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -134,6 +140,7 @@ Global
{13DDB1E7-EF71-48BA-A1E7-365C94783709} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
{BB6A1F98-DEF9-475C-A69A-82FE518D1E9E} = {8C8838E0-B002-426F-9B25-4C1F65A6D33D}
{8540B212-5605-4402-BAE4-BEFEBAAD9F97} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
{F26A2088-EB8B-43F0-8F78-9A2BCE514367} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D44C572-D749-4A76-A199-8C598A08AE8A}
Expand Down
18 changes: 18 additions & 0 deletions examples/BenchmarkEndToEnd/BenchmarkEndToEnd.csproj
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>
141 changes: 141 additions & 0 deletions examples/BenchmarkEndToEnd/Program.cs
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

}

}
73 changes: 73 additions & 0 deletions examples/BenchmarkEndToEnd/README.md
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 &lt;Benchmark_dir&gt;
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; &lt;Benchmark_dir&gt;\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 &lt;Benchmark_dir&gt;
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.
Binary file added examples/BenchmarkEndToEnd/obama-1080p.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/BenchmarkEndToEnd/obama-240p.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/BenchmarkEndToEnd/obama-480p.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/BenchmarkEndToEnd/obama-720p.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions nuget/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tmp
48 changes: 48 additions & 0 deletions nuget/ExtractNupkgToArtifacts.ps1
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
}
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.CPU.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.CUDA100.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet.CUDA100</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet for CUDA 10.0</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.CUDA101.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet.CUDA101</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet for CUDA 10.1</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.CUDA102.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet.CUDA102</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet for CUDA 10.2</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.CUDA110.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet.CUDA110</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet for CUDA 11.0</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.CUDA111.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet.CUDA111</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet for CUDA 11.1</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.CUDA112.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet.CUDA112</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet for CUDA 11.2</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.CUDA92.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet.CUDA92</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet for CUDA 9.2</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
2 changes: 1 addition & 1 deletion nuget/nuspec/FaceRecognitionDotNet.MKL.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package>
<metadata>
<id>FaceRecognitionDotNet.MKL</id>
<version>1.3.0.4</version>
<version>1.3.0.5</version>
<title>FaceRecognitionDotNet for MKL</title>
<authors>Takuya Takeuchi</authors>
<owners>Takuya Takeuchi</owners>
Expand Down
Loading

0 comments on commit 6d5353c

Please sign in to comment.