我最近组了一个NAS,不过这个NAS目前的相册还没有ai功能,不能识别人物,虽然系统官方说AI快了快了,但是我还是想着尝试先找个开源方案折腾一下看看,然后我找到了PhotoPrism。

PhotoPrism 是一款由前 Google 工程师 Michael Mayer 发起的项目,一个开源、AI驱动的照片管理工具,自2018年发布以来,已经在 GitHub 上获得了近34,000颗星,并且拥有超过200位贡献者。该项目的核心理念围绕隐私优先、去中心化部署、AI驱动的功能以及用户友好的界面设计展开。

先说结论,识别的效果不太行,至少比我手机自带的相册差一点。

来看看表现吧,我的NAS是N100的CPU,索引的时候,1300多的图片,耗时是928秒。负载情况如下图:

cpu.png

索引.png

然后人脸识别的效果也比较差,1300多张图片,就识别出了2个人~

然后对于位置的识别也是差点意思,同一个视频,飞牛自带的可以识别到贺龙体育场~zjl.png

而且看官方文档,这个地点识别也会有些限制。

limit.png

虽然但是,还是走一遍流程,来个安装指南。安装很简单,我喜欢用docker-compose来安装~

先上docker-compose.yaml:

这边可以直接安装官方文档把docke-compose.yaml 文件下载下来

wget https://dl.photoprism.app/docker/compose.yaml
services:
  photoprism:
    image: docker.unsee.tech/photoprism/photoprism:latest
    stop_grace_period: 10s
    depends_on:
      - mariadb
    security_opt:
      - seccomp:unconfined
      - apparmor:unconfined

    ports:
      - "22342:2342"
    environment:
      PHOTOPRISM_ADMIN_USER: "xx"                 # admin login username
      PHOTOPRISM_ADMIN_PASSWORD: "xx"          # initial admin password (8-72 characters)
      PHOTOPRISM_AUTH_MODE: "password"               # authentication mode (public, password)
      PHOTOPRISM_SITE_URL: "http://localhost:22342/"  # server URL in the format "http(s)://domain.name(:port)/(path)"
      PHOTOPRISM_DISABLE_TLS: "false"                # disables HTTPS/TLS even if the site URL starts with https:// and a certificate is available
      PHOTOPRISM_DEFAULT_TLS: "true"                 # defaults to a self-signed HTTPS/TLS certificate if no other certificate is available
      PHOTOPRISM_ORIGINALS_LIMIT: 5000               # file size limit for originals in MB (increase for high-res video)
      PHOTOPRISM_HTTP_COMPRESSION: "gzip"            # improves transfer speed and bandwidth utilization (none or gzip)
      PHOTOPRISM_LOG_LEVEL: "info"                   # log level: trace, debug, info, warning, error, fatal, or panic
      PHOTOPRISM_READONLY: "false"                   # do not modify originals directory (reduced functionality)
      PHOTOPRISM_EXPERIMENTAL: "false"               # enables experimental features
      PHOTOPRISM_DISABLE_CHOWN: "false"              # disables updating storage permissions via chmod and chown on startup
      PHOTOPRISM_DISABLE_WEBDAV: "false"             # disables built-in WebDAV server
      PHOTOPRISM_DISABLE_SETTINGS: "false"           # disables settings UI and API
      PHOTOPRISM_DISABLE_TENSORFLOW: "false"         # disables all features depending on TensorFlow
      PHOTOPRISM_DISABLE_FACES: "false"              # disables face detection and recognition (requires TensorFlow)
      PHOTOPRISM_DISABLE_CLASSIFICATION: "false"     # disables image classification (requires TensorFlow)
      PHOTOPRISM_DISABLE_VECTORS: "false"            # disables vector graphics support
      PHOTOPRISM_DISABLE_RAW: "false"                # disables indexing and conversion of RAW images
      PHOTOPRISM_RAW_PRESETS: "false"                # enables applying user presets when converting RAW images (reduces performance)
      PHOTOPRISM_SIDECAR_YAML: "true"                # creates YAML sidecar files to back up picture metadata
      PHOTOPRISM_BACKUP_ALBUMS: "true"               # creates YAML files to back up album metadata
      PHOTOPRISM_BACKUP_DATABASE: "true"             # creates regular backups based on the configured schedule
      PHOTOPRISM_BACKUP_SCHEDULE: "daily"            # backup SCHEDULE in cron format (e.g. "0 12 * * *" for daily at noon) or at a random time (daily, weekly)
      PHOTOPRISM_INDEX_SCHEDULE: ""                  # indexing SCHEDULE in cron format (e.g. "@every 3h" for every 3 hours; "" to disable)
      PHOTOPRISM_AUTO_INDEX: 300                     # delay before automatically indexing files in SECONDS when uploading via WebDAV (-1 to disable)
      PHOTOPRISM_AUTO_IMPORT: -1                     # delay before automatically importing files in SECONDS when uploading via WebDAV (-1 to disable)
      PHOTOPRISM_DETECT_NSFW: "false"                # automatically flags photos as private that MAY be offensive (requires TensorFlow)
      PHOTOPRISM_UPLOAD_NSFW: "true"                 # allows uploads that MAY be offensive (no effect without TensorFlow)
      # PHOTOPRISM_DATABASE_DRIVER: "sqlite"         # SQLite is an embedded database that does not require a separate database server
      PHOTOPRISM_DATABASE_DRIVER: "mysql"            # MariaDB 10.5.12+ (MySQL successor) offers significantly better performance compared to SQLite
      PHOTOPRISM_DATABASE_SERVER: "mariadb:3306"     # MariaDB database server (hostname:port)
      PHOTOPRISM_DATABASE_NAME: "photoprism"         # MariaDB database schema name
      PHOTOPRISM_DATABASE_USER: "photoprism"         # MariaDB database user name
      PHOTOPRISM_DATABASE_PASSWORD: "WLTYgzuL1LTQbZHe6zhQ"       # MariaDB database user password
      PHOTOPRISM_SITE_CAPTION: "AI-Powered Photos App"
      PHOTOPRISM_SITE_DESCRIPTION: ""                # meta site description
      PHOTOPRISM_SITE_AUTHOR: ""                     # meta site author

    working_dir: "/photoprism" # do not change or remove
   
    volumes:

      - type: bind
        source: /vol2/1000/Photos/MobileBackup/old
        target: /photoprism/originals/old
        read_only: true
      - "/vol3/1000/PhotoPrism/storage:/photoprism/storage"

  mariadb:
    image: docker.unsee.tech/mariadb:11
    restart: unless-stopped
    stop_grace_period: 5s
    security_opt: # see https://github.com/MariaDB/mariadb-docker/issues/434#issuecomment-1136151239
      - seccomp:unconfined
      - apparmor:unconfined
    command: --innodb-buffer-pool-size=512M --transaction-isolation=READ-COMMITTED --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --max-connections=512 --innodb-rollback-on-timeout=OFF --innodb-lock-wait-timeout=120
    ## Never store database files on an unreliable device such as a USB flash drive, an SD card, or a shared network folder:
    volumes:
      - "/vol3/1000/安装的软件/PhotoPrism/database:/var/lib/mysql" # DO NOT REMOVE
    environment:
      MARIADB_AUTO_UPGRADE: "1"
      MARIADB_INITDB_SKIP_TZINFO: "1"
      MARIADB_DATABASE: "photoprism"
      MARIADB_USER: "photoprism"
      MARIADB_PASSWORD: "xx"
      MARIADB_ROOT_PASSWORD: "xx"
  watchtower:
    restart: unless-stopped
    image: docker.unsee.tech/containrrr/watchtower
    profiles: ["update"]
    environment:
      WATCHTOWER_CLEANUP: "true"
      WATCHTOWER_POLL_INTERVAL: 7200
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"

这个docker-compose.yaml我修改了一部分,主要就是替换默认的admin用户名(PHOTOPRISM_ADMIN_USER)、密码(PHOTOPRISM_ADMIN_PASSWORD)、暴露的端口号(PHOTOPRISM_SITE_URL)、数据库的密码(PHOTOPRISM_DATABASE_PASSWORD)。数据库的密码有两个地方,我第一次部署的时候漏掉了一个没改,折腾了半天服务起不来。。

关于挂载目录也有两点修改:

  • 挂载的相册目录的模式是只读的(因为是只读模式,这个会影响webdav和web upload、delete的一些功能)

      - type: bind
        source: /vol2/1000/Photos/MobileBackup/xxx
        target: /photoprism/originals/xxx
        read_only: true
  • /photoprism/storage挂载的是ssd盘(官方推荐这么做~)

另外在docker image部分用的是国内的镜像源:

  photoprism:
    image: docker.unsee.tech/photoprism/photoprism:latest

  mariadb:
    image: docker.unsee.tech/mariadb:11

  watchtower:
    restart: unless-stopped
    image: docker.unsee.tech/containrrr/watchtower

其他的没有改,有需要的朋友可以进一步仔细研究一下~

启动成功并且登录成功之后,首先需要到资料库里面去索引一下:

library.png

等待索引之后就可以看到数据了,瞬间人物标签~

项目地址:https://docs.photoprism.app/

到这里基本上就完成了,有什么欢迎评论区留言讨论,也欢迎大家关注我的公众号~

Snipaste_2024-12-07_11-05-00.png