Objects365 Dataset (#2932)
* add object365 * ADD CONVERSION SCRIPT * fix transcript * Reformat and simplify * spelling * Update get_objects365.py Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
1 parent
33712d6dd0
commit
dbce1bc54c
4 files changed
+120
-3
No files matched your search
@@ -0,0 +1,33 @@
|
||||
# Objects365 https://www.objects365.org labels JSON to YOLO script
|
||||
# 1. Download Object 365 from the Object 365 website And unpack all images in datasets/object365/images
|
||||
# 2. Place this file and zhiyuan_objv2_train.json file in datasets/objects365
|
||||
# 3. Execute this file from datasets/object365 path
|
||||
# /datasets
|
||||
# /objects365
|
||||
# /images
|
||||
# /labels
|
||||
|
||||
from pycocotools.coco import COCO
|
||||
|
||||
coco = COCO("zhiyuan_objv2_train.json")
|
||||
cats = coco.loadCats(coco.getCatIds())
|
||||
nms = [cat["name"] for cat in cats]
|
||||
print("COCO categories: \n{}\n".format(" ".join(nms)))
|
||||
for categoryId, cat in enumerate(nms):
|
||||
catIds = coco.getCatIds(catNms=[cat])
|
||||
imgIds = coco.getImgIds(catIds=catIds)
|
||||
print(cat)
|
||||
# Create a subfolder in this directory called "labels". This is where the annotations will be saved in YOLO format
|
||||
for im in coco.loadImgs(imgIds):
|
||||
width, height = im["width"], im["height"]
|
||||
path = im["file_name"].split("/")[-1] # image filename
|
||||
try:
|
||||
with open("labels/train/" + path.replace(".jpg", ".txt"), "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"{categoryId} {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