Skip to content

Commit 1d1fe31

Browse files
ppoundclaude
andcommitted
LR-PROF-CAMERA: look tools refuse duplicate raw names and skip a look without usable pixels
probe_look writes one probe per file name, so two raws of the same name would overwrite each other's probe and the fit would pair one raw's probe with the other's conversion: it now refuses such a list before exporting anything. fit_look.py skipped no look: one with no usable pixels (an empty block, or every raw rejected) failed in np.concatenate and no output was written; it is now reported and left as it was, and an empty validation set is reported instead of failing. (CodeRabbit review of storytold#3339.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7937fea commit 1d1fe31

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

‎crates/engine/examples/probe_look.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ fn main() -> Result<(), String> {
4545
let o =
4646
ExportOptions::from_params(&json!({"format": "tiff", "bitDepth": 32, "colorSpace": "adobeRgb", "longEdge": edge, "tiffCompression": "none"}))
4747
.map_err(|e| e.to_string())?;
48+
// one probe per file name: two raws of the same name (another folder, a camera's numbering wrapping round) would
49+
// overwrite each other's probe, and the fit would pair one raw's probe with the other's conversion
50+
let stem_of = |raf: &str| std::path::Path::new(raf).file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or_default();
51+
let mut seen = std::collections::HashMap::new();
52+
for raf in rafs {
53+
if let Some(first) = seen.insert(stem_of(raf), raf) {
54+
return Err(format!("{first} and {raf} have the same name: rename one, or probe them into different folders"));
55+
}
56+
}
4857
for raf in rafs {
4958
let path = std::fs::canonicalize(raf).map_err(|e| format!("{raf}: {e}"))?.to_string_lossy().to_string();
5059
let mut s = Session::new().with_fs();
@@ -53,7 +62,7 @@ fn main() -> Result<(), String> {
5362
s.execute("library.select", &json!({"ids": [pid], "active": pid})).map_err(|e| e.to_string())?;
5463
s.execute("develop.merge", &json!({"settings": {"profile": {"id": id, "amount": 100}}})).map_err(|e| e.to_string())?;
5564
let e = export_photo(&mut s, PhotoId(pid), &o, 1)?;
56-
let stem = std::path::Path::new(raf).file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or_default();
65+
let stem = stem_of(raf);
5766
let dst = std::path::Path::new(out).join(format!("{stem}.tif"));
5867
std::fs::write(&dst, &e.bytes).map_err(|err| format!("{}: {err}", dst.display()))?;
5968
eprintln!("{stem}: {}x{}", e.width, e.height);

‎tools/fit_look.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ def main():
163163
r = pairs(probe_dir, stem, jdir, edge, lax, abx)
164164
if r is not None:
165165
ins.append(r[0]); tgs.append(r[1])
166+
if sum(len(v) for v in ins) == 0:
167+
print(f"{lid}: no usable pixels in its {len(blocks[lid])} listed raws; its nodes are left as they were", file=sys.stderr, flush=True)
168+
continue
166169
lab, y = np.concatenate(ins), np.concatenate(tgs)
167170
W = weights(lab, lax, abx)
168171
# normalise so the regularisers mean the same whatever the pixel count: per 10k pixels
@@ -179,8 +182,11 @@ def main():
179182
r = pairs(probe_dir, stem, jdir, edge, lax, abx)
180183
if r is not None:
181184
vi.append(r[0]); vt.append(r[1])
182-
Wv, yv = weights(np.concatenate(vi), lax, abx), np.concatenate(vt)
183-
msg += f", val dE {np.mean(np.linalg.norm(lab_of_enc(Wv @ x0) - lab_of_enc(yv), axis=-1)):.2f} -> {np.mean(np.linalg.norm(lab_of_enc(Wv @ x) - lab_of_enc(yv), axis=-1)):.2f}"
185+
if sum(len(v) for v in vi) == 0:
186+
msg += ", no usable validation pixels"
187+
else:
188+
Wv, yv = weights(np.concatenate(vi), lax, abx), np.concatenate(vt)
189+
msg += f", val dE {np.mean(np.linalg.norm(lab_of_enc(Wv @ x0) - lab_of_enc(yv), axis=-1)):.2f} -> {np.mean(np.linalg.norm(lab_of_enc(Wv @ x) - lab_of_enc(yv), axis=-1)):.2f}"
184190
print(msg, flush=True)
185191
look["nodes"] = encode(x, off, step)
186192
json.dump(f, open(out, "w", encoding="utf-8"))

0 commit comments

Comments
 (0)