Skip to content

Run FocalNet's published human-ranking model - #17

Merged
TorstenDittmann merged 1 commit into
mainfrom
torsten/focalnet-inference-7b70
Sep 18, 2026
Merged

TorstenDittmann merged 1 commit into
mainfrom
torsten/focalnet-inference-7b70

Conversation

@TorstenDittmann

@TorstenDittmann TorstenDittmann commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Ship FocalNet as a selectable Autogravity backend using the published human-ranking ONNX graph, not an importance-only subset.

What this does

  • Adds MODEL_BACKEND=focalnet (default remains u2net).
  • Loads format-v2 focalnet-human.onnx from the FocalNet 2026-09-14-rc1 release (image, boxes, contentimportance, crop_scores).
  • Generates FocalNet's candidate crops (5 positions × scales 1.0/0.9/0.8/0.7/0.65), applies the 0.05 importance-retention gate, and returns the selected crop center as gravity.
  • Adds a crop rectangle to FocalNet /analyze responses. Optional ?aspect_ratio=16:9 (default 1:1).
  • Skips YuNet on this path; faces stay fused in the map.
  • Downloads the 19 MiB weights with make model-focalnet and copies them into the Docker image. They are not vendored in git.
make model-focalnet
MODEL_BACKEND=focalnet ./autogravity
# or
docker run --rm -p 8080:8080 -e MODEL_BACKEND=focalnet autogravity

Tests

  • Candidate generation, letterbox content, and score_crop match FocalNet Python goldens.
  • Retention-gated ranking prefers a high human score among crops that keep enough importance.
  • HTTP handler feeds the 3-input graph, returns source=focalnet plus crop, and does not call YuNet.
  • Integration: format-v2 dummy ONNX returns a near-center crop on rose.png.
  • Local smoke against the published focalnet-human.onnx: 1:1 and 16:9 crops on rose.png.

Unit/vet/fmt passed. Dummy integration and the published human model both ran against ONNX Runtime 1.23.2.

Follow-up

Keep YuNet + U²-Net as the production default until FocalNet is validated in Autogravity traffic. Then flip MODEL_BACKEND in the image.

@TorstenDittmann TorstenDittmann self-assigned this Sep 15, 2026
@appwrite

appwrite Bot commented Sep 15, 2026

Copy link
Copy Markdown

Autogravity

Project ID: 6a9e5d640016fa6fb653

Sites (1)
Site Status Logs Preview QR
 Docs
autogravity-docs
Ready Ready View Logs Preview URL QR Code

Tip

HTTPS and SSL certificates are handled automatically for all your Sites

@TorstenDittmann
TorstenDittmann marked this pull request as ready for review September 15, 2026 15:30
@greptile-apps

greptile-apps Bot commented Sep 15, 2026

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

The runtime changes appear sound, but the implementation-coupled FocalNet golden tests violate an explicit repository requirement and must be replaced before merging.

Fix All in Claude CodeFindings

  1. P2 Golden Tests Mirror Implementation
Fix with agent prompt
### Issue 1
internal/focalnet/candidates_test.go:43-57
This test snapshots every candidate coordinate and its ordering from the Python implementation instead of validating user-visible crop selection. The normalized letterbox assertions in this file and the exact letterbox assertions in `internal/focalnet/letterbox_test.go` repeat the same problem. These tests can fail after a harmless implementation change while still passing when the model selects the wrong subject. This violates the repository directive to test observable behavior rather than mirror implementation details. Replace these snapshots with image-sensitive crop-selection checks against independently annotated subject regions; this repository requirement must be satisfied before merging.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds a selectable FocalNet backend that loads the published human-ranking ONNX graph, generates and ranks crop candidates, and returns the selected crop and normalized gravity point.

  • Adds FocalNet preprocessing, inference, map restoration, candidate generation, and retention-gated ranking.
  • Extends /analyze with aspect-ratio selection and FocalNet crop metadata.
  • Adds model download, checksum verification, optional CI packaging, and mandatory release packaging.
  • Keeps U²-Net and YuNet as the default production path.

Reviews (5) · Last reviewed commit: "feat: run the published FocalNet human-r..."

Comment thread cmd/autogravity/main_test.go Outdated
@TorstenDittmann TorstenDittmann changed the title Add FocalNet as an optional inference backend Run FocalNet's published human-ranking model Sep 15, 2026
Comment thread .github/workflows/ci.yml
Load format-v2 focalnet-human.onnx and rank candidate crops with the
0.05 importance-retention gate. Default backend stays YuNet + U²-Net.
Docker copies the published 2026-09-14-rc1 weights only when their
checksum matches; the test dummy is never packaged.
@TorstenDittmann
TorstenDittmann force-pushed the torsten/focalnet-inference-7b70 branch from 9701bbc to 78f8ee2 Compare September 17, 2026 13:26
Comment thread internal/focalnet/candidates_test.go
@TorstenDittmann
TorstenDittmann merged commit 035ea6c into main Sep 18, 2026
5 checks passed
@TorstenDittmann
TorstenDittmann deleted the torsten/focalnet-inference-7b70 branch September 18, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant