Datasets:
Download code/robohome/src/tools/asset_curation/scene_pose2.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/tools/asset_curation/scene_pose2.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/tools/asset_curation/scene_pose2.py
-
curl -L -o scene_pose2.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/tools/asset_curation/scene_pose2.py
2.45 kB
| import curation_paths as paths | |
| import json,glob,math,sqlite3,collections as C,os | |
| B=paths.B | |
| W=paths.W | |
| loc=C.defaultdict(list) | |
| for f in glob.glob(B+"/scenes/*.scene_instance.json"): | |
| try: d=json.load(open(f)) | |
| except Exception: continue | |
| for o in d.get("object_instances",[]): | |
| w,x,y,z=o["rotation"]; n=math.sqrt(w*w+x*x+y*y+z*z) or 1; w,x,y,z=w/n,x/n,y/n,z/n | |
| # local up = R^-1 * (0,1,0) = R^T * yhat (third... second row of R) | |
| lx=2*(x*y+w*z); ly=1-2*(x*x+z*z); lz=2*(y*z-w*x) | |
| loc[o["template_name"]].append((lx,ly,lz)) | |
| def snap(v): | |
| i=max(range(3),key=lambda k:abs(v[k])); | |
| if abs(v[i])<0.98: return "oblique" | |
| return ("+" if v[i]>0 else "-")+"XYZ"[i] | |
| db=sqlite3.connect("file:"+paths.L+"/full_matrix_reviewed_compatibility_v5.sqlite3?mode=ro",uri=True) | |
| cat=dict(db.execute("select asset_id,normalized_category from assets")) | |
| pose=json.load(open(W+"/out/hssd_pose_fix_candidates.json")) if False else None | |
| cand=json.load(open(paths.A+"/hssd_pose_fix_candidates.json")) | |
| conf={r["asset_id"]:r for r in cand} | |
| # per asset: dominant local-up axis and consistency | |
| def asset_up(t): | |
| L=loc.get(t); | |
| if not L: return None | |
| c=C.Counter(snap(v) for v in L); top,n=c.most_common(1)[0]; return top,n/len(L),len(L) | |
| tab=C.Counter(); bycat=C.defaultdict(C.Counter); out=[] | |
| for aid,r in conf.items(): | |
| a=asset_up(aid.split("/")[-1]) | |
| if not a: tab["no_instance"]+=1; continue | |
| top,cons,n=a; tab[(top,"consistent>=0.9" if cons>=.9 else "inconsistent")]+=1; bycat[cat.get(aid)][top if cons>=.9 else "inconsistent"]+=1 | |
| out.append(dict(asset_id=aid,scene_up=top,consistency=round(cons,3),n=n,producer_source_up=r["source_up"],producer_current_up=r["current_up"],category=cat.get(aid))) | |
| print("pose-conflict assets: dominant LOCAL up axis implied by real scene placements"); [print(" ",k,v) for k,v in tab.most_common()] | |
| print("by category:"); [print(" ",k,dict(v)) for k,v in sorted(bycat.items(),key=lambda x:-sum(x[1].values()))[:8]] | |
| # control: ordinary (non conflict) hssd assets | |
| ctl=C.Counter() | |
| for aid,c0 in cat.items(): | |
| if not aid.startswith("hssd:objects") or aid in conf: continue | |
| a=asset_up(aid.split("/")[-1]) | |
| if a: ctl[a[0] if a[1]>=.9 else "inconsistent"]+=1 | |
| print("CONTROL non-conflict hssd assets:",dict(ctl.most_common(6))) | |
| print("producer says source_up ->",C.Counter(str(r["source_up"]) for r in cand).most_common(3)) | |
| json.dump(out,open(W+"/out/pose_scene_up.json","w")) | |