import bootstrap,json,math
from data_robust import OUT,read
from inputs import load
result={}
for clip in read(OUT/'specs.json'):
 rows,chosen,*_=load(clip);bad=[]
 for r in rows:
  for i,p in enumerate(r['persons']):
   b=p['bbox'];w,h=r['width'],r['height']
   if not (0<=b[0]<=b[2]<=w and 0<=b[1]<=b[3]<=h):
    bad.append(dict(frame=r['source_frame'],index=i,bbox=b,width=w,height=h,score=p['score']))
 result[clip]=dict(count=len(bad),examples=bad[:5])
(OUT/'download/cache_bounds.json').write_text(json.dumps(result,indent=2));print(json.dumps({k:v for k,v in result.items() if v['count']},indent=2))
