Differentiable Euler-density morphology loss / euler_custom_track.py

Mechanism confirmed, baseline not beaten

Raw ⬇ ZIP
 1import numpy as np
 2
 3META = {
 4    "name": "euler_morphology_denoising",
 5    "domain": "vision",
 6    "description": "Synthetic binary-shape image denoising with spatial topology in the clean target."
 7}
 8
 9def get_dataset(seed, n_train, n_test):
10    rng = np.random.RandomState(seed)
11    h = w = 16
12    yy, xx = np.mgrid[:h, :w]
13
14    def make(n):
15        clean = np.zeros((n, 1, h, w), dtype=np.float32)
16        for i in range(n):
17            if rng.rand() < 0.5:
18                cx, cy = rng.uniform(3, 13, 2)
19                r = rng.uniform(2.0, 4.5)
20                clean[i, 0] = (((xx-cx)**2 + (yy-cy)**2) <= r*r)
21            else:
22                x0, y0 = rng.randint(1, 10, 2)
23                bw, bh = rng.randint(3, 7, 2)
24                clean[i, 0, y0:y0+bh, x0:x0+bw] = 1.0
25            if rng.rand() < 0.25:
26                cx, cy = rng.uniform(3, 13, 2)
27                r = rng.uniform(1.2, 2.5)
28                blob = (((xx-cx)**2 + (yy-cy)**2) <= r*r)
29                clean[i, 0] = np.maximum(clean[i, 0], blob)
30        noisy = np.clip(clean + rng.normal(0, 0.28, clean.shape), 0, 1)
31        return noisy.astype(np.float32), clean
32
33    xtr, ytr = make(n_train)
34    xte, yte = make(n_test)
35    return {"xtr": xtr, "ytr": ytr, "xte": xte, "yte": yte,
36            "task": "regression", "metric": "mse", "out_dim": 1}