Container and face recognisize

Hey everyone! I’ve been setting up the face recognition feature on my Nextcloud instance and I have a question about the proper way to manage cron jobs for it.

I’ve set up a cron job to run cron.php regularly for general Nextcloud maintenance. My question is, do I need to run additional occ scan commands specifically for the face recognition to work properly? Or is executing cron.php sufficient for the face recognition tasks as well?

I’m curious about whether running cron.php alone handles all necessary operations, or if I should include commands like occ files:scan --all, occ recognize:classify, and occ recognize:cluster-faces in my cron jobs to ensure the face recognition process runs smoothly.

Appreciate any insights or tips from those who have experience with this. Thanks in advance!

At my crontab -e i run this file:
/home/docker-projects/nextcloud/cronjob-copy-scan-files.sh

content is:
cat /home/docker-projects/nextcloud/cronjob-copy-scan-files.sh

#!/bin/bash

LOG_DIR="/home/docker-projects/nextcloud/cron_logs"
LOCKFILE="/tmp/sync_and_scan.lock"

# Erstelle das Log-Verzeichnis, falls es nicht existiert
mkdir -p "$LOG_DIR"

# Aktuelles Datum und Uhrzeit für die Log-Datei
LOGFILE="$LOG_DIR/cronjob_$(date +"%Y-%m-%d_%H-%M-%S").log"

# Funktion zum Begrenzen der Anzahl der Log-Dateien auf 50
cleanup_logs() {
    cd "$LOG_DIR"
    ls -tp | grep -v '/$' | tail -n +51 | xargs -I {} rm -- {}
}

# Funktion zum Hinzufügen von Zeitstempeln
log_with_date() {
    echo "$(date +"%Y-%m-%d %T"): $*" >> "$LOGFILE"
}

# Starte Logging
log_with_date "Cronjob gestartet."

# Prüfe, ob das Lock-File existiert
if [ -f "$LOCKFILE" ]; then
    log_with_date "Skript läuft bereits. Abbruch."
    exit 1
else
    # Erstelle das Lock-File
    touch "$LOCKFILE"

    # Führe die Befehle aus
    log_with_date "Starte Synchronisation der Fotos vom NAS."
    rsync -av /home/nas/NasHome/Photos/ /home/docker-projects/nextcloud/NasFotos >> "$LOGFILE" 2>&1

    log_with_date "Starte Nextcloud Dateiscan."
    docker exec -u www-data nextcloud-app-1 php /var/www/html/occ files:scan your-admin-username >> "$LOGFILE" 2>&1

    log_with_date "Führe Nextcloud Cronjob aus."
    docker exec -u www-data nextcloud-app-1 php -f /var/www/html/cron.php >> "$LOGFILE" 2>&1

#    log_with_date "Stoppe eventuelle Hintergrundjobs."
#    docker exec -u www-data nextcloud-app-1 php /var/www/html/occ recognize:clear-background-jobs >> "$LOGFILE" 2>&1

#    log_with_date "Starte Gesichtserkennung."
#    docker exec -u www-data nextcloud-app-1 php /var/www/html/occ recognize:classify >> "$LOGFILE" 2>&1

#    log_with_date "Starte Gesichter-Clustering."
#    docker exec -u www-data nextcloud-app-1 php /var/www/html/occ recognize:cluster-faces >> "$LOGFILE" 2>&1

    # Entferne das Lock-File
    rm "$LOCKFILE"

    log_with_date "Cronjob beendet."

    # Aufräumen alter Log-Dateien
    cleanup_logs
fi

Here’s what my script currently does:

Creates a log directory at /home/docker-projects/nextcloud/cron_logs if it doesn’t already exist.
Generates a timestamped log file for each run of the script.
Limits the log files to 50, automatically deleting the oldest ones.
Checks for a lock file to prevent simultaneous runs.
Syncs photos from NAS to a Nextcloud folder.
Runs Nextcloud’s file scan for a specific user.
Executes Nextcloud’s cron.php for regular maintenance tasks.

I’ve commented out the parts related to face recognition (recognize:classify and recognize:cluster-faces) for now.

My questions for the community:

Does this script sufficiently cover the essential tasks for Nextcloud maintenance?
For face recognition features, should I include recognize:classify and recognize:cluster-faces in this script or handle them separately?
Any suggestions for improvements or best practices I should follow?
I’m especially interested in how to optimize this for performance and reliability. Thanks in advance for your insights and tips! :blush:

Hi @BoBBer446

I’m curious about whether running cron.php alone handles all necessary operations, or if I should include commands like occ files:scan --all, occ recognize:classify, and occ recognize:cluster-faces in my cron jobs to ensure the face recognition process runs smoothly.

You do not need to set up anything else other than cron jobs. Recognize will handle everything on its own.

2 Likes

Hi there!

Thanks for your input! So, if I understand correctly, once my cron job runs, the rsync script will copy the photos, and then all I need to do is call cron.php?

Would this mean my crontab -e should look something like this?

*/5 * * * *  rsync -av /home/nas/NasHome/Photos/ /home/docker-projects/nextcloud/NasFotos
*/5 * * * *  docker exec -u www-data nextcloud-app-1 php -f /var/www/html/cron.php

In this setup, the command docker exec -u www-data nextcloud-app-1 php /var/www/html/occ files:scan your-admin-username is not required, right?

I’m noticing that not all newly added images are being tagged. Some images have been tagged, but many haven’t. Also, I’ve observed that the processor is almost constantly running at 100%.

Could this be related to how the cron jobs are set up, or is there another aspect I should consider?

Any further insights would be greatly appreciated!

I’ve observed that the processor is almost constantly running at 100%.

Check out the admin panel of recognize in the admin settings. You can allow or disable concurrent job runs there as well as set the amount of cores to be used.

In this setup, the command docker exec -u www-data nextcloud-app-1 php /var/www/html/occ files:scan your-admin-username is not required, right?

Anytime you change user’s files on disk, you will need files:scan – this has nothing to do with recognize, it’s how nextcloud works.

1 Like

Hello Nextcloud Community,

I’ve encountered a challenge with the face recognition background job in my containerized Nextcloud setup. Initially, I couldn’t find any cronjobs within the container, and it wasn’t clear how they should be managed in this environment. It seemed that no additional recognitions were being performed automatically.

To work around this, I set up a cronjob on the host system:

*/30 * * * * docker exec -u www-data nextcloud-app-1 php -f /var/www/nextcloud/occ face:background_job -t 1500

This ensures the job runs for 25 minutes every 30 minutes. I hope this solution can assist others facing similar issues with container-based Nextcloud instances.

Best regards

Source:

Hello @BoBBer446

I would like to point out that there are two distinct apps for nextcloud that provide face recognition functionality: recognize and face_recognition. I am not sure if you are aware of this.

1 Like

I recently encountered a mix-up with two applications within my Nextcloud setup. After resolving that, I’ve noticed a persistent issue that doesn’t seem to be affected by the earlier confusion: the categorization of new files in Nextcloud doesn’t appear to be working correctly.

It seems that when new files are added, they are not being categorized as expected. I’m not entirely sure if this is a configuration issue or something else.

Has anyone else experienced similar issues with file categorization in Nextcloud? Any insights or suggestions on how to troubleshoot this would be greatly appreciated.

Thanks in advance for your help!

Which app are you using for “file categorization”? If you are using recognize, can you post a screenshot of what the recognize admin panel looks like for you?

Im using this:

Thank you :slight_smile:

can you post a screenshot of what the recognize admin panel looks like for you?

Sure here it is :slight_smile:






If i click any Button here:


nothing changed and no response is there

Example:

This image is just one of thousands that haven’t been analyzed. Many other high-resolution images that clearly depict dogs, cats, or humans also went unrecognized because they were not properly classified. I’m unsure how to solve or address this issue.

What makes you think that recognize is finished? From where I’m sitting you have 12000 files still in the object recognition queue. Sit back and wait, this will take some time.

I believe the recognition process is finished because I manually executed the classification and clustering, and both have completed. Additionally, HTOP doesn’t show any further system load, indicating that no significant background processing is taking place.

I’ll wait a few days and check again, but I don’t feel like the queue is diminishing or being processed.

I believe the recognition process is finished because I manually executed the classification and clustering, and both have completed.

Ah ok. that makes sense

Have they not been analyzed or not been tagged? Recognize should analyze everything, but it might not add a tag if it doesn’t detect anything. All images should at least have an admin-only tag called “tagged by recognize …” to indicate they’ve been processed.

Something went wrong. I think I need a bit of time to check. Currently, I’m confused about that.

I reinstalled the plugin. Disable > delete > install.

{"reqId":"WRevTxmsC8VVpF8jbRwW","level":3,"time":"2023-12-20T15:34:17+00:00","remoteAddr":"192.168.178.22","user":"your-admin-username","app":"PHP","method":"PROPFIND","url":"/remote.php/dav/recognize/your-admin-username/unassigned-faces","message":"Undefined property: OCA\\Recognize\\Dav\\Faces\\UnassignedFacesHome::$metadataManager at /var/www/html/custom_apps/recognize/lib/Dav/Faces/UnassignedFacesHome.php#108","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","version":"28.0.0.11","data":{"app":"PHP"}}
{"reqId":"WRevTxmsC8VVpF8jbRwW","level":3,"time":"2023-12-20T15:34:17+00:00","remoteAddr":"192.168.178.22","user":"your-admin-username","app":"webdav","method":"PROPFIND","url":"/remote.php/dav/recognize/your-admin-username/unassigned-faces","message":"OCA\\Recognize\\Dav\\Faces\\UnassignedFacePhoto::__construct(): Argument #5 ($preview) must be of type OCP\\IPreview, null given, called in /var/www/html/custom_apps/recognize/lib/Dav/Faces/UnassignedFacesHome.php on line 108","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36","version":"28.0.0.11","exception":{"Exception":"TypeError","Message":"OCA\\Recognize\\Dav\\Faces\\UnassignedFacePhoto::__construct(): Argument #5 ($preview) must be of type OCP\\IPreview, null given, called in /var/www/html/custom_apps/recognize/lib/Dav/Faces/UnassignedFacesHome.php on line 108","Code":0,"Trace":[{"file":"/var/www/html/custom_apps/recognize/lib/Dav/Faces/UnassignedFacesHome.php","line":108,"function":"__construct","class":"OCA\\Recognize\\Dav\\Faces\\UnassignedFacePhoto","type":"->","args":[["OCA\\Recognize\\Db\\FaceDetectionMapper"],"*** sensitive parameters replaced ***",["OC\\Files\\Node\\LazyUserFolder"],["OC\\TagManager"],null,["OC\\PreviewManager"]]},{"function":"OCA\\Recognize\\Dav\\Faces\\{closure}","class":"OCA\\Recognize\\Dav\\Faces\\UnassignedFacesHome","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/custom_apps/recognize/lib/Dav/Faces/UnassignedFacesHome.php","line":107,"function":"array_map","args":[["Closure"],["*** sensitive parameters replaced ***",["OCA\\Recognize\\Db\\FaceDetection",1],["OCA\\Recognize\\Db\\FaceDetection",2],["OCA\\Recognize\\Db\\FaceDetection",3],["OCA\\Recognize\\Db\\FaceDetection",5],"And 2739 more entries, set log level to debug to see all entries"]]},{"file":"/var/www/html/custom_apps/recognize/lib/Dav/Faces/PropFindPlugin.php","line":71,"function":"getChildren","class":"OCA\\Recognize\\Dav\\Faces\\UnassignedFacesHome","type":"->","args":[]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/PropFind.php","line":95,"function":"OCA\\Recognize\\Dav\\Faces\\{closure}","class":"OCA\\Recognize\\Dav\\Faces\\PropFindPlugin","type":"->","args":["*** sensitive parameters replaced ***"]},{"file":"/var/www/html/custom_apps/recognize/lib/Dav/Faces/PropFindPlugin.php","line":71,"function":"handle","class":"Sabre\\DAV\\PropFind","type":"->","args":["{http://nextcloud.org/ns}nbItems",["Closure"]]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"propFind","class":"OCA\\Recognize\\Dav\\Faces\\PropFindPlugin","type":"->","args":[["Sabre\\DAV\\PropFind"],["OCA\\Recognize\\Dav\\Faces\\UnassignedFacesHome"]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":1052,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["propFind",[["Sabre\\DAV\\PropFind"],["OCA\\Recognize\\Dav\\Faces\\UnassignedFacesHome"]]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":984,"function":"getPropertiesByNode","class":"Sabre\\DAV\\Server","type":"->","args":[["Sabre\\DAV\\PropFind"],["OCA\\Recognize\\Dav\\Faces\\UnassignedFacesHome"]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":1662,"function":"getPropertiesIteratorForPath","class":"Sabre\\DAV\\Server","type":"->","args":["recognize/your-admin-username/unassigned-faces",["{DAV:}getcontentlength","{DAV:}getcontenttype","{DAV:}getetag","{DAV:}getlastmodified","{DAV:}resourcetype","And 12 more entries, set log level to debug to see all entries"],0]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":1647,"function":"writeMultiStatus","class":"Sabre\\DAV\\Server","type":"->","args":[["Sabre\\Xml\\Writer",[],"/remote.php/dav/",["d","s","oc","nc"],[]],["Generator"],false]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/CorePlugin.php","line":346,"function":"generateMultiStatus","class":"Sabre\\DAV\\Server","type":"->","args":[["Generator"],false]},{"file":"/var/www/html/3rdparty/sabre/event/lib/WildcardEmitterTrait.php","line":89,"function":"httpPropFind","class":"Sabre\\DAV\\CorePlugin","type":"->","args":[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":472,"function":"emit","class":"Sabre\\DAV\\Server","type":"->","args":["method:PROPFIND",[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":253,"function":"invokeMethod","class":"Sabre\\DAV\\Server","type":"->","args":[["Sabre\\HTTP\\Request"],["Sabre\\HTTP\\Response"]]},{"file":"/var/www/html/3rdparty/sabre/dav/lib/DAV/Server.php","line":321,"function":"start","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/lib/Server.php","line":370,"function":"exec","class":"Sabre\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/apps/dav/appinfo/v2/remote.php","line":35,"function":"exec","class":"OCA\\DAV\\Server","type":"->","args":[]},{"file":"/var/www/html/remote.php","line":172,"args":["/var/www/html/apps/dav/appinfo/v2/remote.php"],"function":"require_once"}],"File":"/var/www/html/custom_apps/recognize/lib/Dav/Faces/UnassignedFacePhoto.php","Line":18,"message":"OCA\\Recognize\\Dav\\Faces\\UnassignedFacePhoto::__construct(): Argument #5 ($preview) must be of type OCP\\IPreview, null given, called in /var/www/html/custom_apps/recognize/lib/Dav/Faces/UnassignedFacesHome.php on line 108","exception":{},"CustomMessage":"OCA\\Recognize\\Dav\\Faces\\UnassignedFacePhoto::__construct(): Argument #5 ($preview) must be of type OCP\\IPreview, null given, called in /var/www/html/custom_apps/recognize/lib/Dav/Faces/UnassignedFacesHome.php on line 108"}}
{"reqId":"dyIf0ouaxpbfRT3Q1Vfq","level":2,"time":"2023-12-20T15:49:31+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 543 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"dyIf0ouaxpbfRT3Q1Vfq","level":2,"time":"2023-12-20T15:49:31+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 586 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"dyIf0ouaxpbfRT3Q1Vfq","level":2,"time":"2023-12-20T15:49:31+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 600 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"dyIf0ouaxpbfRT3Q1Vfq","level":2,"time":"2023-12-20T15:49:31+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 643 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"dyIf0ouaxpbfRT3Q1Vfq","level":2,"time":"2023-12-20T15:49:32+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 813 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"dyIf0ouaxpbfRT3Q1Vfq","level":2,"time":"2023-12-20T15:49:32+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 820 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"JopSZWezWQGRGHQ3sjKc","level":2,"time":"2023-12-20T16:47:26+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 543 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"r6gNoVVanX1ey0dyJk4k","level":2,"time":"2023-12-20T17:17:26+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 586 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"r6gNoVVanX1ey0dyJk4k","level":2,"time":"2023-12-20T17:17:26+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 600 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"dvcPVHZWVLUOAyvtWMnz","level":2,"time":"2023-12-20T17:37:27+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 643 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"50yw3K6MjmJAeo9wJuKF","level":2,"time":"2023-12-20T18:37:30+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 813 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}
{"reqId":"50yw3K6MjmJAeo9wJuKF","level":2,"time":"2023-12-20T18:37:30+00:00","remoteAddr":"","user":"--","app":"recognize","method":"","url":"--","message":"Failed to generate preview of 820 with dimension 1024 with nextcloud preview manager: No provider successfully handled the preview generation","userAgent":"--","version":"28.0.0.11","data":{"app":"recognize"}}

Which version of Nextcloud and which version of recognize?

image

Recognize 6.0.1

$ cat docker-compose.yml
version: '3.8'

services:
  db:
    image: postgres
    restart: always
    volumes:
      - /home/docker-projects/nextcloud/volumes/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=nextcloud
      - POSTGRES_USER=nextcloud
      - POSTGRES_PASSWORD=your-db-password

  redis:
    image: redis:alpine
    restart: always

  app:
    build: ./nextcloud-custom
    ports:
      - 8009:80
    links:
      - db
      - redis
    volumes:
      - /home/docker-projects/nextcloud/volumes/html:/var/www/html
      - /home/docker-projects/nextcloud/NasFotos:/mnt/NasPhotos
    restart: always
    environment:
      - POSTGRES_HOST=db
      - POSTGRES_DB=nextcloud
      - POSTGRES_USER=nextcloud
      - POSTGRES_PASSWORD=your-db-password
      - NEXTCLOUD_ADMIN_USER=your-admin-username
      - NEXTCLOUD_ADMIN_PASSWORD=your-admin-password
      - NEXTCLOUD_DEFAULT_PHONE_REGION=DE
      - REDIS_HOST=redis
      - PHP_MEMORY_LIMIT=1024M
$ cat Dockerfile
FROM nextcloud:latest
RUN apt-get update && \
    apt-get install -y libbz2-dev && \
    docker-php-ext-install bz2 && \
    apt-get install -y nano