Skip to content

Commit

Permalink
A bit more aggressively..
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasdelellis committed Oct 1, 2024
1 parent a3fb7fe commit cbf6ad8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/BackgroundJob/Tasks/CreateClustersTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,15 @@ private function createClusterIfNeeded(string $userId) {
$min_confidence = $this->settingsService->getMinimumConfidence();

$faces = $this->faceMapper->getGroupableFaces($userId, $modelId, $min_face_size, $min_confidence);
$nonGroupables = $this->faceMapper->getNonGroupableFaces($userId, $modelId, $min_face_size, $min_confidence);

$facesCount = count($faces);
$this->logInfo('There are ' . $facesCount . ' faces for clustering and '. count($nonGroupables) . ' that cannot be grouped.');
$this->logInfo('There are ' . $facesCount . ' faces for clustering.');

$noSlices = 1;
$noSlices = 0;
$sliceSize = $facesCount;

$defaultSlice = $this->settingsService->getClusterigBatchSize();
if ($defaultSlice > 0) {
if ($facesCount > 0 && $defaultSlice > 0) {
// The minimum batch size is 20000 faces
$defaultSlice = max($defaultSlice, 2000);
// The maximun batch size is the faces count.
Expand All @@ -184,16 +183,21 @@ private function createClusterIfNeeded(string $userId) {
}

// Append non groupable faces on a single step.
$nonGroupables = $this->faceMapper->getNonGroupableFaces($userId, $modelId, $min_face_size, $min_confidence);
$this->logInfo('We will add '. count($nonGroupables) . ' faces that cannot be grouped.');
$newClusters = array_merge($newClusters, $this->getFakeClusters($nonGroupables));

// Cluster is associative array where key is person ID.
// Value is array of face IDs. For old clusters, person IDs are some existing person IDs,
// and for new clusters is whatever chinese whispers decides to identify them.
//
$currentClusters = $this->getCurrentClusters(array_merge($faces, $nonGroupables));

$this->logInfo(count($newClusters) . ' clusters found after clustering');

// Discard variables aggressively to improve memory consumption.
unset($faces);
unset($nonGroupables);

// New merge
$mergedClusters = $this->mergeClusters($currentClusters, $newClusters);

Expand Down

0 comments on commit cbf6ad8

Please sign in to comment.