Update Objects365.yaml to include the official validation set (#5194)
* Update Objects365.yaml Download the official Objects365 validation set and convert the labels * Enforce 4-space indent, reformat and cleanup * shorten list comprehension Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
1c9f710b46
commit
fc3606420d
1 file changed
+34
-27
+34
-27
@@ -72,33 +72,40 @@ download: |
|
|||||||
for q in 'train', 'val':
|
for q in 'train', 'val':
|
||||||
(dir / p / q).mkdir(parents=True, exist_ok=True)
|
(dir / p / q).mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# Download
|
# Train, Val Splits
|
||||||
url = "https://dorc.ks3-cn-beijing.ksyun.com/data-set/2020Objects365%E6%95%B0%E6%8D%AE%E9%9B%86/train/"
|
for split, patches in [('train', 50 + 1), ('val', 43 + 1)]:
|
||||||
download([url + 'zhiyuan_objv2_train.tar.gz'], dir=dir, delete=False) # annotations json
|
print(f"Processing {split} in {patches} patches ...")
|
||||||
download([url + f for f in [f'patch{i}.tar.gz' for i in range(51)]], dir=dir / 'images' / 'train',
|
images, labels = dir / 'images' / split, dir / 'labels' / split
|
||||||
curl=True, delete=False, threads=8)
|
|
||||||
|
|
||||||
# Move
|
# Download
|
||||||
train = dir / 'images' / 'train'
|
url = f"https://dorc.ks3-cn-beijing.ksyun.com/data-set/2020Objects365%E6%95%B0%E6%8D%AE%E9%9B%86/{split}/"
|
||||||
for f in tqdm(train.rglob('*.jpg'), desc=f'Moving images'):
|
if split == 'train':
|
||||||
f.rename(train / f.name) # move to /images/train
|
download([f'{url}zhiyuan_objv2_{split}.tar.gz'], dir=dir, delete=False) # annotations json
|
||||||
|
download([f'{url}patch{i}.tar.gz' for i in range(patches)], dir=images, curl=True, delete=False, threads=8)
|
||||||
|
elif split == 'val':
|
||||||
|
download([f'{url}zhiyuan_objv2_{split}.json'], dir=dir, delete=False) # annotations json
|
||||||
|
download([f'{url}images/v1/patch{i}.tar.gz' for i in range(15 + 1)], dir=images, curl=True, delete=False, threads=8)
|
||||||
|
download([f'{url}images/v2/patch{i}.tar.gz' for i in range(16, patches)], dir=images, curl=True, delete=False, threads=8)
|
||||||
|
|
||||||
# Labels
|
# Move
|
||||||
coco = COCO(dir / 'zhiyuan_objv2_train.json')
|
for f in tqdm(images.rglob('*.jpg'), desc=f'Moving {split} images'):
|
||||||
names = [x["name"] for x in coco.loadCats(coco.getCatIds())]
|
f.rename(images / f.name) # move to /images/{split}
|
||||||
for cid, cat in enumerate(names):
|
|
||||||
catIds = coco.getCatIds(catNms=[cat])
|
|
||||||
imgIds = coco.getImgIds(catIds=catIds)
|
|
||||||
for im in tqdm(coco.loadImgs(imgIds), desc=f'Class {cid + 1}/{len(names)} {cat}'):
|
|
||||||
width, height = im["width"], im["height"]
|
|
||||||
path = Path(im["file_name"]) # image filename
|
|
||||||
try:
|
|
||||||
with open(dir / 'labels' / 'train' / path.with_suffix('.txt').name, 'a') as file:
|
|
||||||
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")
|
|
||||||
|
|
||||||
except Exception as e:
|
# Labels
|
||||||
print(e)
|
coco = COCO(dir / f'zhiyuan_objv2_{split}.json')
|
||||||
|
names = [x["name"] for x in coco.loadCats(coco.getCatIds())]
|
||||||
|
for cid, cat in enumerate(names):
|
||||||
|
catIds = coco.getCatIds(catNms=[cat])
|
||||||
|
imgIds = coco.getImgIds(catIds=catIds)
|
||||||
|
for im in tqdm(coco.loadImgs(imgIds), desc=f'Class {cid + 1}/{len(names)} {cat}'):
|
||||||
|
width, height = im["width"], im["height"]
|
||||||
|
path = Path(im["file_name"]) # image filename
|
||||||
|
try:
|
||||||
|
with open(labels / path.with_suffix('.txt').name, 'a') as file:
|
||||||
|
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")
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
Reference in new issue
Block a user