ysharma HF Staff commited on
Commit
1b55f03
·
verified ·
1 Parent(s): fb75f2f

Fix contact-sheet filename bug; write split + upload core data before contact sheets

Browse files
Files changed (1) hide show
  1. render_full.py +17 -7
render_full.py CHANGED
@@ -11,7 +11,7 @@ Outputs (uploaded to ysharma/gso-orbit-rgba):
11
  renders/{object_id}/az{000..315}_el{low|eye|high}.png
12
  metadata.jsonl one line per view
13
  split.json heldout_40 / rejected_objects / train_objects
14
- contact_sheets/*.png one sheet per sampled category
15
  """
16
  import os
17
  os.environ['PYOPENGL_PLATFORM'] = 'osmesa' # must precede pyrender import
@@ -199,7 +199,6 @@ def list_all_objects():
199
 
200
 
201
  def make_split(jobs, all_flags):
202
- """40 held-out objects stratified by category; rejected objects excluded from both."""
203
  cats = {}
204
  for _, oid, cat in jobs:
205
  cats.setdefault(cat, []).append(oid)
@@ -225,9 +224,10 @@ def contact_sheets(sheets_ids):
225
  cell = 256
226
  for sample_id in sheets_ids:
227
  sheet = Image.new('RGB', (8 * cell, 3 * cell), (128, 128, 128))
228
- for r, (_, el) in enumerate(ELEVS):
229
  for c, az in enumerate(AZS):
230
- im = Image.open(os.path.join(OUT, 'renders', sample_id, f'az{az:03d}_el{el[0]}.png'))
 
231
  im = im.resize((cell, cell), Image.LANCZOS)
232
  sheet.paste(im, (c * cell, r * cell), im)
233
  sheet.save(os.path.join(OUT, 'contact_sheets', f'{sample_id}.jpg'), quality=88)
@@ -240,7 +240,7 @@ def main():
240
  os.makedirs(OUT, exist_ok=True)
241
  all_rows, ok_flags, sheets_pool = [], {}, []
242
  s_per_view = []
243
- n_ok = n_fail = n_rej = 0
244
  with ProcessPoolExecutor(max_workers=WORKERS) as ex:
245
  for k, res in enumerate(ex.map(render_object, jobs)):
246
  if not res['ok']:
@@ -266,7 +266,6 @@ def main():
266
  'n_renders': len(all_rows), 'instructions_version': 'orbit-relative-v1'}
267
  with open(os.path.join(OUT, 'split.json'), 'w') as f:
268
  json.dump(split, f, indent=2)
269
- contact_sheets(sheets_pool[:6])
270
  bad = sum(1 for r in all_rows if r['coverage'] < COV_MIN)
271
  n_rej = sum(1 for r in ok_flags.values() if r)
272
  print(f'\nDONE {n_ok} ok / {n_fail} failed | rejected {n_rej} objects | '
@@ -275,11 +274,22 @@ def main():
275
  print(f'split: {len(heldout)} heldout, {len(train)} train', flush=True)
276
 
277
  api = HfApi(token=os.environ.get('HF_TOKEN'))
278
- print('uploading to Hub (upload_large_folder)...', flush=True)
279
  t_up = time.time()
280
  api.upload_large_folder(repo_id=REPO_ID, repo_type='dataset', folder_path=OUT)
281
  print(f'UPLOAD DONE in {time.time()-t_up:.0f}s', flush=True)
282
 
 
 
 
 
 
 
 
 
 
 
 
283
 
284
  if __name__ == '__main__':
285
  main()
 
11
  renders/{object_id}/az{000..315}_el{low|eye|high}.png
12
  metadata.jsonl one line per view
13
  split.json heldout_40 / rejected_objects / train_objects
14
+ contact_sheets/*.jpg one sheet per sampled category (uploaded after core data)
15
  """
16
  import os
17
  os.environ['PYOPENGL_PLATFORM'] = 'osmesa' # must precede pyrender import
 
199
 
200
 
201
  def make_split(jobs, all_flags):
 
202
  cats = {}
203
  for _, oid, cat in jobs:
204
  cats.setdefault(cat, []).append(oid)
 
224
  cell = 256
225
  for sample_id in sheets_ids:
226
  sheet = Image.new('RGB', (8 * cell, 3 * cell), (128, 128, 128))
227
+ for r, (el_name, _el_deg) in enumerate(ELEVS):
228
  for c, az in enumerate(AZS):
229
+ im = Image.open(os.path.join(OUT, 'renders', sample_id,
230
+ f'az{az:03d}_el{el_name}.png'))
231
  im = im.resize((cell, cell), Image.LANCZOS)
232
  sheet.paste(im, (c * cell, r * cell), im)
233
  sheet.save(os.path.join(OUT, 'contact_sheets', f'{sample_id}.jpg'), quality=88)
 
240
  os.makedirs(OUT, exist_ok=True)
241
  all_rows, ok_flags, sheets_pool = [], {}, []
242
  s_per_view = []
243
+ n_ok = n_fail = 0
244
  with ProcessPoolExecutor(max_workers=WORKERS) as ex:
245
  for k, res in enumerate(ex.map(render_object, jobs)):
246
  if not res['ok']:
 
266
  'n_renders': len(all_rows), 'instructions_version': 'orbit-relative-v1'}
267
  with open(os.path.join(OUT, 'split.json'), 'w') as f:
268
  json.dump(split, f, indent=2)
 
269
  bad = sum(1 for r in all_rows if r['coverage'] < COV_MIN)
270
  n_rej = sum(1 for r in ok_flags.values() if r)
271
  print(f'\nDONE {n_ok} ok / {n_fail} failed | rejected {n_rej} objects | '
 
274
  print(f'split: {len(heldout)} heldout, {len(train)} train', flush=True)
275
 
276
  api = HfApi(token=os.environ.get('HF_TOKEN'))
277
+ print('uploading core data to Hub (upload_large_folder)...', flush=True)
278
  t_up = time.time()
279
  api.upload_large_folder(repo_id=REPO_ID, repo_type='dataset', folder_path=OUT)
280
  print(f'UPLOAD DONE in {time.time()-t_up:.0f}s', flush=True)
281
 
282
+ # contact sheets last, guarded: a bug here must never cost the render sweep
283
+ try:
284
+ contact_sheets(sheets_pool[:6])
285
+ api.upload_folder(repo_id=REPO_ID, repo_type='dataset',
286
+ folder_path=os.path.join(OUT, 'contact_sheets'),
287
+ path_in_repo='contact_sheets')
288
+ print('contact sheets uploaded', flush=True)
289
+ except Exception:
290
+ print('contact sheets failed (non-fatal):', flush=True)
291
+ traceback.print_exc()
292
+
293
 
294
  if __name__ == '__main__':
295
  main()