interlock-edge-comparator

Edge comparator from Interlock, an automatic jigsaw puzzle solver. Given two pieces, it scores how likely the second is the first one's right-hand neighbor; rotating both pieces covers the other three directions. The solver turns these scores into a full placement.

This version is trained to hold up when piece outlines aren't pixel-perfect, as they won't be when pieces come from a photo, and to match on the picture as well as the shape.

Input and output

  • Input: seam windows of shape (5, 184, 80), uint8: RGB plus each piece's mask, cropped around the seam and zero-padded to that size (pairs.seam_windows, pairs.pad_to).
  • Output: one logit per window. Higher means more likely neighbors.
  • Calibration: divide logits by T = 0.73 before a softmax over candidates (testing/robust_comparator.scale_logits does this for the solver).

Use

from huggingface_hub import hf_hub_download
from interlock.models.edge_comparator import load_comparator, pick_device, score_matrix

model = load_comparator(hf_hub_download("dm157/interlock-edge-comparator", "edge_comparator.pt"), pick_device())
logits = score_matrix(model, pieces, masks)  # (4, N, N): right, below, left, above

pieces and masks are what interlock.data_collection.cutting.cut returns. The code is in the Interlock repository (testing/ on the greedy branch).

Training

  • Data: 1500 images from Meta's SA-1B, resized and cropped to 400 ร— 400, each cut into a new random puzzle every epoch (30-100 px pieces, 6 tab shapes per puzzle). Manifest hash cb08f6f90cc3.
  • Every piece's outline gets segmentation-style error: it grows or shrinks by up to 3.5% of a piece, unevenly, capped at 5%; 20% of pieces stay exact.
  • 50.0% of wrong examples are decoys with the true neighbor's exact outline but another part of the picture, so only color can reject them.
  • 12.5% of puzzles are cut on an even grid of straight lines and 12.5% with slanted straight lines, so edge length and angle can't decide a match either.
  • 15 epochs, AdamW, one-cycle learning rate up to 0.001, on Apple Silicon (MPS). Best epoch (15) picked on 20 dev puzzles with outline error.

Evaluation

100 held-out puzzles per test set (30 for flat edges), val images 100 onward, about 58 pieces each, never used for training or tuning. "Placed / neighbors / solved" is the share of pieces in the right space, of neighboring pairs that are true neighbors, and of puzzles fully solved, by Interlock's greedy solver (stages 2-4, stock settings). Flat-edged puzzles have no corner or edge shapes to anchor the grid, so their assemblies can come out shifted: read neighbors there.

Test set Top-1, baseline Top-1, robust Placed / neighbors / solved, baseline Placed / neighbors / solved, robust
Clean pieces 98.6% 95.5% 100.0% / 100.0% / 100.0% 99.9% / 99.9% / 99.0%
Pixel noise (ฯƒ = 12) 95.7% 89.8% 100.0% / 100.0% / 100.0% 99.5% / 99.3% / 94.0%
Half the outlines shrunk 1 px 28.9% 91.2% 42.3% / 35.1% / 3.0% 99.0% / 99.1% / 95.0%
Uneven outline error (โ‰ค 5% of a piece) 4.5% 86.3% 30.4% / 19.2% / 0.0% 97.5% / 97.9% / 91.0%
Smoothed outlines 96.9% 93.9% 100.0% / 100.0% / 100.0% 98.8% / 99.3% / 95.0%
Flat edges, even grid 84.2% 86.8% 4.1% / 44.1% / 3.3% 1.3% / 48.3% / 0.0%
Flat edges, diagonal cuts 97.1% 90.3% 2.3% / 50.4% / 0.0% 5.9% / 47.5% / 3.3%
Color removed (diagnostic: should drop) 33.9% 30.5% 85.7% / 86.1% / 77.0% 75.4% / 74.3% / 64.0%

Full tables, including calibration, are in robust_eval.md.

Limitations

  • Trained and tested on synthetic cuts of real images, not on photos of physical pieces.
  • 19 of 10268 true pairs under outline error are ruled out before the comparator runs, because pairs.side_types misreads a tab or blank.
  • The greedy solver locks most pieces early (its threshold 1), so better scores don't always mean better placements.

License

Research and non-commercial use only. These weights were trained on Meta's SA-1B dataset, which is released under the SA-1B Dataset Research License. That license allows research on a non-commercial basis and forbids any commercial or production use, surveillance, biometric processing, and attempts to identify people in the images. Use these weights under the same terms. The release contains no SA-1B images or masks.

Downloads last month
40
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support