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

Zero safety #398

Merged
merged 1 commit into from
Oct 20, 2022
Merged

Zero safety #398

merged 1 commit into from
Oct 20, 2022

Conversation

marcelklehr
Copy link
Member

fixes #397

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Copy link
Member

@julien-nc julien-nc left a 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);
Copy link
Member Author

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) {
Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanations.

@marcelklehr marcelklehr merged commit 396bfa3 into master Oct 20, 2022
@marcelklehr marcelklehr deleted the fix/zero-safety branch October 20, 2022 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Division by zero in FaceClusterAnalyzer
2 participants