ysharma HF Staff commited on
Commit
12ecf8e
·
verified ·
1 Parent(s): a10d063

final 160-edit comparison: ckpt2000 with and without transparency suffix

Browse files
Files changed (1) hide show
  1. final_eval.py +58 -0
final_eval.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Final comparison: chosen checkpoint (steps2000) on the full 160-edit
3
+ held-out set at 40 steps, run twice: with the transparency suffix (deployed
4
+ usage, matches training captions) and without (apples-to-apples with the
5
+ baselines, which ran bare instructions). Reuses eval_edit.py's pipeline,
6
+ metrics and seeding so numbers are directly comparable to the baseline run.
7
+
8
+ Usage:
9
+ python final_eval.py --lora /ckpts/orbit_alpha_lora.safetensors --out /out/final
10
+ """
11
+ import argparse, json, os, sys
12
+
13
+ import eval_edit as E
14
+
15
+
16
+ def main():
17
+ ap = argparse.ArgumentParser()
18
+ ap.add_argument('--lora', required=True)
19
+ ap.add_argument('--out', required=True)
20
+ args = ap.parse_args()
21
+
22
+ pairs = [json.loads(l) for l in open(E.get_file('pairs_eval.jsonl'))]
23
+ assert len(pairs) == 160, f'expected 160 eval pairs, got {len(pairs)}'
24
+
25
+ pipe = E.load_pipe()
26
+ m = E.make_metrics()
27
+ pipe.load_lora_weights(args.lora)
28
+
29
+ for variant, suffix in (('no_suffix', ''), ('suffix', ' ' + E.ALPHA_SUFFIX)):
30
+ pv = [dict(p, instruction=p['instruction'] + suffix) for p in pairs]
31
+ r = E.run_pairs(pipe, m, pv, 'instruction', os.path.join(args.out, variant))
32
+ E.agg(r, f'FINAL/{variant}')
33
+
34
+ # side-by-side contact sheet: pred-with-suffix vs GT for 12 objects
35
+ try:
36
+ from PIL import Image
37
+ sheet_pairs = pairs[::13][:12]
38
+ tiles = []
39
+ for p in sheet_pairs:
40
+ pred = Image.open(os.path.join(args.out, 'suffix', p['pair_id'] + '.png'))
41
+ gt = Image.open(E.get_file(p['target_file'])).convert('RGBA')
42
+ for im in (pred, gt):
43
+ bg = Image.new('RGB', im.size, (128, 128, 128))
44
+ bg.paste(im, mask=im.split()[3])
45
+ tiles.append(bg.resize((256, 256)))
46
+ sheet = Image.new('RGB', (256 * 4, 256 * 6), (30, 30, 30))
47
+ for i, t in enumerate(tiles):
48
+ sheet.paste(t, ((i % 4) * 256, (i // 4) * 256))
49
+ sheet.save(os.path.join(args.out, 'final_sheet.png'))
50
+ print('sheet written', flush=True)
51
+ except Exception as e:
52
+ print(f'sheet failed (non-fatal): {e}', flush=True)
53
+
54
+ print('DONE', flush=True)
55
+
56
+
57
+ if __name__ == '__main__':
58
+ main()