georg-jung / FaceAiSharp

State-of-the-art face detection and face recognition for .NET.
https://nuget.org/packages/FaceAiSharp/
MIT License
60 stars 9 forks source link

How can I use GPU? #43

Closed achmstein closed 1 week ago

achmstein commented 4 months ago

Hello,

Thank you for the great library.

How to use GPU for face detection and recognition? I want to use it with Frigate for camera's stream!

georg-jung commented 4 months ago

Thanks for the kind words. Instead of

dotnet add package Microsoft.ML.OnnxRuntime
dotnet add package FaceAiSharp.Bundle

you could do

dotnet add package Microsoft.ML.OnnxRuntime.Gpu
// or
dotnet add package Microsoft.ML.OnnxRuntime.DirectML
dotnet add package FaceAiSharp.Bundle

Then, for e.g. DirectML you could do

        _embedderSessOpts = new SessionOptions
        {
            EnableMemoryPattern = false,
        };
        _embedderSessOpts.AppendExecutionProvider_DML();

        _emb = new ArcFaceEmbeddingsGenerator(
            new()
            {
                ModelPath = arcFaceModel.FullName,
            },
            _embedderSessOpts);

Also take a look here: https://onnxruntime.ai/docs/get-started/with-csharp.html#running-on-gpu-optional

Let me know if this works for you.