Git Product home page Git Product logo

georg-jung / faceaisharp Goto Github PK

View Code? Open in Web Editor NEW
48.0 48.0 7.0 326 KB

State-of-the-art face detection and face recognition for .NET.

Home Page: https://nuget.org/packages/FaceAiSharp/

License: MIT License

C# 97.29% Dockerfile 0.97% Jupyter Notebook 1.74%
ai arcface artificial-intelligence artificial-neural-networks csharp eye-state-detection face-detection face-recognition facial-keypoints facial-landmarks machine-learning onnx onnxruntime

faceaisharp's People

Contributors

dependabot[bot] avatar georg-jung avatar ritorna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

faceaisharp's Issues

Different Face Detection result compare to Demo Site

Hi @georg-jung , first of all thanks for the great work that you put into this library.
Currently I was testing some pictures and lib is working great, but then I ran into 1 picture where I cannot detect the face. I would clarify this picture as good picture, the face can be seen clearly only a mic blocking the mouth.

But funny thing is on your demo site part Face Recognition, the face was detected normally.

Can you suggest me where can I start to check, I already checkout your demo code make sure everything the same config and using the same lib version. But I'm using .NET6 MVC instead of Blazor .NET7.

Thanks before.

exception when comparing two faces.

Hi,
I tried your example to compare two face (code below) and it worked fine.
Now without making any change on the code, i am getting an exception at this line:
var det = FaceAiSharpBundleFactory.CreateFaceDetectorWithLandmarks();
the exception is :
The type initializer for 'Microsoft.ML.OnnxRuntime.NativeMethods' threw an exception.

How to fix this issue?
i tried to unistall and reinstall the libraries : FaceAiSharp & FaceAiSharp.Bundle but still getting the same exception.

Here is the code i have used from your documentation.

`using var hc = new HttpClient();
var groupPhoto = await hc.GetByteArrayAsync(
"https://raw.githubusercontent.com/georg-jung/FaceAiSharp/master/examples/obama_family.jpg");
var img = Image.Load(groupPhoto);

var det = FaceAiSharpBundleFactory.CreateFaceDetectorWithLandmarks();_**//exception at this line**_
var rec = FaceAiSharpBundleFactory.CreateFaceEmbeddingsGenerator();

var faces = det.DetectFaces(img);
var first = faces.First();
var second = faces.Skip(1).First();

// AlignFaceUsingLandmarks is an in-place operation so we need to create a clone of img first
var secondImg = img.Clone();
rec.AlignFaceUsingLandmarks(img, first.Landmarks!);
rec.AlignFaceUsingLandmarks(secondImg, second.Landmarks!);

var embedding1 = rec.GenerateEmbedding(img);
var embedding2 = rec.GenerateEmbedding(secondImg);

var dot = FaceAiSharp.Extensions.GeometryExtensions.Dot(embedding1, embedding2);

Console.WriteLine($"Dot product: {dot}");
if (dot >= 0.42)
{
    Console.WriteLine("Assessment: Both pictures show the same person.");
}
else if (dot > 0.28 && dot < 0.42)
{
    Console.WriteLine("Assessment: Hard to tell if the pictures show the same person.");
}
else if (dot <= 0.28)
{
    Console.WriteLine("Assessment: These are two different people.");
}`

Image profile crop example

Hi Georg,

Your project it's really good. Congratz.

Do you have any example of cropping image for profile I saw your page but didn't see the code of this example.

Thank you,

Johan

How can I use GPU?

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!

Compatibility Issue: FaceAiSharp DetectFaces Method Fails with ImageSharp 3.1.1 Due to Missing ImageInfoExtensions

Compatibility Issue with ImageSharp 3.1.1: Missing 'ImageInfoExtensions'

Description

When the FaceAiSharp library is used alongside the latest version of ImageSharp (3.1.1), the DetectFaces method throws a runtime exception, indicating a compatibility issue. This problem does not occur with the older version of ImageSharp (2.1.5), suggesting that changes in ImageSharp's library, specifically the removal or modification of ImageInfoExtensions, might be the cause.

Environment

  • .NET Runtime: .NET 6
  • FaceAiSharp Version: Latest
  • ImageSharp Version: 3.1.1
  • Operating System: Windows 11

Exception Details

Could not load type 'SixLabors.ImageSharp.ImageInfoExtensions' from assembly 'SixLabors.ImageSharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13'.

Steps to Reproduce

  1. Ensure the .NET 6 environment is set up with the latest versions of FaceAiSharp and ImageSharp (3.1.1).
  2. Run the following code, replacing file paths with valid image paths on your system:
var selfiePath = @"<ReplaceWithValidPath>\Selfie.jpg";
var groupPhotoPath = @"<ReplaceWithValidPath>\GroupPhoto.jpg";

// Load images from file paths
using var selfieStream = File.OpenRead(selfiePath);
var selfie = Image.Load<Rgb24>(selfieStream);

using var groupPhotoStream = File.OpenRead(groupPhotoPath);
var groupPhoto = Image.Load<Rgb24>(groupPhotoStream);

var detector = FaceAiSharpBundleFactory.CreateFaceDetectorWithLandmarks();
var recognizer = FaceAiSharpBundleFactory.CreateFaceEmbeddingsGenerator();

var selfieFaces = detector.DetectFaces(selfie);
if (!selfieFaces.Any())
{
    Console.WriteLine("No faces detected in the selfie.");
    return;
}

Expected Behavior

The DetectFaces method should successfully identify faces within the provided images without triggering any exceptions.

Actual Behavior

An exception is thrown by the method, pointing to the inability to load the type ImageInfoExtensions, which suggests that this class has either been removed or relocated in the latest ImageSharp version.

Possible Solution

A review of the changes made between ImageSharp versions 2.1.5 and 3.1.1 could clarify whether ImageInfoExtensions has been deprecated or replaced. Adapting FaceAiSharp to align with these updates could potentially resolve the issue.

exception on FaceAiSharpBundleFactory.CreateFaceDetectorWithLandmarks()

Hi,
I tried your example to compare two face (code below) and it worked fine on .net maui (win & andtoid).
After making an update of the faceaisharp, the android app throw an exception:
Microsoft.ML.OnnxRuntime.OnnxRuntimeException: '[ErrorCode:NoSuchFile] Load model from /data/data/com.companyname.facerecognitiontest/files/.override/onnx/scrfd_2.5g_kps.onnx failed:Load model /data/data/com.companyname.facerecognitiontest/files/.override/onnx/scrfd_2.5g_kps.onnx failed. File doesn't exist'

On windows it still working. but on Adroid i am getting the exception on this line:
var det = FaceAiSharpBundleFactory.CreateFaceDetectorWithLandmarks();
I am not able to resolve this issue. Can you please help with this. Is it possible to provide an example that works on .net maui for Android.

thanks in advance.

Eception when compare faces.

I tried your example to compare faces. I am getting an exception at this line: var faces = det.DetectFaces(img);
the exception is :
System.TypeLoadException:` 'Could not load type 'SixLabors.ImageSharp.ImageInfoExtensions' from assembly 'SixLabors.ImageSharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=d998eea7b14cab13'.'
How to fix this issue?

Here is the code i have used from your documentation.

    using var hc = new HttpClient();
    var groupPhoto = await hc.GetByteArrayAsync(
        "https://raw.githubusercontent.com/georg-jung/FaceAiSharp/master/examples/obama_family.jpg");
    var img = Image.Load<Rgb24>(groupPhoto);

    var det = FaceAiSharpBundleFactory.CreateFaceDetectorWithLandmarks();
    var rec = FaceAiSharpBundleFactory.CreateFaceEmbeddingsGenerator();

    var faces = det.DetectFaces(img);
    var first = faces.First();
    var second = faces.Skip(1).First();

    // AlignFaceUsingLandmarks is an in-place operation so we need to create a clone of img first
    var secondImg = img.Clone();
    rec.AlignFaceUsingLandmarks(img, first.Landmarks!);
    rec.AlignFaceUsingLandmarks(secondImg, second.Landmarks!);

    var embedding1 = rec.GenerateEmbedding(img);
    var embedding2 = rec.GenerateEmbedding(secondImg);

    var dot = FaceAiSharp.Extensions.GeometryExtensions.Dot(embedding1, embedding2);

    Console.WriteLine($"Dot product: {dot}");
    if (dot >= 0.42)
    {
        Console.WriteLine("Assessment: Both pictures show the same person.");
    }
    else if (dot > 0.28 && dot < 0.42)
    {
        Console.WriteLine("Assessment: Hard to tell if the pictures show the same person.");
    }
    else if (dot <= 0.28)
    {
        Console.WriteLine("Assessment: These are two different people.");
    }

Face detection code is not working on android.

Hi Georg--jung, i tried to implement an example to detect and recognise faces in .Net Maui. I am able to make it work on win device but not on android device. I am getting this exception on android:
Microsoft.ML.OnnxRuntime.OnnxRuntimeException: '[ErrorCode:NoSuchFile] Load model from /data/data/com.companyname.faceaitestmaui/files/.override/onnx/scrfd_2.5g_kps.onnx failed:Load model /data/data/com.companyname.faceaitestmaui/files/.override/onnx/scrfd_2.5g_kps.onnx failed. File doesn't exist'

Does your plugin works on android or it is designed to work on windows only?

best regards.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.