-
Notifications
You must be signed in to change notification settings - Fork 43
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
Zero safety #398
Zero safety #398
Conversation
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only understood the parts avoiding the division by zero...
$distance = new Euclidean(); | ||
$distanceValue = $distance->compute($centroid, $this->faceDetection->getVector()); | ||
// Set threshold to avoid recreating the same mistake | ||
$this->faceDetection->setThreshold($distanceValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we only want to calculate and set a threshold if there's more than the one face in the cluster, otherwise we do a useless calculation.
@@ -107,7 +107,8 @@ public function calculateClusters(string $userId) { | |||
/** @var FaceDetection $detection */ | |||
$detection = $item[0]; | |||
$distance = new Euclidean(); | |||
if ($detection->getThreshold() > 0.0) { | |||
// If threshold is larger than 0 and $clusterCentroid is not the null vector | |||
if ($detection->getThreshold() > 0.0 && count(array_filter($clusterCentroid, fn($el) => $el !== 0.0)) > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the centroid could not be calculated, because there were zero detections in the cluster (see below), the centroid will be the null vector (count(array_filter($clusterCentroid, fn($el) => $el !== 0.0)) > 0
checks if it is not the null vector). Then we don't want to apply the threshold either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanations.
fixes #397