Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
ARCHIVIS_REQUIRE_MODELS: "1"
ARCHIVIS_TEST_MODELS: ${{ env.DATA }}/models
ONNXRUNTIME_LIB: ${{ env.DATA }}/lib/${{ matrix.lib }}
run: go test -count=1 -v -run 'Faces|CLIP|Tokenizer' ./internal/ml/
run: go test -count=1 -v -run 'Faces|CLIP|Tokenizer|MUSIQ' ./internal/ml/
# CoreML, with every unit and with the CPU and GPU only, gives what the
# CPU gives (runners have no Neural Engine or GPU to use, but ORT must
# take each setting: a refused one falls back to the CPU with a warning,
Expand Down Expand Up @@ -165,6 +165,27 @@ jobs:
case "$(args)" in *--prune*) echo "::error::--prune not deleted"; exit 1 ;; esac
tools/deploy-test/block.sh prune-on | zsh
check
- name: Turn on the MUSIQ backfill (already on, then on a job set up without it)
shell: zsh -e -o pipefail {0}
run: |
p=~/Library/LaunchAgents/com.archivis.index.plist
args() { plutil -extract ProgramArguments json -o - "$p" | python3 -c 'import json,sys; print(" ".join(json.load(sys.stdin)))'; }
check() {
a=$(args)
[ "$(grep -o -- ' --backfill 2h ' <<<" $a " | wc -l | tr -d ' ')" = 1 ] || { echo "::error::want one --backfill 2h: $a"; exit 1; }
case "$a" in *" index "*"--backfill 2h"*) ;; *) echo "::error::--backfill not after index: $a"; exit 1 ;; esac
[ "$(grep -o -- ' --prune ' <<<" $a " | wc -l | tr -d ' ')" = 1 ] || { echo "::error::--prune lost: $a"; exit 1; }
launchctl print gui/$(id -u)/com.archivis.index >/dev/null || { echo "::error::the index agent is not loaded"; exit 1; }
echo "backfill: ok ($a)"
}
tools/deploy-test/block.sh backfill-on | zsh # the agent from step 7 has it: nothing changes
check
i=$(plutil -extract ProgramArguments json -o - "$p" | python3 -c 'import json,sys; print(json.load(sys.stdin).index("--backfill"))')
/usr/libexec/PlistBuddy -c "Delete :ProgramArguments:$i" "$p" # "--backfill"
/usr/libexec/PlistBuddy -c "Delete :ProgramArguments:$i" "$p" # its "2h": as set up before it
case "$(args)" in *--backfill*|*" 2h "*) echo "::error::--backfill not deleted"; exit 1 ;; esac
tools/deploy-test/block.sh backfill-on | zsh
check
- name: Move to system services
shell: zsh {0}
run: |
Expand Down
75 changes: 71 additions & 4 deletions DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ sudo install -m 755 archivis /usr/local/bin/archivis
### 3. Download the runtime and models

```sh
archivis setup # ~800 MB into ~/.archivis, checksum-verified
archivis setup # ~900 MB into ~/.archivis, checksum-verified
```

**Intel Macs:** Microsoft no longer publishes ONNX Runtime for Intel Macs, so
Expand Down Expand Up @@ -183,6 +183,7 @@ cat > ~/Library/LaunchAgents/com.archivis.index.plist <<EOF
<string>/usr/local/bin/archivis</string>
<string>index</string>
<string>--prune</string>
<string>--backfill</string><string>2h</string>
<string>/Volumes/Archive1</string>
<string>/Volumes/Archive2</string>
</array>
Expand Down Expand Up @@ -236,6 +237,28 @@ started at boot ([Start at boot, with nobody
logged in](#start-at-boot-with-nobody-logged-in)), swap the comment marks on
the first two lines.

`--backfill 2h` then spends up to two hours a night scoring, with MUSIQ,
photos indexed before it was installed (see [Technical score and
MUSIQ](#technical-score-and-musiq)); new photos are scored as they are
indexed. Change `2h` to give it more or less time, or score them all at once
with `archivis quality backfill`. To add it to a job set up without it (run
it as the one above, swapping the first two lines the same way):

<!-- ci: backfill-on (run as written by the deploy job in .github/workflows/ci.yml) -->
```sh
d=~/Library/LaunchAgents; dom=gui/$(id -u); s= # agents
# d=/Library/LaunchDaemons; dom=system; s=sudo # services started at boot
p=$d/com.archivis.index.plist
args=$($s /usr/libexec/PlistBuddy -c "Print :ProgramArguments" "$p")
if [ -n "$args" ] && ! grep -qxE ' *--?backfill' <<<"$args"; then
$s /usr/libexec/PlistBuddy -c "Add :ProgramArguments:4 string 2h" "$p" # after "index"
$s /usr/libexec/PlistBuddy -c "Add :ProgramArguments:4 string --backfill" "$p"
$s launchctl bootout $dom/com.archivis.index
while $s launchctl print $dom/com.archivis.index >/dev/null 2>&1; do sleep 1; done
$s launchctl bootstrap $dom "$p"
fi
```

### Managing the services

```sh
Expand Down Expand Up @@ -402,7 +425,7 @@ sudo install -m 755 archivis /usr/local/bin/archivis
### 4. Download the runtime and models

```sh
archivis setup # ~800 MB into ~/.archivis, checksum-verified
archivis setup # ~900 MB into ~/.archivis, checksum-verified
```

**NVIDIA GPU (optional, untested):** run `archivis setup --cuda` instead, and
Expand Down Expand Up @@ -469,7 +492,7 @@ User=$(id -un)
Environment=ARCHIVIS_DATA=$HOME/.archivis
Nice=10
IOSchedulingClass=idle
ExecStart=/usr/local/bin/archivis index --prune /mnt/archive1 /mnt/archive2
ExecStart=/usr/local/bin/archivis index --prune --backfill 2h /mnt/archive1 /mnt/archive2
EOF

sudo tee /etc/systemd/system/archivis-index.timer >/dev/null <<EOF
Expand Down Expand Up @@ -506,6 +529,16 @@ grep -q 'archivis index --prune' /etc/systemd/system/archivis-index.service ||
sudo systemctl daemon-reload
```

`--backfill 2h` spends up to two hours a night scoring, with MUSIQ, photos
indexed before it was installed (see [Technical score and
MUSIQ](#technical-score-and-musiq)). To add it:

```sh
grep -q -- '--backfill' /etc/systemd/system/archivis-index.service ||
sudo sed -i 's|archivis index |archivis index --backfill 2h |' /etc/systemd/system/archivis-index.service
sudo systemctl daemon-reload
```

### Managing the services

```sh
Expand Down Expand Up @@ -875,6 +908,35 @@ Settings saved before scenes stacked kept the old similarity default, 6:
they now read as 10 until saved again. A similarity set to anything else
is kept.

### Technical score and MUSIQ

The technical score blends archivis's own measurements (focus, exposure,
noise and the rest) with **MUSIQ**, Google Research's image-quality model,
which `archivis setup` downloads (about 110 MB). Together they agree with
people's ratings far better than the measurements alone: Spearman 0.77
against 0.63 on 2,000 photos neither saw in training (see VALIDATION.md). Without MUSIQ installed, the technical score is the
measurements' rating, as before.

New photos are scored as they are indexed. Photos indexed before MUSIQ was
installed need each file read again, about a second of processor time per
photo (more for RAW files), several at once (`--workers`, half the cores
by default): roughly a day for 250,000 photos on an 8-core Mac. The
nightly `--backfill 2h` does two hours' worth each night; the command does
them all:

```sh
archivis quality # how many are scored, how many not
archivis quality backfill # score the rest now (resumable; Ctrl-C to stop)
archivis quality backfill --for 3h # or for at most 3 hours
```

It takes the index lock, so it doesn't run alongside an index: if one is
running, it says so and stops. While it runs, the nightly index can't start
either and waits for the next night, so give a long backfill `--for` to end
before 2:30, or let that night's index be skipped. A photo's file that is missing (an unmounted drive) is skipped
and tried again next time. Each photo's technical and overall scores update
as it is scored; bursts, stacks and album covers follow on the next regroup.

### Bursts and duplicates

**Duplicates** are sets of the same picture: identical images (the same
Expand Down Expand Up @@ -1122,7 +1184,12 @@ Disk Access afterwards (step 4). If you also changed a service's settings,
nobody logged in](#start-at-boot-with-nobody-logged-in).

Catalogue changes are applied automatically when Archivis opens it; nothing
needs re-indexing unless the release notes say so. A release with a new
needs re-indexing unless the release notes say so. When `archivis setup`
adds MUSIQ (the technical score's learned half), photos indexed before it
keep their technical score until MUSIQ scores them: add `--backfill 2h` to
the nightly job ([macOS](#7-index-new-photos-every-night),
[Ubuntu](#7-index-first-run-and-every-night)), or run `archivis quality
backfill` to do them all at once. A release with a new
built-in aesthetic model adds it next to the old one, and it scores your
photos from their stored embeddings. Earlier scores, and models you
trained, are kept.
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ everything runs locally, nothing leaves your machine.
(with face focus for portraits), exposure/clipping, colour cast / white
balance, noise and JPEG compression — each checked against photos with known
applied defects — plus a technical score calibrated on 10,000 photos rated by
people, and an aesthetic score fit to ~30 people's ratings of appeal per
people, with Google Research's MUSIQ image-quality model blended in, and an aesthetic score fit to ~30 people's ratings of appeal per
photo, which learns your own taste from ratings you give on photo pages.
Filter ("sharp, well exposed, neutral colour, no heavy
compression"), see warning badges on thumbnails, and sort
Expand Down Expand Up @@ -57,7 +57,7 @@ indexing, access from other devices, backups) follow **[DEPLOY.md](DEPLOY.md)**.
```sh
go build -o archivis ./cmd/archivis
sudo mkdir -p /usr/local/bin && sudo install -m 755 archivis /usr/local/bin/archivis # on your PATH
archivis setup # downloads ONNX Runtime + models (~800 MB) into ~/.archivis
archivis setup # downloads ONNX Runtime + models (~900 MB) into ~/.archivis
```

(Without the install step, run it as `./archivis` from this folder instead.
Expand Down Expand Up @@ -115,6 +115,7 @@ archivis aesthetic models # every aesthetic model used, and the current blend
archivis retag # after editing ~/.archivis/categories.txt
archivis prune /Volumes/Archive1 # forget files deleted from that drive
archivis index --prune /Volumes/Archive1 /Volumes/Archive2 # index, then forget deleted files if both drives are there
archivis quality backfill # MUSIQ-score photos indexed before it was installed (or nightly: index --backfill 2h)
archivis stats ; archivis errors
archivis inspect --previews ~/Desktop/check /Volumes/Card/DCIM # what Archivis reads from your camera's files
```
Expand Down Expand Up @@ -170,7 +171,7 @@ they were fixed. Headlines: 99.65% on the LFW face-verification benchmark;
99.9% precision / 98.9% recall when naming people from a single confirmed
face among 5,400 strangers; a scripted "label every photo of this person" task
completed 10/10 times in 3.0 actions; technical score agrees with human
ratings at Spearman 0.63 on held-out photos; training on 20 of a person's
ratings at Spearman 0.77 on held-out photos with MUSIQ (0.63 without); training on 20 of a person's
own ratings cuts the aesthetic score's error for that person by a fifth. Rerun everything with
`tools/validate/`.

Expand Down
46 changes: 45 additions & 1 deletion VALIDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ timings are pessimistic.
| Face detection | Open Images V5, 500 photos, 929 human-drawn face boxes | recall **87.3%** overall, **92.9%** for unoccluded faces ≥ 32 px (was 85.0% / 90.6%); false detections on face-free photos 9.3% |
| Pets mistaken for people | 1,998 Oxford-IIIT Pets photos | **10.7%** counted as "with people" (was 31.9% with any face) |
| Technical quality vs people | BIQ2021 test split, 2,000 photos × 30 raters | Spearman **0.63** (was 0.43); separates worst from best quarter 92% of the time |
| Technical quality vs people, with MUSIQ | BIQ2021 test split, as above; MUSIQ never saw BIQ2021 | Spearman **0.768** [0.746, 0.788], **+0.141** [+0.123, +0.159] over the technical score without it; worst vs best quarter 96% |
| Aesthetics vs people | EVA, 4,070 photos × ~30 raters (photos unseen by the model) | Spearman **0.78** (LAION predictor it replaced: 0.42); the raters' own panel reliability is 0.90 |
| Learning one person's taste | 25 EVA raters, their own held-out votes, 75 trials per row | error **1.81 → 1.46** points after 20 ratings; rank agreement **0.477 → 0.517** after 400; worse in < 1% of trials |
| Overall score vs people | EVA appeal ratings / BIQ2021 quality ratings | **0.71 / 0.71** (was 0.41 / 0.64) |
Expand Down Expand Up @@ -229,7 +230,10 @@ score, versus **23%** with the textbook Laplacian-variance measure.

| Score | Spearman | Pearson |
|---|---|---|
| **Technical (shipped)** | **0.628** | 0.678 |
| **Technical with MUSIQ (shipped, for photos MUSIQ has scored)** | **0.768** | 0.802 |
| Rating with MUSIQ, before penalties | 0.777 | 0.807 |
| MUSIQ alone (KonIQ checkpoint) | 0.753 | 0.782 |
| **Technical without MUSIQ (shipped)** | **0.628** | 0.678 |
| Human-calibrated rating alone | 0.632 | 0.687 |
| Original hand-weighted formula | 0.427 | 0.476 |
| Focus alone | 0.442 | 0.481 |
Expand All @@ -247,6 +251,46 @@ applied to the exported features on all 1,998 test photos (max difference
0.0001 points). That check fails, by up to 14 points, if the model is fed the
reported grey-edge cast instead of its own colour input (`lab_cast`).

### Technical rating with MUSIQ

Photos MUSIQ has scored (`archivis setup` installs it; older photos with
`archivis quality backfill`) are rated by Google Research's MUSIQ (Ke et
al., ICCV 2021; its KonIQ-10k checkpoint, run in Go through ONNX Runtime at
512 px) together with the measurements above, in the same quadratic ridge,
fit on the BIQ2021 train split only. Measured on the 2,000 test photos
through archivis's own code, with 95% bootstrap intervals:

| Score | Spearman [95% CI] | vs technical without MUSIQ [paired] |
|---|---|---|
| Technical without MUSIQ | 0.627 [0.597, 0.655] | — |
| MUSIQ alone | 0.753 [0.729, 0.775] | |
| Rating with MUSIQ | 0.777 [0.756, 0.796] | |
| **Technical with MUSIQ** | **0.768** [0.746, 0.788] | **+0.141** [+0.123, +0.159] |

The exposure, colour and JPEG penalties were tuned again for the new
rating, by the same rule and tool (`tools/validate/tune_penalties.py`) on
tuning data only: the strongest that cost at most 0.01 on BIQ2021 train.
They came out milder, exposure 0.1, colour 0 and compression 0.1 (0.1 / 0.1
/ 0.2 without MUSIQ, which the same run chooses again for today's rating).
Today's strengths would have cost the new rating 0.028; these cost 0.009.
There is **no colour penalty**: even 0.1 cost 0.014, because people (and
MUSIQ) seldom mark a warm or tinted photo down. Casts stay reported by the
colour score and the thumbnail badge.

On a rebuilt set of 153 photos with applied defects (`tools/musiq/
ladder_photos.txt`; the original set was not recorded), the 73 held out
from tuning show what that trades. Against the technical score without
MUSIQ, the new one falls further below the original photo for over-exposure
(AUC 0.74 vs 0.55 at +2 EV), JPEG (0.81 vs 0.69 at quality 8), blur and
motion blur. It falls less for colour casts (0.47 vs 0.52–0.59 at 35%:
no longer at all), and slightly less for under-exposure, noise and haze
(from the MUSIQ rating itself). The separate focus, exposure, colour and
noise scores are unchanged and still flag each defect.

Details, commands and every number: `tools/musiq/FIT.md`; the earlier
PyTorch benchmark (and why MUSIQ was not adopted for aesthetics):
`tools/musiq/RESULTS.md`.

### What the testing changed

| Finding | Evidence | Fix |
Expand Down
24 changes: 20 additions & 4 deletions cmd/archivis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const usage = `Archivis — face search and quality ranking for large photo arch
Usage: archivis <command> [flags]

Commands:
setup download ONNX Runtime and the models (~800 MB, once)
setup download ONNX Runtime and the models (~900 MB, once)
index catalogue photos under one or more folders (incremental, resumable)
serve run the web interface (search, people, quality browsing)
search search from the terminal: text, --face IMAGE or --like IMAGE
Expand All @@ -45,6 +45,7 @@ Commands:
prune drop catalogue entries for files that no longer exist
stats catalogue summary
groups bursts, stacks, duplicates and folders: status | rebuild
quality MUSIQ scores of photos indexed before it was installed: status | backfill
roots the indexed folders Albums starts from: list | add | remove | name
errors show files that failed to index
inspect show what Archivis reads from photo files (camera, lens, preview, rotation)
Expand Down Expand Up @@ -176,7 +177,7 @@ func parseInterleaved(fs *flag.FlagSet, args []string) []string {
}
}

type need struct{ faces, clip bool }
type need struct{ faces, clip, musiq bool }

// modelOptions are the face and CLIP models' options: opts, with the
// provider --face-provider or --clip-provider names, if any.
Expand Down Expand Up @@ -232,6 +233,17 @@ func (g *globals) engines(n need, workers int) (*indexer.Engines, error) {
}
}
}
if n.musiq {
// optional: without it the technical score is the measurements'
// rating alone, as before MUSIQ was added
if !fileExists(filepath.Join(g.modelsDir(), "musiq", "koniq.onnx")) {
fmt.Fprintln(os.Stderr, "note: MUSIQ is not installed, so technical scores use archivis's measurements alone; run `archivis setup` to add it")
} else if m, err := ml.NewMUSIQ(g.modelsDir(), clipOpts); err != nil {
fmt.Fprintf(os.Stderr, "warning: MUSIQ could not be loaded, so technical scores use archivis's measurements alone: %v\n", err)
} else {
eng.MUSIQ = m // only a loaded model: a nil *ml.MUSIQ would be a non-nil scorer
}
}
return eng, nil
}

Expand All @@ -252,7 +264,7 @@ func main() {
"setup": runSetup, "index": runIndex, "serve": runServe, "search": runSearch,
"list": runList, "export": runExport, "people": runPeople, "retag": runRetag,
"prune": runPrune, "stats": runStats, "errors": runErrors, "aesthetic": runAesthetic, "inspect": runInspect,
"users": runUsers, "version": runVersion, "settings": runSettings, "groups": runGroups,
"users": runUsers, "version": runVersion, "settings": runSettings, "groups": runGroups, "quality": runQuality,
"roots": runRoots,
}
fn, ok := cmds[cmd]
Expand Down Expand Up @@ -354,6 +366,7 @@ func runIndex(g *globals, args []string) error {
noFaces := fs.Bool("no-faces", false, "skip face detection")
noMatch := fs.Bool("no-match", false, "don't auto-label people after indexing")
minBytes := fs.Int64("min-bytes", 4096, "skip files smaller than this many bytes (icons, tiny thumbnails)")
backfill := fs.Duration("backfill", 0, "afterwards, spend up to this long (e.g. 2h) scoring photos indexed before MUSIQ was installed (archivis quality backfill does them all at once)")
prune := fs.Bool("prune", false, "afterwards, remove photos deleted from these folders from the catalogue; only when every folder is there and not empty (an unmounted drive's is not) before and after the run, and the run read and recorded everything; else an error says why and nothing is removed")
g.register(fs)
roots := parseInterleaved(fs, args)
Expand Down Expand Up @@ -393,7 +406,7 @@ func runIndex(g *globals, args []string) error {
}
release := sync.OnceFunc(unlock)
defer release()
eng, err := g.engines(need{faces: !*noFaces, clip: true}, *workers)
eng, err := g.engines(need{faces: !*noFaces, clip: true, musiq: true}, *workers)
if err != nil {
return err
}
Expand Down Expand Up @@ -440,6 +453,9 @@ func runIndex(g *globals, args []string) error {
if ctx.Err() == nil {
classifySources(ctx, cat.Store, eng.Sources, false)
}
if *backfill > 0 && ctx.Err() == nil {
backfillMUSIQ(ctx, cat.Store, eng.MUSIQ, time.Now().Add(*backfill), max(1, *workers/2), os.Stderr)
}
if ctx.Err() == nil {
release() // indexing is done: another index run may start while this regroups
regroupAndMark(ctx, g.data, cat.Store)
Expand Down
Loading
Loading