Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Features #14

Merged
merged 19 commits into from
Jun 24, 2024
Merged

New Features #14

merged 19 commits into from
Jun 24, 2024

Conversation

pablo-gbr
Copy link
Contributor

  • Added new anti_spoofing feature

    • Deepface added a new anti-spoofing feature to detect if the image is a photo or a real person, it's currently added to all methods and defaults to false.
  • Fixed Unicode characters

    • When uploading an image from a folder like 'Users', it would throw an error trying to parse the '\U' in the path as a Unicode character. This should be fixed.
  • Fixed wrong result being returned in Verify function

    • When comparing output['Verified'] to 'True' it would return false, resulting in the wrong outcome even if the face is verified.
  • Updated scripts to handle Exceptions.

    • Now the scripts can handle ValueError exceptions and output the error using stderr.
  • Added custom exception.

I published a new release on my fork, feel free to test it and let me know any problem!

Copy link
Member

@Gummibeer Gummibeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that big upgrade! 🥳
Just a few points I spotted.
And it seems CodeStyle is failing: composer fix

scripts/represent.py Show resolved Hide resolved
src/DeepFace.php Outdated
);
} catch(DeepFaceException $e){
// if any of these images fails the spoof detection, it will throw 'Exception while processing imgX_path'
return array("error" => $e->getMessage());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's way easier to let these exceptions bubble up and let the user decide how to handle them. There's a special exception for this package the user can catch and do whatever needed. While catching the array will be harder and also not as straight forward.
Or what's the reason to catch the exception in package and only provide an array to the user? 🤔

Copy link
Contributor Author

@pablo-gbr pablo-gbr Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verify method would throw Exception while processing imgX_path if any of the images is spoofed, since it uses extract_faces when verifying, and since the function returns a VerifyResult, I added array as a return to catch the exception message.

I can change it to any other way to return the exception or handle it in a different way if you have a better idea 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think best would be to let the exception just bubble up and do nothing about it in the package (for all methods). That way each user can decide what they do with that exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

src/Exceptions/DeepFaceGenericException.php Outdated Show resolved Hide resolved
src/DeepFace.php Outdated
$errorResult = json_decode($lastJson, true);

if ($errorResult !== null && isset($errorResult['error'])) {
throw new DeepFaceException($errorResult['error']); // should return 'Spoof detected in the given image'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this comment isn't needed. If there's a special scenario for "Spoof detected in the given image" and that exception message stays the same we can make a dedicated exception for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it there since I thought that Deepface returned "Spoof detected in the given image" everytime, but upon inspection of the recent changes they added, it returns a different message under ValueError, so, $errorResult['error'] can be any error thrown by the script.

I can remove the comment if you want.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, please remove it. Or if there is any special string we can match to a special exception do that one. But I'm fine with one exception for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

src/DeepFace.php Show resolved Hide resolved
@Gummibeer Gummibeer added the enhancement New feature or request label Jun 24, 2024
@Gummibeer Gummibeer linked an issue Jun 24, 2024 that may be closed by this pull request
src/DeepFace.php Outdated Show resolved Hide resolved
@pablo-gbr
Copy link
Contributor Author

I've seen #12 and forgot to point out that this update works with v0.0.92 of deepface, old versions of this package should work with <= v0.0.91

Copy link
Member

@Gummibeer Gummibeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it - thanks a lot! 🥳

@Gummibeer Gummibeer merged commit bc26991 into Astrotomic:main Jun 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

Update package
2 participants