Skip to content

Commit c7e9412

Browse files
committed
Scrfd benchmark: use onnx next to exe
1 parent 7bf6a96 commit c7e9412

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/Benchmarks/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ public static void Main(string[] args)
1818
// var summary = BenchmarkRunner.Run<ImageSharp>();
1919
// var summary = BenchmarkRunner.Run<FaceOnnxVsImageSharpAlignment>();
2020
// var summary = BenchmarkRunner.Run<CropFirstVsResizeFirst>(args: args);
21-
// var summary = BenchmarkRunner.Run<Scrfd>(opt, args);
21+
var summary = BenchmarkRunner.Run<Scrfd>(opt, args);
2222
// var summary = BenchmarkRunner.Run<ImageToTensor.Benchmarks>(opt, args);
2323
// var summary = BenchmarkRunner.Run<NonMaxSupression.Benchmarks>(opt, args);
2424
// var summary = BenchmarkRunner.Run<ImageCloneVsMutate>(opt, args);
25-
var summary = BenchmarkRunner.Run<ScrfdGenerateAnchorCenters>(opt, args);
25+
// var summary = BenchmarkRunner.Run<ScrfdGenerateAnchorCenters>(opt, args);
2626
}
2727
}

src/Benchmarks/Scrfd.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Copyright (c) Georg Jung. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System.Numerics;
4+
using System.Reflection;
55
using BenchmarkDotNet.Attributes;
66
using FaceAiSharp;
77
using FaceAiSharp.Extensions;
8-
using FaceONNX;
98
using Microsoft.ML.OnnxRuntime.Tensors;
109
using SixLabors.ImageSharp;
1110
using SixLabors.ImageSharp.PixelFormats;
@@ -19,7 +18,7 @@ public class Scrfd
1918
private readonly Image _img = Image.Load(@"C:\Users\georg\facePics\avGroup.jpg");
2019
private readonly Image<Rgb24> _preprocImg;
2120
private readonly ScrfdDetector _scrfd1;
22-
private readonly ScrfdDetector _scrfd2;
21+
/* private readonly ScrfdDetector _scrfd2; */
2322
private readonly DenseTensor<float> _imgTensor;
2423

2524
public Scrfd()
@@ -36,14 +35,15 @@ public Scrfd()
3635

3736
_preprocImg = x.Image;
3837
_imgTensor = ScrfdDetector.CreateImageTensor(_preprocImg);
38+
var modelPath = Path.Combine(GetExeDir(), "onnx", "scrfd_2.5g_kps.onnx");
3939
_scrfd1 = new(
4040
new ScrfdDetectorOptions()
4141
{
42-
ModelPath = @"C:\Users\georg\OneDrive\Dokumente\ScrfdOnnx\scrfd_2.5g_bnkps_shape640x640.onnx",
42+
ModelPath = modelPath,
4343
AutoResizeInputToModelDimensions = false,
4444
});
4545

46-
_scrfd2 = new(
46+
/*_scrfd2 = new(
4747
new()
4848
{
4949
ModelPath = @"C:\Users\georg\OneDrive\Dokumente\ScrfdOnnx\scrfd_2.5g_bnkps_dyn.onnx",
@@ -52,12 +52,14 @@ public Scrfd()
5252
new()
5353
{
5454
ExecutionMode = Microsoft.ML.OnnxRuntime.ExecutionMode.ORT_PARALLEL,
55-
});
55+
});*/
5656
}
5757

5858
[Benchmark]
5959
public IReadOnlyCollection<FaceDetectorResult> First() => _scrfd1.Detect(_imgTensor, new Size(640, 640), 1.0f);
6060

61-
[Benchmark]
62-
public IReadOnlyCollection<FaceDetectorResult> Second() => _scrfd2.Detect(_imgTensor, new Size(640, 640), 1.0f);
61+
/*[Benchmark]
62+
public IReadOnlyCollection<FaceDetectorResult> Second() => _scrfd2.Detect(_imgTensor, new Size(640, 640), 1.0f);*/
63+
64+
private static string GetExeDir() => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!;
6365
}

0 commit comments

Comments
 (0)