Datasets:
Download code/robohome/src/tools/asset_curation/scene_pose.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/tools/asset_curation/scene_pose.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/tools/asset_curation/scene_pose.py
-
curl -L -o scene_pose.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/tools/asset_curation/scene_pose.py
1.99 kB
| import curation_paths as paths | |
| import json,glob,math,sqlite3,collections as C,os | |
| B=paths.B | |
| W=paths.W | |
| inst=C.defaultdict(list); nsc=0 | |
| for f in glob.glob(B+"/scenes/*.scene_instance.json"): | |
| try: d=json.load(open(f)) | |
| except Exception: continue | |
| nsc+=1 | |
| 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 | |
| # image of the glTF +Y axis under the placement rotation: R*(0,1,0) | |
| ux=2*(x*y-w*z); uy=1-2*(x*x+z*z); uz=2*(y*z+w*x) | |
| inst[o["template_name"]].append((uy,os.path.basename(f)[:9],o.get("motion_type"))) | |
| print("scenes",nsc,"templates",len(inst),"instances",sum(len(v) for v in inst.values())) | |
| allup=[u for v in inst.values() for u,_,_ in v] | |
| print("all instances: upright (uy>=0.999) %.4f; tilted (uy<0.99) %d of %d"%(sum(1 for u in allup if u>=.999)/len(allup),sum(1 for u in allup if u<.99),len(allup))) | |
| db=sqlite3.connect("file:"+paths.L+"/full_matrix_reviewed_compatibility_v5.sqlite3?mode=ro",uri=True) | |
| cand=json.load(open(paths.A+"/hssd_pose_fix_candidates.json")) | |
| cat=dict(db.execute("select asset_id,normalized_category from assets")) | |
| res=[];c=C.Counter(); bycat=C.defaultdict(C.Counter) | |
| for r in cand: | |
| aid=r["asset_id"]; t=aid.split("/")[-1]; L=inst.get(t,[]) | |
| if not L: c["no_scene_instance"]+=1; res.append(dict(asset_id=aid,verdict="no_scene_evidence",n=0)); bycat[cat.get(aid)]["no_scene_evidence"]+=1; continue | |
| up=[u for u,_,_ in L]; frac=sum(1 for u in up if u>=.999)/len(up); mn=min(up) | |
| v="upright_in_scenes" if frac>=.98 else ("mixed" if frac>=.5 else "tilted_in_scenes") | |
| c[v]+=1; bycat[cat.get(aid)][v]+=1; res.append(dict(asset_id=aid,verdict=v,n=len(L),scenes=len({s for _,s,_ in L}),upright_frac=round(frac,3),min_uy=round(mn,3))) | |
| print("pose-conflict records",len(cand),dict(c)) | |
| for k,v in sorted(bycat.items(),key=lambda x:-sum(x[1].values()))[:10]: print(" ",k,dict(v)) | |
| json.dump(res,open(W+"/out/pose_scene_evidence.json","w")) | |