meteor-p150 / code /scripts /seg_fuse_check.py
changh95's picture
tt-model push meteor-p150 (container)
8eeb550 verified
Raw History Blame Contribute Delete
2.37 kB
#!/usr/bin/env python3
"""SEG_FUSE A/B on the host (CPU only, OPT round 5 R5.2): planar vs inplace seg fusion over a 24-frame stream built
from the round-4 device dumps (real lane logits, noisy / wide-range / NaN / inf frames, a pose jump, a missing pose),
compared bit for bit (fused lane map and accumulator), then alternating timings.
PYTHONPATH=code python code/scripts/seg_fuse_check.py [--dumps DIR]
"""
import time, os, numpy as np, warnings
warnings.simplefilter('ignore')
from tt_meteor.host.temporal import SegFusion, set_seg_fuse
from tt_meteor.host.postprocess import set_host_post
set_host_post('sparse')
import sys
D=(sys.argv[sys.argv.index('--dumps')+1] if '--dumps' in sys.argv else '/home/ubuntu/experiments/tt-models/logs/meteor/opt_r4/dump_final')+'/'
raw=dict(np.load(D+'pandaset_019_f40.npz')); raw2=dict(np.load(D+'meteor_valday_f040.npz'))
rng=np.random.default_rng(1)
seq=[]
for i in range(24):
src = raw if i%2==0 else raw2
L=src['lane_logit'].copy()
if i%5==3: L=L+rng.normal(size=L.shape).astype(np.float32)*(1+i)
if i%7==5: L=(rng.normal(size=L.shape)*30).astype(np.float32)
if i==7: L[0,0,700:705,10]=np.nan; L[0,3,600,100]=np.inf; L[0,2,650,20]=-np.inf; L[0,:,300,300]=np.nan
lane=src['lane'].copy() if i%3 else rng.integers(0,9,src['lane'].shape).astype(np.uint8)
pose=(0.6*i,0.03*i*i,0.004*i*(-1)**i) if i!=10 else (50.0,0,0)
if i==12: pose=None
seq.append((lane,L,pose))
res={}
for mode in ('planar','inplace'):
set_seg_fuse(mode); sf=SegFusion(); out=[]
for lane,L,pose in seq:
o=sf.apply(lane,L,pose); out.append((o.copy(), None if sf.acc is None else sf.acc.copy()))
res[mode]=out
bad=0
for i,(a,b) in enumerate(zip(res['planar'],res['inplace'])):
ok=np.array_equal(a[0],b[0]) and ((a[1] is None and b[1] is None) or (a[1] is not None and b[1] is not None and np.array_equal(a[1].view(np.int32),b[1].view(np.int32))))
bad+= not ok
if not ok: print('frame',i,'DIFFERENT')
print('IDENTICAL' if not bad else f'{bad} DIFFERENT')
for mode in ('planar','inplace','planar','inplace'):
set_seg_fuse(mode); sf=SegFusion(); ts=[]
for i in range(15):
lane,L,_=seq[0]
t=time.perf_counter(); sf.apply(lane,L,(0.5*i,0.02*i,0.003*i)); ts.append(time.perf_counter()-t)
print(mode, 'ms p50 %.2f min %.2f'%(np.median(ts[1:])*1e3, min(ts[1:])*1e3))