#!/usr/bin/env bash # Finalize an Immich user's stage: # 1. Copy queue.json to /mnt/c so the Windows embed worker can read it # 2. Run the embed worker on Windows (DML) # 3. Copy the resulting cache back to /opt/face-sets/work/cache/ # 4. Run cluster_immich.py to discover + emit new facesets # # Usage: ./work/finalize_immich.sh set -euo pipefail USER_LABEL="${1:?usage: $0 }" REPO="$(cd "$(dirname "$0")/.." && pwd)" WSL_QUEUE="$REPO/work/immich/$USER_LABEL/queue.json" WIN_QUEUE_DIR="/mnt/c/face_embed_venv/work/immich/$USER_LABEL" WIN_QUEUE="$WIN_QUEUE_DIR/queue.json" WIN_QUEUE_FOR_PS="C:\\face_embed_venv\\work\\immich\\$USER_LABEL\\queue.json" WIN_CACHE_DIR="/mnt/c/face_embed_venv/work/cache" WIN_CACHE="$WIN_CACHE_DIR/immich_${USER_LABEL}.npz" WIN_CACHE_FOR_PS="C:\\face_embed_venv\\work\\cache\\immich_${USER_LABEL}.npz" WSL_CACHE="$REPO/work/cache/immich_${USER_LABEL}.npz" LOG="$REPO/work/logs/immich_finalize_${USER_LABEL}.log" [ -f "$WSL_QUEUE" ] || { echo "missing queue: $WSL_QUEUE" >&2; exit 1; } echo "=== finalize: $USER_LABEL ===" | tee -a "$LOG" date | tee -a "$LOG" mkdir -p "$WIN_QUEUE_DIR" "$WIN_CACHE_DIR" "$REPO/work/cache" echo "[1/4] copying queue: $WSL_QUEUE -> $WIN_QUEUE" | tee -a "$LOG" cp "$WSL_QUEUE" "$WIN_QUEUE" echo " $(wc -c < "$WIN_QUEUE") bytes; $(/home/peter/face_sort_env/bin/python3 -c "import json,sys; print(len(json.load(open('$WIN_QUEUE'))))") entries" echo "[2/4] running Windows DML embed worker" | tee -a "$LOG" powershell.exe -NoProfile -Command "C:\\face_embed_venv\\Scripts\\python.exe C:\\face_embed_venv\\bench\\embed_worker.py '$WIN_QUEUE_FOR_PS' '$WIN_CACHE_FOR_PS'" 2>&1 | tee -a "$LOG" [ -f "$WIN_CACHE" ] || { echo "embed produced no cache file at $WIN_CACHE" | tee -a "$LOG"; exit 1; } echo "[3/4] copying cache back: $WIN_CACHE -> $WSL_CACHE" | tee -a "$LOG" cp "$WIN_CACHE" "$WSL_CACHE" echo " $(/home/peter/face_sort_env/bin/python3 -c "import sys,json; sys.path.insert(0,'$REPO'); from sort_faces import load_cache; e,m,_,_,_=load_cache('$WSL_CACHE'); print(f'{len(e)} embeddings, {sum(1 for x in m if x.get(\"noface\"))} noface, {sum(1 for x in m if not x.get(\"noface\"))} faces')")" echo "[4/4] running cluster_immich.py" | tee -a "$LOG" /home/peter/face_sort_env/bin/python3 "$REPO/work/cluster_immich.py" "$WSL_CACHE" 2>&1 | tee -a "$LOG" echo "=== finalize done: $USER_LABEL ===" | tee -a "$LOG" date | tee -a "$LOG"