From 622ff919ff9e8fc524671a1fe4559af4ac01a79a Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Sun, 19 Mar 2023 15:45:40 +0100 Subject: [PATCH] enh(ClusterFaces): Add batch-size option Signed-off-by: Marcel Klehr --- lib/Command/ClusterFaces.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Command/ClusterFaces.php b/lib/Command/ClusterFaces.php index 984ae78e..1051486e 100644 --- a/lib/Command/ClusterFaces.php +++ b/lib/Command/ClusterFaces.php @@ -12,6 +12,7 @@ use OCP\DB\Exception; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class ClusterFaces extends Command { @@ -35,7 +36,8 @@ public function __construct(Logger $logger, FaceDetectionMapper $detectionMapper */ protected function configure() { $this->setName('recognize:cluster-faces') - ->setDescription('Cluster detected faces per user'); + ->setDescription('Cluster detected faces per user (Memory usage will grow with O(n²): n=2000: 450MB, n=4000: 700MB, n=5000: 1200MB)') + ->addOption('batch-size', 'b', InputOption::VALUE_REQUIRED, 'The number of face detections to cluster in one go. 0 for no limit.', 0); } /** @@ -59,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($userIds as $userId) { $this->logger->info('Clustering face detections for user ' . $userId); try { - $this->clusterAnalyzer->calculateClusters($userId); + $this->clusterAnalyzer->calculateClusters($userId, $input->getOption('batch-size')); } catch (\JsonException|Exception $e) { $this->logger->error($e->getMessage(), ['exception' => $e]); }