import sys
sys.argv=['r3_yolo.py']
source=open('research/r3_yolo.py').read()
__file__='research/r3_yolo.py'
exec(source[:source.index('fields = json.loads')], globals())
from PIL import ImageDraw
result=[]
for angle in (0,45,90):
 im=Image.open(root/f"results/l4/synthetic-{angle}.png").convert("RGB")
 pred=model.predict(np.array(im), imgsz=512, conf=.05,device="cpu",verbose=False)[0]
 boxes=pred.boxes.xyxy.cpu().tolist()
 draw=ImageDraw.Draw(im)
 for box in boxes:draw.rectangle(box,outline="#00b99a",width=3)
 im.save(root/f"results/l4/predicted-{angle}.png")
 result.append(dict(rotation=angle,boxes=boxes,confidences=pred.boxes.conf.cpu().tolist()))
print(json.dumps(result,indent=2))
(root/"results/l4/predictions.json").write_text(json.dumps(result,indent=2))
