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
@@ -36,7 +36,7 @@ for val in annotation_files:
|
||||
img_name = a['images'][img_id]['name']
|
||||
img_label_name = img_name[:-3] + "txt"
|
||||
|
||||
obj_class = annot['category_id']
|
||||
cls = annot['category_id'] # instance class id
|
||||
x_center, y_center, width, height = annot['bbox']
|
||||
x_center = (x_center + width / 2) / 1920. # offset and scale
|
||||
y_center = (y_center + height / 2) / 1200. # offset and scale
|
||||
@@ -46,11 +46,10 @@ for val in annotation_files:
|
||||
img_dir = "./labels/" + a['seq_dirs'][a['images'][annot['image_id']]['sid']]
|
||||
|
||||
Path(img_dir).mkdir(parents=True, exist_ok=True)
|
||||
|
||||
if img_dir + "/" + img_label_name not in label_dict:
|
||||
label_dict[img_dir + "/" + img_label_name] = []
|
||||
|
||||
label_dict[img_dir + "/" + img_label_name].append(f"{obj_class} {x_center} {y_center} {width} {height}\n")
|
||||
label_dict[img_dir + "/" + img_label_name].append(f"{cls} {x_center} {y_center} {width} {height}\n")
|
||||
|
||||
for filename in label_dict:
|
||||
with open(filename, "w") as file:
|
||||
|
||||
@@ -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