标签: immich

  • 使用远程服务器加速 Immich 的机器学习推理

    为了显著提升 Immich 在执行照片和视频分析等任务时的机器学习推理性能,可以将 Immich 的机器学习容器部署在具备更强硬件性能(例如配备高性能 GPU 或专用 AI 加速卡的服务器)的远程服务器上。这种方式可以将计算密集型的推理工作负载从运行 Immich Server 的主服务器卸载,从而释放主服务器的资源并加快推理速度。

    1. 确保版本一致性

    重要提示

    1. Immich 服务器(即运行 Immich Web、API 和 Microservices 的主服务器)的版本必须与您计划在远程服务器上部署的机器学习服务容器的版本完全一致
    2. 如果这两个组件的版本不匹配,极有可能导致各种不可预期的错误、功能异常,甚至推理任务的彻底失败。为了确保系统的稳定性和功能的正常运行,请务必仔细核对并保持版本同步。

    2. 在远程系统上部署机器学习容器

    在您选定的远程服务器上,创建一个名为 docker-compose.yml 的文件。该文件将定义并配置 Immich 机器学习服务的 Docker 容器。请根据您的远程服务器的硬件配置以及您希望使用的加速后端选择合适的配置:

    name: immich_remote_ml
    
    services:
      immich-machine-learning:
        container_name: immich_machine_learning
        # For hardware acceleration, add one of -[armnn, cuda, rocm, openvino, rknn] to the image tag.
        # Example tag: ${IMMICH_VERSION:-release}-cuda
        image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
        # extends:
        #   file: hwaccel.ml.yml
        #   service: # set to one of [armnn, cuda, rocm, openvino, openvino-wsl, rknn] for accelerated inference - use the `-wsl` version for WSL2 where applicable
        volumes:
          - model-cache:/cache
        restart: always
        ports:
          - 3003:3003
    
    volumes:
      model-cache:

    3. 启动容器

    在远程服务器上执行以下命令启动服务:

    docker compose up -d

    4. 配置 Immich 使用远程推理服务

    在 Immich Web 界面中:

    • 进入 系统设置
    • 打开 系统管理 > 设置 > 机器学习设置
    • 将远程服务器的机器学习服务 URL 填入(例如:http://<远程服务器IP>:3003

    完成以上配置后,Immich Server 在需要进行机器学习推理时,例如人脸识别、物体识别、场景分类等,将会自动将这些请求发送到您配置的远程机器学习服务。这将利用远程服务器更强大的计算资源来加速推理过程,从而提升 Immich 的整体性能和用户体验。您可以通过观察 Immich 的任务队列和远程服务器的资源使用情况来验证远程推理是否正常工作。

  • 使用 Immich CLI 上传照片和视频

    要求

    在使用 Immich CLI 之前,请确保您的环境满足以下条件:

    • Node.js 20 或更高版本
    • npm(Node.js 包管理器)

    安装 Immich CLI

    全局安装

    使用 npm 进行全局安装 Immich CLI:

    npm i -g @immich/cli

    卸载旧版本

    如果您之前安装过旧版 CLI,建议先卸载以避免冲突:

    npm uninstall -g immich

    快速入门

    在使用 Immich CLI 之前,您需要先进行身份验证,并连接到您的 Immich 服务器。

    1. 认证登录

    您需要使用 API 密钥向 Immich 服务器进行身份验证。
    执行以下命令,将 [服务器地址][API 密钥] 替换为实际值:

    immich login [服务器地址] [API 密钥]

    示例:

    immich login http://192.168.1.216:2283/api HFEJ38DNSDUEG

    认证成功后:

    • CLI 会自动将您的凭据存储在 auth.yml 配置文件中。
    • 默认情况下,该文件位于 ~/.config/ 目录下。
    • 如果需要自定义存储目录,可以使用 -d 选项或 IMMICH_CONFIG_DIR 环境变量。

    安全提示:

    • 为确保账户安全,在使用完 CLI 后,建议执行 immich logout 注销,或手动删除 auth.yml 文件。

    2. 上传文件到 Immich 服务器

    上传单个或多个文件

    如果要上传单个文件或多个文件,可以直接指定文件路径:

    immich upload file1.jpg file2.jpg

    上传整个目录(默认不包含子文件夹)

    如果要上传目录中的所有文件(不包括子目录),可执行:

    immich upload directory/

    上传包含子文件夹的目录

    如果目录中包含多个子文件夹,并希望上传所有内容,请使用 --recursive 选项:

    immich upload --recursive directory/

    3. 预览上传内容

    如果不确定哪些文件会被上传,或者希望在执行前进行确认,可以使用 --dry-run 选项进行模拟运行:

    immich upload --dry-run --recursive directory/

    此命令不会实际上传文件,只会显示哪些文件将被上传。

    4. 提高上传性能

    跳过哈希计算

    默认情况下,Immich 在上传文件前会计算哈希值,以避免重复上传。
    如果您确定文件是唯一的,并希望加快上传速度,可以使用 --skip-hash 选项跳过哈希计算:

    immich upload --skip-hash --recursive directory/

    注意

    • Immich 服务器仍会进行哈希处理以执行重复数据删除,因此这个选项仅影响客户端性能。
    • 如果您的带宽充足,跳过哈希计算可以加快上传速度。

    5. 自动管理相册

    Immich CLI 支持自动创建相册,并根据文件夹名称或自定义名称进行管理。

    根据文件夹名称自动创建相册

    使用 --album 选项,Immich 会根据文件夹名称自动创建相册,并将对应文件上传到相册中:

    immich upload --album --recursive directory/

    上传文件到指定相册

    如果希望将所有文件上传到一个特定相册,可以使用 --album-name 选项:

    immich upload --album-name "My Summer Holiday" --recursive directory/

    6. 过滤上传文件

    有时,您可能需要跳过某些文件或目录,Immich 提供了 --ignore 选项来实现文件过滤。

    跳过特定文件或文件夹

    例如,如果您想跳过 Raw 文件夹下的所有内容,可以执行:

    immich upload --ignore **/Raw/** --recursive directory/

    排除多个文件类型

    可以使用多个 --ignore 规则,匹配不同的文件类型,例如排除 .tif 文件:

    immich upload --ignore **/Raw/** **/*.tif --recursive directory/

    7. 包含隐藏文件

    默认情况下,Immich 不会上传隐藏文件(文件名以 . 开头)。
    如果希望上传隐藏文件,可以使用 --include-hidden 选项:

    immich upload --include-hidden --recursive directory/

    获取 API 密钥

    使用 Immich CLI 之前,您需要一个 API 密钥,该密钥可以在 Web 界面的 用户设置面板 中获取。

    获取 API 密钥的步骤:

    1. 进入 Immich Web 管理界面
    2. 用户设置 页面中找到 API Key 选项
    3. 生成新的 API 密钥并复制,用于 CLI 登录
  • Debian12安装 Immich 进行自托管照片和视频

    Immich 是一个强大的自托管照片和视频管理解决方案,允许用户在自己的服务器上存储、管理和浏览照片,同时提供智能搜索、面部识别等 AI 功能,保护您的隐私。

    1. 介绍 Immich

    Immich 的主要功能

    • 自动备份:支持手机和桌面端自动同步照片和视频。
    • 智能搜索:基于 AI 的搜索和标签功能,快速查找照片。
    • 面部识别:自动识别照片中的人物并进行分类。
    • 隐私保护:完全自托管,确保数据不会泄露到第三方服务器。
    • 高效存储:支持增量备份和重复数据删除,优化存储空间。
    • 跨平台支持:支持 Android、iOS、Web 和桌面端访问。

    2. 安装 Docker 和 Docker Compose

    在 Linux 服务器上运行以下命令安装 Docker:

    curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh

    安装完成后,检查 Docker 版本:

    docker --version

    安装 Docker Compose:

    apt install -y docker-compose

    3. 下载 Immich 并配置环境变量

    3.1 创建 Immich 安装目录

    mkdir ./immich-app && cd ./immich-app

    3.2 下载官方 Docker Compose 文件

    # &nbsp;docker-compose.yml
    wget -O docker-compose.yml https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
    
    # .env
    wget -O .env https://github.com/immich-app/immich/releases/latest/download/example.env

    docker-compose.yml文件

    #
    # WARNING: To install Immich, follow our guide: https://immich.app/docs/install/docker-compose
    #
    # Make sure to use the docker-compose.yml of the current release:
    #
    # https://github.com/immich-app/immich/releases/latest/download/docker-compose.yml
    #
    # The compose file on main may not be compatible with the latest release.
    
    name: immich
    
    services:
      immich-server:
        container_name: immich_server
        image: ghcr.io/immich-app/immich-server:${IMMICH_VERSION:-release}
        # extends:
        #   file: hwaccel.transcoding.yml
        #   service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
        volumes:
          # Do not edit the next line. If you want to change the media storage location on your system, edit the value of UPLOAD_LOCATION in the .env file
          - ${UPLOAD_LOCATION}:/usr/src/app/upload
          - /etc/localtime:/etc/localtime:ro
        env_file:
          - .env
        ports:
          - '2283:2283'
        depends_on:
          - redis
          - database
        restart: always
        healthcheck:
          disable: false
    
      immich-machine-learning:
        container_name: immich_machine_learning
        # For hardware acceleration, add one of -[armnn, cuda, openvino] to the image tag.
        # Example tag: ${IMMICH_VERSION:-release}-cuda
        image: ghcr.io/immich-app/immich-machine-learning:${IMMICH_VERSION:-release}
        # extends: # uncomment this section for hardware acceleration - see https://immich.app/docs/features/ml-hardware-acceleration
        #   file: hwaccel.ml.yml
        #   service: cpu # set to one of [armnn, cuda, openvino, openvino-wsl] for accelerated inference - use the `-wsl` version for WSL2 where applicable
        volumes:
          - model-cache:/cache
        env_file:
          - .env
        restart: always
        healthcheck:
          disable: false
    
      redis:
        container_name: immich_redis
        image: docker.io/redis:6.2-alpine@sha256:148bb5411c184abd288d9aaed139c98123eeb8824c5d3fce03cf721db58066d8
        healthcheck:
          test: redis-cli ping || exit 1
        restart: always
    
      database:
        container_name: immich_postgres
        image: docker.io/tensorchord/pgvecto-rs:pg14-v0.2.0@sha256:739cdd626151ff1f796dc95a6591b55a714f341c737e27f045019ceabf8e8c52
        environment:
          POSTGRES_PASSWORD: ${DB_PASSWORD}
          POSTGRES_USER: ${DB_USERNAME}
          POSTGRES_DB: ${DB_DATABASE_NAME}
          POSTGRES_INITDB_ARGS: '--data-checksums'
        volumes:
          # Do not edit the next line. If you want to change the database storage location on your system, edit the value of DB_DATA_LOCATION in the .env file
          - ${DB_DATA_LOCATION}:/var/lib/postgresql/data
        healthcheck:
          test: >-
            pg_isready --dbname="$${POSTGRES_DB}" --username="$${POSTGRES_USER}" || exit 1;
            Chksum="$$(psql --dbname="$${POSTGRES_DB}" --username="$${POSTGRES_USER}" --tuples-only --no-align
            --command='SELECT COALESCE(SUM(checksum_failures), 0) FROM pg_stat_database')";
            echo "checksum failure count is $$Chksum";
            [ "$$Chksum" = '0' ] || exit 1
          interval: 5m
          start_interval: 30s
          start_period: 5m
        command: >-
          postgres
          -c shared_preload_libraries=vectors.so
          -c 'search_path="$$user", public, vectors'
          -c logging_collector=on
          -c max_wal_size=2GB
          -c shared_buffers=512MB
          -c wal_compression=on
        restart: always
    
    volumes:
      model-cache:

    .env文件

    # You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables
    
    # The location where your uploaded files are stored
    UPLOAD_LOCATION=./library
    # The location where your database files are stored
    DB_DATA_LOCATION=./postgres
    
    # To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
    # TZ=Etc/UTC
    
    # The Immich version to use. You can pin this to a specific version like "v1.71.0"
    IMMICH_VERSION=release
    
    # Connection secret for postgres. You should change it to a random password
    # Please use only the characters `A-Za-z0-9`, without special characters or spaces
    DB_PASSWORD=postgres
    
    # The values below this line do not need to be changed
    ###################################################################################
    DB_USERNAME=postgres
    DB_DATABASE_NAME=immich

    3.3 配置环境变量

    编辑 .env 文件:

    nano .env

    修改以下关键参数:

    # You can find documentation for all the supported env variables at https://immich.app/docs/install/environment-variables
    
    # The location where your uploaded files are stored
    UPLOAD_LOCATION=./library
    # The location where your database files are stored
    DB_DATA_LOCATION=./postgres
    
    # To set a timezone, uncomment the next line and change Etc/UTC to a TZ identifier from this list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
    # TZ=Etc/UTC
    
    # The Immich version to use. You can pin this to a specific version like "v1.71.0"
    IMMICH_VERSION=release
    
    # Connection secret for postgres. You should change it to a random password
    # Please use only the characters `A-Za-z0-9`, without special characters or spaces
    DB_PASSWORD=postgres
    
    # The values below this line do not need to be changed
    ###################################################################################
    DB_USERNAME=postgres
    DB_DATABASE_NAME=immich
    • 指定备份存储位置:
      • 请在UPLOAD_LOCATION中填写您希望存储备份文件的绝对路径。建议选择服务器上具有足够可用空间的新建目录,以确保备份顺利进行。
    • 设置数据库密码:
      • 强烈建议您修改DB_PASSWORD,为其设置一个自定义的强密码。由于PostgreSQL服务仅在本地Docker容器内运行,此密码用于本地身份验证。为避免Docker在解析密码时出现问题,请仅使用A-Za-z0-9范围内的字符。您可以使用pwgen等工具生成安全的随机密码。

    4. 启动 Immich

    运行 Docker Compose 启动 Immich

    docker-compose.yml 所在目录运行:

    docker compose up -d

    5. 访问 Immich Web 界面

    在浏览器中输入:

    http://<服务器IP>:2283

    首次访问时,需要注册一个管理员账户,登录后即可开始使用。