Skip to content

Commit

Permalink
The same but to batched descriptors..
Browse files Browse the repository at this point in the history
1.10 % less memory, totaling 42,99 % reduction..
  • Loading branch information
matiasdelellis committed Aug 2, 2024
1 parent 35eb454 commit efb7a8c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/BackgroundJob/Tasks/CreateClustersTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private function getNewClusters(array $faces): array {
$face1 = $faces[$i];
for ($j = $i; $j < $faces_count; $j++) {
$face2 = $faces[$j];
$distance = dlib_vector_length($face1->descriptor, $face2->descriptor);
$distance = dlib_vector_length($face1['descriptor'], $face2['descriptor']);
if ($distance < $sensitivity) {
$edges[] = array($i, $j);
}
Expand All @@ -338,7 +338,7 @@ private function getNewClusters(array $faces): array {
$face1 = $faces[$i];
for ($j = $i; $j < $faces_count; $j++) {
$face2 = $faces[$j];
$distance = Euclidean::distance($face1->descriptor, $face2->descriptor);
$distance = Euclidean::distance($face1['descriptor'], $face2['descriptor']);
if ($distance < $sensitivity) {
$edges[] = array($i, $j);
}
Expand All @@ -363,7 +363,7 @@ private function getNewClusters(array $faces): array {
if (!isset($newClusters[$newChineseClustersByIndex[$i]])) {
$newClusters[$newChineseClustersByIndex[$i]] = array();
}
$newClusters[$newChineseClustersByIndex[$i]][] = $faces[$i]->id;
$newClusters[$newChineseClustersByIndex[$i]][] = $faces[$i]['id'];
}
return $newClusters;
}
Expand Down
14 changes: 13 additions & 1 deletion lib/Db/FaceMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,20 @@ public function findDescriptorsBathed (array $faceIds): array {
$qb->select('id', 'descriptor')
->from($this->getTableName(), 'f')
->where($qb->expr()->in('id', $qb->createParameter('face_ids')));

$qb->setParameter('face_ids', $faceIds, IQueryBuilder::PARAM_INT_ARRAY);
return $this->findEntities($qb);

$descriptors = [];
$result = $qb->executeQuery();
while ($row = $result->fetch()) {
$descriptors[] = [
'id' => $row['id'],
'descriptor' => json_decode($row['descriptor'])
];
}
$result->closeCursor();

return $descriptors;
}

/**
Expand Down

0 comments on commit efb7a8c

Please sign in to comment.