Datasets:
Download code/robohome/src/tools/asset_curation/pub9_vlm.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 6.59 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/tools/asset_curation/pub9_vlm.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/tools/asset_curation/pub9_vlm.py
-
curl -L -o pub9_vlm.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/tools/asset_curation/pub9_vlm.py
6.59 kB
| #!/usr/bin/env python3 | |
| """EXPERIMENT GROUP. Publish VLM-proposed operation-side fronts as ONE replacement of the parent release. | |
| Uses the pipeline's existing visual-review contract (labelled canonical frame, 4 registered renders, status 'inferred'). | |
| reviewer = automated:vlm_choice_v2. NOT human reviewed. Measured blind agreement on 12 sampled assets: 8/12.""" | |
| import curation_paths as paths | |
| import copy,hashlib,json,sqlite3,sys,time,os | |
| from pathlib import Path | |
| sys.path.insert(0,paths.S) | |
| import front_evidence_extension as fee | |
| R=paths.R; A=paths.A; W=paths.W | |
| PARENT_SET=Path(os.environ['PARENT']) | |
| OUT=Path(sys.argv[1]); REVIEWER='automated:vlm_choice_v2'; CONF=.9 | |
| HSSD_MATRIX=[1,0,0,0,0,0,-1,0,0,1,0,0,0,0,0,1] | |
| SYMMETRIC={'rug','coffee_table','dining_table','side_table','stool','plant','table_lamp','floor_lamp','lamp','ceiling_light','decorative_object','cushion','bowl','plate','cup','bottle','book','clock','picture','basket','box','vase'} | |
| prop={p['asset_id']:p for p in json.load(open(W+'/out/proposals_v2.json'))} | |
| spec={s['asset_id']:s for s in json.load(open(A+'/render_spec_full.json'))} | |
| grey=set(json.load(open(W+'/out/grey_summary.json'))['keys']) | |
| DEC=json.load(open(W+'/out/front_decisions.json'))['decisions'] | |
| eligible={a:p for a,p in prop.items() if DEC.get(a,{}).get('source')=='vlm' and DEC[a]['axis']==p['axis']} | |
| OUT.mkdir(parents=True,exist_ok=False) | |
| pset=json.load(open(PARENT_SET)); stats=dict(eligible_assets=len(eligible),skipped={}); new=[]; summ=[] | |
| def skip(w): stats['skipped'][w]=stats['skipped'].get(w,0)+1 | |
| for ri,ref in enumerate(pset['releases']): | |
| dpath=Path(ref.get('delivery') or ref['delivery_uri']); delivery=json.load(open(dpath)); recs=delivery['artifacts'].get('records.jsonl') | |
| if not recs: new.append(ref); continue | |
| rpath=Path(recs['uri']); changed={} | |
| for line in rpath.open('rb'): | |
| if not line.strip(): continue | |
| row=json.loads(line); aid=row.get('asset_id') | |
| if aid not in eligible: continue | |
| if row['processing']['pool_status']!='prepared': skip('not_prepared'); continue | |
| ff=row['attributes'].get('functional_front') or {} | |
| if ff.get('status')!='unknown': skip('front_already_%s'%ff.get('status')); continue | |
| tr=row['identity']['canonical_transform']['value'] | |
| if tr.get('matrix_row_major')!=HSSD_MATRIX: skip('non_standard_transform'); continue | |
| try: | |
| for n in ('source','runtime'): fee._verify(row['identity'][n]['value']) | |
| except Exception: skip('source_bytes_changed'); continue | |
| reg=row['evidence_registry'] | |
| if any(k.startswith('vlm_') for k in reg): skip('key_collision'); continue | |
| p=eligible[aid]; key=spec[aid]['key']; d=A+('/../../overnight_20261107/out/renders_grey' if key in grey else '/renders') | |
| views=json.load(open(f'{d}/{key}_views.json'))['view_axis']; vw=[] | |
| for i,ax in enumerate(views): | |
| f=Path(f'{d}/{key}_p{i}.png'); | |
| if not f.exists(): vw=None; break | |
| vw.append(dict(axis=ax,uri=str(f.resolve()),sha256=fee.sha256(f))) | |
| if not vw: skip('render_missing'); continue | |
| axis=p['axis']; rid=row['record_id'] | |
| cert=dict(schema='rhg.functional_front_evidence.v1',record_id=rid,asset_id=aid,source_sha256=row['identity']['source']['value']['sha256'], | |
| runtime_sha256=row['identity']['runtime']['value']['sha256'],canonical_transform=tr['matrix_row_major'],canonical_axis=axis, | |
| scene_yaw_already_applied=False,geometry_changed=False,review_status='inferred',reviewer=REVIEWER, | |
| rationale='Two vision-language models, each asked twice with the four labelled views in different orders, all four answers picked the view showing %s as the side with doors, drawers or handles facing outward.'%axis, | |
| method=dict(name='vlm_multiview_choice_v2',models=['Qwen3.5-9B','gemma-4-31B-it'],votes=p['votes'],zeros=p['zeros'], | |
| measured_blind_agreement='8 of 12 on a hand-checked sample (95% interval 39%-86%); not a calibrated confidence'), | |
| views=vw,previous_functional_front=copy.deepcopy(ff),scope='static_visual_access_face_not_articulation_clearance_or_dynamics') | |
| cp=OUT/('vlm_'+hashlib.sha256(rid.encode()).hexdigest()[:16]+'.front.json'); fee._write(cp,cert) | |
| reg['v29_front_certificate']=dict(fee._ref(cp),kind='source_visual_front_certificate'); keys=['v29_front_certificate'] | |
| for i,v in enumerate(vw): reg['v29_front_image_%d'%i]=dict(uri=v['uri'],sha256=v['sha256'],kind='source_material_render'); keys.append('v29_front_image_%d'%i) | |
| row['attributes']['functional_front']=dict(status='inferred',confidence=CONF, | |
| value=dict(axis=axis,axis_frame=fee.FRAME,certificate='v29_front_certificate',visual=dict(axis=axis,confidence=CONF)),evidence=keys, | |
| provenance=dict(method='vlm_multiview_choice_v2',reviewer=REVIEWER,confidence_basis='pipeline minimum, not a probability', | |
| limitations='Automated visual proposal, not human reviewed; no geometry or physical qualification changed')) | |
| changed[rid]=row | |
| if not changed: new.append(ref); continue | |
| pub=OUT/('release_%02d'%ri); pub.mkdir(); target=pub/'records.jsonl'; n=0 | |
| with rpath.open('rb') as s, target.open('wb') as dst: | |
| for line in s: | |
| row=json.loads(line) if line.strip() else {} | |
| if row.get('record_id') in changed: dst.write((json.dumps(changed[row['record_id']],ensure_ascii=False,allow_nan=False)+'\n').encode()); n+=1 | |
| else: dst.write(line) | |
| assert n==len(changed) | |
| d=copy.deepcopy(delivery); d.update(release=delivery['release']+'_vlm_front_'+OUT.name,consumer_contract='rhg.source_geometry_attributes.v1',status='vlm_front_extension_other_fields_preserved',parent_delivery=fee._ref(dpath)) | |
| d['artifacts']['records.jsonl']=fee._ref(target); fee._write(pub/'delivery.json',d) | |
| new.append(dict(delivery=str((pub/'delivery.json').resolve()),sha256=fee.sha256(pub/'delivery.json'))) | |
| summ.append(dict(release_index=ri,records=len(changed),assets=len({r['asset_id'] for r in changed.values()}),by_axis={a:sum(1 for r in changed.values() if r['attributes']['functional_front']['value']['axis']==a) for a in('-Y','+Y','-X','+X')})) | |
| out=copy.deepcopy(pset); out['releases']=new; fee._write(OUT/'attribute_releases.json',out) | |
| res=dict(status='PUBLISHED-VLM-FRONT-EXPERIMENT',release_set=str((OUT/'attribute_releases.json').resolve()),stats=stats,releases=summ,built=time.strftime('%F %T')) | |
| fee._write(OUT/'publication.json',res); print(json.dumps(res,indent=1)) | |