matiasdelellis / facerecognition

Nextcloud app that implement a basic facial recognition system.
GNU Affero General Public License v3.0
517 stars 46 forks source link

DivisionByZeroError: CreateClustersTask.php:168 #773

Open mrishab opened 2 months ago

mrishab commented 2 months ago

I started getting this error when I run face:background_job. It wasn't occurring before. I didn't change any configuration.

Make sure you read all the documentation, and the FAQ, and that the issue has not been reported before. :wink:

Expected behaviour

Actual behaviour

Steps to reproduce

  1. Run php occ face:background_job

Server configuration

Client configuration

Logs

$ php occ face:background_job

1/8 - Executing task CheckRequirementsTask (Check all requirements)
2/8 - Executing task CheckCronTask (Check that service is started from either cron or from command)
3/8 - Executing task DisabledUserRemovalTask (Purge all the information of a user when disable the analysis.)
4/8 - Executing task StaleImagesRemovalTask (Crawl for stale images (either missing in filesystem or under .nomedia) and remove them from DB)
5/8 - Executing task CreateClustersTask (Create new persons or update existing persons)
    Skipping cluster creation, not enough data (yet) collected. For cluster creation, you need either one of the following:
    * have 1000 faces already processed
    * or you need to have 95% of you images processed
    Use stats command to track progress
    Clusters already exist, estimated there is no need to recreate them
    Face clustering will be created for the first time.
    There are 0 faces for clustering
An unhandled exception has been thrown:
DivisionByZeroError: Division by zero in /var/www/html/custom_apps/facerecognition/lib/BackgroundJob/Tasks/CreateClustersTask.php:168
Stack trace:
#0 /var/www/html/custom_apps/facerecognition/lib/BackgroundJob/Tasks/CreateClustersTask.php(90): OCA\FaceRecognition\BackgroundJob\Tasks\CreateClustersTask->createClusterIfNeeded('admin')
#1 /var/www/html/custom_apps/facerecognition/lib/BackgroundJob/BackgroundService.php(150): OCA\FaceRecognition\BackgroundJob\Tasks\CreateClustersTask->execute(Object(OCA\FaceRecognition\BackgroundJob\FaceRecognitionContext))
#2 /var/www/html/custom_apps/facerecognition/lib/Command/BackgroundCommand.php(192): OCA\FaceRecognition\BackgroundJob\BackgroundService->execute(0, false, NULL, NULL, 'default-mode')
#3 /var/www/html/3rdparty/symfony/console/Command/Command.php(298): OCA\FaceRecognition\Command\BackgroundCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#4 /var/www/html/3rdparty/symfony/console/Application.php(1040): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#5 /var/www/html/3rdparty/symfony/console/Application.php(301): Symfony\Component\Console\Application->doRunCommand(Object(OCA\FaceRecognition\Command\BackgroundCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#6 /var/www/html/3rdparty/symfony/console/Application.php(171): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#7 /var/www/html/lib/private/Console/Application.php(213): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#8 /var/www/html/console.php(113): OC\Console\Application->run()
#9 /var/www/html/occ(11): require_once('/var/www/html/c...')

Background task log with debug.

sudo -u apache php occ -vvv face:background_job ``` Insert your background log here ```

Web server error log

Web server error log ``` Insert your webserver log here ```

Nextcloud log (data/nextcloud.log)

Nextcloud log ``` Insert your Nextcloud log here ```

Browser log

Browser log ``` Insert your browser log here, this could for example include: a) The javascript console log b) The network log c) ... ```
vwbusguy commented 2 months ago

It looks like it has evaluated your pictures but detected no faces in any of them and hit an unhandled exception. I assume this error goes away if the user has any pictures with detectable faces in it, but you'll probably need to pass --defer-clustering to the background task so that it will attempt the face detection first before hitting this divide by zero and breaking during clustering before it otherwise would get to the detection.

Still seems like a bug that needs fixing because one user having this condition might break things for other users since the script bails at that point.

matiasdelellis commented 2 months ago

D'Oh!. I didn't consider it... I'll fix it tomorrow, but as vwbusguy says, you can use the --defer-clustering option.