ov-seg / open_vocab_seg /data /datasets /register_voc_seg.py
liangfeng
add ovseg
583456e
raw
history blame
1.45 kB
# Copyright (c) Facebook, Inc. and its affiliates.
import os
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.data.datasets import load_sem_seg
PASCALVOC20_NAMES = (
"aeroplane",
"bicycle",
"bird",
"boat",
"bottle",
"bus",
"car",
"cat",
"chair",
"cow",
"diningtable",
"dog",
"horse",
"motorbike",
"person",
"pottedplant",
"sheep",
"sofa",
"train",
"tvmonitor",
)
def _get_voc_meta(cat_list):
ret = {
"stuff_classes": cat_list,
}
return ret
def register_pascalvoc(root):
root = os.path.join(root, "VOCdevkit/VOC2012")
meta = _get_voc_meta(PASCALVOC20_NAMES)
for name, image_dirname, sem_seg_dirname in [
("val", "JPEGImages", "annotations_detectron2/val"),
]:
image_dir = os.path.join(root, image_dirname)
gt_dir = os.path.join(root, sem_seg_dirname)
all_name = f"pascalvoc20_sem_seg_{name}"
DatasetCatalog.register(
all_name,
lambda x=image_dir, y=gt_dir: load_sem_seg(
y, x, gt_ext="png", image_ext="jpg"
),
)
MetadataCatalog.get(all_name).set(
image_root=image_dir,
sem_seg_root=gt_dir,
evaluator_type="sem_seg",
ignore_label=255,
**meta,
)
_root = os.getenv("DETECTRON2_DATASETS", "datasets")
register_pascalvoc(_root)