From 6d9b99fc4d700ee9d3e52491b852a8067efadb40 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Fri, 15 Oct 2021 23:19:39 -0700 Subject: [PATCH] Clip Objects365 autodownload labels (#5214) Fixes out of bounds labels that seem to affect ~10% of images in dataset. --- data/Objects365.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/data/Objects365.yaml b/data/Objects365.yaml index 5c0a732253e3..97a424fd03a0 100644 --- a/data/Objects365.yaml +++ b/data/Objects365.yaml @@ -63,7 +63,7 @@ download: | from pycocotools.coco import COCO from tqdm import tqdm - from utils.general import download, Path + from utils.general import Path, download, np, xyxy2xywhn # Make Directories dir = Path(yaml['path']) # dataset root dir @@ -105,7 +105,8 @@ download: | annIds = coco.getAnnIds(imgIds=im["id"], catIds=catIds, iscrowd=None) for a in coco.loadAnns(annIds): x, y, w, h = a['bbox'] # bounding box in xywh (xy top-left corner) - x, y = x + w / 2, y + h / 2 # xy to center - file.write(f"{cid} {x / width:.5f} {y / height:.5f} {w / width:.5f} {h / height:.5f}\n") + xyxy = np.array([x, y, x + w, y + h])[None] # pixels(1,4) + x, y, w, h = xyxy2xywhn(xyxy, w=width, h=height, clip=True)[0] # normalized and clipped + file.write(f"{cid} {x:.5f} {y:.5f} {w:.5f} {h:.5f}\n") except Exception as e: print(e)