Closed theladyjaye closed 4 years ago
What package did you try? I tried the FRDN.CUDA100 and original python face_recognition for same obama2.jpg.
Your performance is a bit slow.
import timeit
# Note: This example is only tested with Python 3 (not Python 2)
# This is a very simple benchmark to give you an idea of how fast each step of face recognition will run on your system.
# Notice that face detection gets very slow at large image sizes. So you might consider running face detection on a
# scaled down version of your image and then running face encodings on the the full size image.
TEST_IMAGES = [
"obama2.jpg"
]
def run_test(setup, test, iterations_per_test=5, tests_to_run=10):
fastest_execution = min(timeit.Timer(test, setup=setup).repeat(tests_to_run, iterations_per_test))
execution_time = fastest_execution / iterations_per_test
fps = 1.0 / execution_time
return execution_time, fps
setup_locate_faces = """
import face_recognition
image = face_recognition.load_image_file("{}")
"""
test_locate_faces = """
face_locations = face_recognition.face_locations(image, 0, "cnn")
"""
setup_end_to_end = """
import face_recognition
image = face_recognition.load_image_file("{}")
"""
test_end_to_end = """
encoding = face_recognition.face_encodings(image)[0]
"""
print("Benchmarks (Note: All benchmarks are only using a single CPU core)")
print()
for image in TEST_IMAGES:
print(" - Face locations: {:.4f}s ({:.2f} fps)".format(*run_test(setup_locate_faces.format(image), test_locate_faces)))
print()
/*
* 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 Benchmark
{
internal class Program
{
#region Fields
private static FaceRecognition FaceRecognition;
#endregion
#region Methods
private static void Main(string[] args)
{
var app = new CommandLineApplication(false);
app.Name = nameof(Benchmark);
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);
app.OnExecute(() =>
{
if (!modelsOption.HasValue())
{
app.ShowHelp();
return -1;
}
var directory = modelsOption.Value();
if (!Directory.Exists(directory))
{
app.ShowHelp();
return -1;
}
FaceRecognition = FaceRecognition.Create(directory);
var testImages = new[]
{
"obama2.jpg",
};
Console.WriteLine("Benchmarks");
Console.WriteLine();
foreach (var image in testImages)
{
var faceLocations = RunTest(image, SetupLocateFaces, TestLocateFaces);
Console.WriteLine($" - Face locations: {faceLocations.Item1:F4}s ({faceLocations.Item2:F2} fps)");
}
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)
{
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 SetupEndToEnd(string path)
{
return FaceRecognition.LoadImageFile(path);
}
private static Image SetupLocateFaces(string path)
{
return FaceRecognition.LoadImageFile(path);
}
private static void TestEndToEnd(Image image)
{
var encoding = FaceRecognition.FaceEncodings(image).First();
}
private static void TestLocateFaces(Image image)
{
var faceLocations = FaceRecognition.FaceLocations(image, 0, FaceRecognitionDotNet.Model.Cnn).ToArray();
}
#endregion
#endregion
}
}
The above benchmark
Benchmarks (Note: All benchmarks are only using a single CPU core)
- Face locations: 0.0467s (21.43 fps)
Benchmarks (Note: All benchmarks are only using a single CPU core)
- Face locations: 0.0468s (21.38 fps)
Benchmarks (Note: All benchmarks are only using a single CPU core)
- Face locations: 0.0467s (21.43 fps)
Benchmarks
- Face locations: 0.0490s (20.41 fps)
Benchmarks
- Face locations: 0.0492s (20.33 fps)
Benchmarks
- Face locations: 0.0492s (20.33 fps)
Ah.. I was just using FaceRecognitionDotNet
not any of the CUDA libs. That might account for it.
It seems that the reporter resolve issue.
It takes about 20-24 seconds: (Using the
Cnn
modelHog
is near instant)Using images from:
https://github.com/takuya-takeuchi/FaceRecognitionDotNet/tree/master/test/FaceRecognitionDotNet.Tests/TestImages
And the following code: