"""Compare camera framing on retained observations with one reserved GPU provider.""" import argparse,json,subprocess,time,http.client,hashlib from pathlib import Path import numpy as np from PIL import Image from k1link.simulation.ai_polygon.camera_optics import DualFisheye,axes def main(): p=argparse.ArgumentParser();p.add_argument('--run',type=Path,required=True);p.add_argument('--reservation',type=Path,required=True);p.add_argument('--output',type=Path,required=True);a=p.parse_args() receipt=json.loads(a.reservation.read_text());assert receipt['state']=='reserved' root=Path(__file__).parent assert not Path('D:/NDC_MISSIONCORE/runtime/simulation/state/active.json').exists() a.output.mkdir(exist_ok=False,parents=True) identity=None try: profile=json.loads((root/'models.worker-006.json').read_text());model=next(m for m in profile['models'] if m['id']=='segformer-b2-cityscapes19') identity=subprocess.check_output(['docker','run','-d','--name','ndc-city-view-qualification-'+receipt['owner_id'][-8:],'--gpus','all','--cpus','3','--memory','4g','--label','com.nodedc.product=mission-core','--label','com.nodedc.stack=ai-polygon-qualification','--label','com.nodedc.role=qualification','--label','com.nodedc.managed-by=ai-polygon-qualification','-p','127.0.0.1:18191:8010','-e','MISSIONCORE_SEGFORMER_PROFILE=cityscapes','--mount',f'type=bind,source={root/"segformer"},target=/adapter/segformer,readonly','--mount',f'type=bind,source={Path(model["checkpoint"]).parent},target=/assets,readonly',model['image']],text=True).strip() def call(path,data=None): c=http.client.HTTPConnection('127.0.0.1',18191,timeout=15) try: c.request('POST' if data is not None else 'GET',path,body=data);r=c.getresponse();b=r.read();assert r.status==200;return b finally:c.close() end=time.monotonic()+60 while True: try:call('/ready');break except (OSError,AssertionError): if time.monotonic()>end:raise time.sleep(.5) inp=json.loads((a.run/'execution-inputs.json').read_text());optics=DualFisheye(inp['sensors']['mounts']['insta360']) sources=[np.asarray(Image.open(a.run/'camera'/f'00000002.insta360_{side}.jpg')) for side in ('left','right')] obs=np.load(a.run/'camera/00000002.range.npz');cal=json.loads(str(obs['calibration_json'])) results=[] for pitch in (-20,0,10): rgb,_=optics.rectify_forward(sources,axes(0,pitch),[800,600],cal['intrinsics']) for full in (False,True): image=Image.fromarray(rgb) if full: resized=image.resize((600,600),Image.Resampling.BILINEAR);image=Image.new('RGB',(800,600));image.paste(resized,(100,0)) raw=call('/infer',np.asarray(image).tobytes());labels=np.frombuffer(raw[:512**2],np.uint8).reshape(512,512);known=np.frombuffer(raw[2*512**2:],np.uint8).reshape(512,512)>0 key=f'pitch{pitch}-'+('full' if full else 'crop') image.save(a.output/(key+'.jpg'));Image.fromarray(labels).save(a.output/(key+'.labels.png')) results.append(dict(case=key,sidewalk_fraction=float(((labels==1)&known).mean()),road_fraction=float(((labels==0)&known).mean()))) (a.output/'results.json').write_text(json.dumps(results,indent=2));print(json.dumps(results)) finally: released=True if identity:released=subprocess.run(['docker','rm','-f',identity],capture_output=True).returncode==0 (a.output/'cleanup.json').write_text(json.dumps(dict(owner_id=receipt['owner_id'],released=released))) assert released if __name__=='__main__':main()