提交 04e4446e 编辑于 作者: suilin0432's avatar suilin0432
浏览文件

updat

上级 948697a4
......@@ -32,6 +32,12 @@ from .pascal_voc import register_pascal_voc, register_pascal_voc_wsl, register_p
# ==== Predefined datasets and splits for COCO ==========
_PREDEFINED_SPLITS_COCO = {}
_PREDEFINED_SPLITS_COCO["voc"] = {
"voc_2012_seg_train": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance.json"),
"voc_2012_seg_val": ("VOC2012/JPEGImages", "VOC2012/voc_2012_val_instance.json"),
"voc_2012_seg_train_irn": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance_irn.json"),
"sbd_seg": ("VOC_SBD/images", "VOC2012/sbd_9118_instance.json")
}
_PREDEFINED_SPLITS_COCO["coco"] = {
"coco_2014_train": ("coco/train2014", "coco/annotations/instances_train2014.json"),
"coco_2014_val": ("coco/val2014", "coco/annotations/instances_val2014.json"),
......@@ -52,10 +58,6 @@ _PREDEFINED_SPLITS_COCO["coco"] = {
"coco_2017_gt_random_30_1": ("coco2017/train2017", "coco2017/annotations/random30_1.json"),
"coco_2017_gt_random_30_2": ("coco2017/train2017", "coco2017/annotations/random30_2.json"),
"coco_2017_gt_random_30_3": ("coco2017/train2017", "coco2017/annotations/random30_3.json"),
"voc_2012_seg_train": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance.json"),
"voc_2012_seg_val": ("VOC2012/JPEGImages", "VOC2012/voc_2012_val_instance.json"),
"voc_2012_seg_train_irn": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance_irn.json"),
"sbd_seg": ("VOC_SBD/images", "VOC2012/sbd_9118_instance.json")
}
_PREDEFINED_SPLITS_COCO["coco_person"] = {
......
......@@ -13,7 +13,7 @@ The only goal is to allow users who don't have these dataset to use pre-trained
Users don't have to download a COCO json (which contains metadata), in order to visualize a
COCO model (with correct class names and colors).
"""
import numpy as np
# All coco categories, together with their nice-looking visualization colors
# It's from https://github.com/cocodataset/panopticapi/blob/master/panoptic_coco_categories.json
......@@ -231,6 +231,70 @@ ADE20K_SEM_SEG_CATEGORIES = [
# After processed by `prepare_ade20k_sem_seg.py`, id 255 means ignore
# fmt: on
VOC_C = 21
def uint82bin(n, count=8):
"""returns the binary of integer n, count refers to amount of bits""" ""
return "".join([str((n >> y) & 1) for y in range(count - 1, -1, -1)])
def labelcolormap(N):
cmap = np.zeros((N, 3), dtype=np.uint8)
for i in range(N):
r = 0
g = 0
b = 0
id = i
for j in range(7):
str_id = uint82bin(id)
r = r ^ (np.uint8(str_id[-1]) << (7 - j))
g = g ^ (np.uint8(str_id[-2]) << (7 - j))
b = b ^ (np.uint8(str_id[-3]) << (7 - j))
id = id >> 3
cmap[i, 0] = r
cmap[i, 1] = g
cmap[i, 2] = b
return cmap
voc_cmaps = labelcolormap(VOC_C).tolist()
VOC_CATEGORIES = [
{"id": 1, "name": "aeroplane", "isthing": 1, "color": voc_cmaps[1]},
{"id": 2, "name": "bicycle", "isthing": 1, "color": voc_cmaps[2]},
{"id": 3, "name": "bird", "isthing": 1, "color": voc_cmaps[3]},
{"id": 4, "name": "boat", "isthing": 1, "color": voc_cmaps[4]},
{"id": 5, "name": "bottle", "isthing": 1, "color": voc_cmaps[5]},
{"id": 6, "name": "bus", "isthing": 1, "color": voc_cmaps[6]},
{"id": 7, "name": "car", "isthing": 1, "color": voc_cmaps[7]},
{"id": 8, "name": "cat", "isthing": 1, "color": voc_cmaps[8]},
{"id": 9, "name": "chair", "isthing": 1, "color": voc_cmaps[9]},
{"id": 10, "name": "cow", "isthing": 1, "color": voc_cmaps[10]},
{"id": 11, "name": "diningtable", "isthing": 1, "color": voc_cmaps[11]},
{"id": 12, "name": "dog", "isthing": 1, "color": voc_cmaps[12]},
{"id": 13, "name": "horse", "isthing": 1, "color": voc_cmaps[13]},
{"id": 14, "name": "motorbike", "isthing": 1, "color": voc_cmaps[14]},
{"id": 15, "name": "person", "isthing": 1, "color": voc_cmaps[15]},
{"id": 16, "name": "pottedplant", "isthing": 1, "color": voc_cmaps[16]},
{"id": 17, "name": "sheep", "isthing": 1, "color": voc_cmaps[17]},
{"id": 18, "name": "sofa", "isthing": 1, "color": voc_cmaps[18]},
{"id": 19, "name": "train", "isthing": 1, "color": voc_cmaps[19]},
{"id": 20, "name": "tvmonitor", "isthing": 1, "color": voc_cmaps[20]},
{"id": 21, "name": "background", "isthing": 0, "color": [255, 255, 255]},
]
def _get_voc_instances_meta():
thing_ids = [k["id"] for k in VOC_CATEGORIES if k["isthing"] == 1]
thing_colors = [k["color"] for k in VOC_CATEGORIES if k["isthing"] == 1]
assert len(thing_ids) == 20, len(thing_ids)
# Mapping from the incontiguous VOC category id to an id in [0, 79]
thing_dataset_id_to_contiguous_id = {k: i for i, k in enumerate(thing_ids)}
thing_classes = [k["name"] for k in VOC_CATEGORIES if k["isthing"] == 1]
ret = {
"thing_dataset_id_to_contiguous_id": thing_dataset_id_to_contiguous_id,
"thing_classes": thing_classes,
"thing_colors": thing_colors,
}
return ret
def _get_coco_instances_meta():
thing_ids = [k["id"] for k in COCO_CATEGORIES if k["isthing"] == 1]
......@@ -281,6 +345,8 @@ def _get_coco_panoptic_separated_meta():
def _get_builtin_metadata(dataset_name):
if dataset_name == "voc":
return _get_voc_instances_meta()
if dataset_name == "coco":
return _get_coco_instances_meta()
if dataset_name == "coco_wsl":
......
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册