# ![Immich Machine Learning](<https://daemonless.io/images/logos/immich-ml.svg>) Immich Machine Learning

[![Build Status](<https://img.shields.io/github/actions/workflow/status/daemonless/immich-ml/build.yaml?style=flat-square&amp;label=Build&amp;color=green>)](<https://github.com/daemonless/immich-ml/actions>) [![Last Commit](<https://img.shields.io/github/last-commit/daemonless/immich-ml?style=flat-square&amp;label=Last+Commit&amp;color=blue>)](<https://github.com/daemonless/immich-ml/commits>) [![OCI Pulls](<https://img.shields.io/docker/pulls/daemonless/immich-ml?style=flat-square&amp;label=OCI+Pulls&amp;color=blue>)](<https://hub.docker.com/r/daemonless/immich-ml>)

Machine learning service for Immich — handles facial recognition, image classification, and semantic search using ONNX models.

|  |  |
| --- | --- |
| **Port** | `3003` |
| **Registry** | [`ghcr.io/daemonless/immich-ml`](<https://github.com/daemonless/immich-ml/pkgs/container/immich-ml>) |
| **Daemonless** | [daemonless/immich-ml](<https://github.com/daemonless/immich-ml>) |
| **Source** | [immich-app/immich](<https://github.com/immich-app/immich>) |
| **Website** | [immich.app](<https://immich.app/>) |

This image is part of the [Immich Stack](<https://daemonless.io/images/immich>).

### Low-power / CPU-only hosts

On weak or CPU-only machines, model loading can be slow and the worker may time out during startup (repeated healthy/unhealthy cycles). Raise the timeout and pin the numeric libraries to a single thread to avoid thrashing:

```
environment:
  MACHINE_LEARNING_WORKERS: "1"
  MACHINE_LEARNING_WORKER_TIMEOUT: "300"
  MACHINE_LEARNING_MODEL_INTER_OP_THREADS: "1"
  MACHINE_LEARNING_MODEL_INTRA_OP_THREADS: "1"
  MACHINE_LEARNING_REQUEST_THREADS: "1"
  OMP_NUM_THREADS: "1"
  OPENBLAS_NUM_THREADS: "1"
  MKL_NUM_THREADS: "1"
```

### Persistent volumes

Mount both `/config` and `/cache` as **persistent volumes**. The one-time recursive chown is skipped on later starts via a `/config/.chown_done` marker — without a persistent `/config`, the marker is lost and the chown re-runs every start, so `SKIP_CHOWN=true` only takes effect once `/config` persists the marker.

## Prerequisites

Before deploying, ensure your host environment is ready. See the [Quick Start Guide](<https://daemonless.io/guides/quick-start/index.md>) for host setup instructions, including the security model for host vs. container privileges.

## Deployment

**Customize Paths, UID & Ports**

Install and manage **Immich Machine Learning** on FreeBSD with [fjord](<https://fjord.daemonless.io>):

```
fjord install immich-ml
```

Or open the **App Store** in the fjord web UI and install **Immich Machine Learning** from the wizard. New to fjord? See the [Install Guide](<https://fjord.daemonless.io/install/>).

```
services:
  immich-ml:
    image: "ghcr.io/daemonless/immich-ml:latest"
    container_name: immich-ml
    environment:
      - MACHINE_LEARNING_HOST=0.0.0.0  # Host to bind to (0.0.0.0)
      - MACHINE_LEARNING_PORT=3003  # Port to bind to (3003)
      - MACHINE_LEARNING_CACHE_FOLDER=/cache  # Path to cache folder (/cache)
      - PUID=1000  # User ID for the application process
      - PGID=1000  # Group ID for the application process
      - TZ=UTC  # Timezone for the container
      - MACHINE_LEARNING_WORKERS=1  # Number of ML worker processes. Keep at 1 on weak / CPU-only hosts.
      - MACHINE_LEARNING_WORKER_TIMEOUT=300  # Gunicorn worker timeout in seconds. Raise on slow CPUs so model loading doesn't time out and cycle the worker.
      - SKIP_CHOWN=true  # Skip the one-time recursive chown of /cache and /config once ownership is recorded in /config/.chown_done (default true). Set false to force a chown on every start.
    volumes:
      - "/containers/immich-ml/cache:/cache"
      - "/containers/immich-ml:/config"
    ports:
      - "3003:3003"
    # always (not unless-stopped) so FreeBSD's podman rc.d auto-starts it at boot
    restart: always
```

Save as `compose.yaml`, then run `podman-compose up -d`.

> [!WARNING]
>
> Exposing ports in AppJail means that your service can be reached from remote hosts. If that is not your intention, do not expose the ports and communicate with the service using the jail's IPv4 address or hostname assigned by the virtual network.

```
# .env

DIRECTOR_PROJECT=immich-ml
MACHINE_LEARNING_HOST=0.0.0.0
MACHINE_LEARNING_PORT=3003
MACHINE_LEARNING_CACHE_FOLDER=/cache
PUID=1000
PGID=1000
TZ=UTC
MACHINE_LEARNING_WORKERS=1
MACHINE_LEARNING_WORKER_TIMEOUT=300
SKIP_CHOWN=true
```

```
# appjail-director.yml

options:
  - virtualnet: ':<random> default'
  - nat:
services:
  immich-ml:
    name: immich_ml
    options:
      - container: 'args:--pull'
      - expose: '3003:3003 proto:tcp'
    oci:
      user: root
      environment:
        - MACHINE_LEARNING_HOST: !ENV '${MACHINE_LEARNING_HOST}'
        - MACHINE_LEARNING_PORT: !ENV '${MACHINE_LEARNING_PORT}'
        - MACHINE_LEARNING_CACHE_FOLDER: !ENV '${MACHINE_LEARNING_CACHE_FOLDER}'
        - PUID: !ENV '${PUID}'
        - PGID: !ENV '${PGID}'
        - TZ: !ENV '${TZ}'
        - MACHINE_LEARNING_WORKERS: !ENV '${MACHINE_LEARNING_WORKERS}'
        - MACHINE_LEARNING_WORKER_TIMEOUT: !ENV '${MACHINE_LEARNING_WORKER_TIMEOUT}'
        - SKIP_CHOWN: !ENV '${SKIP_CHOWN}'
    volumes:
      - immich-ml_cache: /cache
      - immich-ml: /config
volumes:
  immich-ml_cache:
    device: '/containers/immich-ml/cache'
  immich-ml:
    device: '/containers/immich-ml'
```

```
# Makejail

ARG tag=latest

OPTION container=boot
OPTION overwrite=force
OPTION from=ghcr.io/daemonless/immich-ml:${tag}
```

Save the files above, then run `appjail-director up`.

> [!WARNING]
>
> **Experimental**
>
> Bastille's OCI support is experimental. It requires `buildah` and shares the host network stack (`inherit`). Mount volumes with `--volume HOST JAIL`; without it, image-declared volumes are stored under `${bastille_volumesdir}/${jail}`.

```
services:
  immich-ml:
    name: immich-ml
    image: "ghcr.io/daemonless/immich-ml:latest"
    network:
      - mode: host
    environment:
      - MACHINE_LEARNING_HOST=0.0.0.0
      - MACHINE_LEARNING_PORT=3003
      - MACHINE_LEARNING_CACHE_FOLDER=/cache
      - PUID=1000
      - PGID=1000
      - TZ=UTC
      - MACHINE_LEARNING_WORKERS=1
      - MACHINE_LEARNING_WORKER_TIMEOUT=300
      - SKIP_CHOWN=true
    volumes:
      - "/containers/immich-ml/cache:/cache"
      - "/containers/immich-ml:/config"
```

Save as `bastille-compose.yml`, then run `bastille up`.

## Parameters

### Environment Variables

| Variable | Default | Description |
| --- | --- | --- |
| `MACHINE_LEARNING_HOST` | `0.0.0.0` | Host to bind to (0.0.0.0) |
| `MACHINE_LEARNING_PORT` | `3003` | Port to bind to (3003) |
| `MACHINE_LEARNING_CACHE_FOLDER` | `/cache` | Path to cache folder (/cache) |
| `PUID` | `1000` | User ID for the application process |
| `PGID` | `1000` | Group ID for the application process |
| `TZ` | `UTC` | Timezone for the container |
| `MACHINE_LEARNING_WORKERS` | `1` | Number of ML worker processes. Keep at 1 on weak / CPU-only hosts. |
| `MACHINE_LEARNING_WORKER_TIMEOUT` | `300` | Gunicorn worker timeout in seconds. Raise on slow CPUs so model loading doesn't time out and cycle the worker. |
| `SKIP_CHOWN` | `true` | Skip the one-time recursive chown of /cache and /config once ownership is recorded in /config/.chown\_done (default true). Set false to force a chown on every start. |

### Volumes

| Path | Description |
| --- | --- |
| `/cache` | Model cache (HuggingFace ONNX models). Use a persistent volume to avoid re-downloading models. |
| `/config` | Gunicorn HOME and the .chown\_done ownership marker. Must be a persistent volume (the chown-skip relies on it). |

### Ports

| Port | Protocol | Description |
| --- | --- | --- |
| `3003` | TCP | ML API |

## Version Tags

| Tag | Description | Best For |
| :--- | :--- | :--- |
| `latest` | **Upstream Binary**. Built from official release. | Most users — recommended. |

> [!NOTE]
>
> **Implementation Details**
>
> - **Architectures:** amd64
> - **User:** `bsd` (UID/GID set via [PUID/PGID](<https://daemonless.io/guides/permissions/index.md>)). Defaults to `1000:1000`.
> - **Base:** Built on `ghcr.io/daemonless/base` (FreeBSD 15.1).

---

Need help? Join our [Discord](<https://discord.gg/Kb9tkhecZT>) community.
