Commit 9fd3ef38 authored by suilin0432's avatar suilin0432
Browse files

update coco60 related

parent 8a804375
_BASE_: "../Base-RCNN-DilatedC5.yaml"
MODEL:
META_ARCHITECTURE: "GeneralizedRCNN"
WEIGHTS: "/mnt/data3/suilin/wsod/VGG/VGG_ILSVRC_16_layers_v1_d2.pkl"
MASK_ON: False
BACKBONE:
NAME: "build_vgg_backbone"
FREEZE_AT: 2
VGG:
DEPTH: 16
CONV5_DILATION: 2
# PROPOSAL_GENERATOR:
# NAME: "PseudoLabRPN"
ROI_BOX_HEAD:
NUM_FC: 2
POOLER_RESOLUTION: 7
FC_DIM: 4096
RPN:
POSITIVE_FRACTION: 0.25
# LOSS: "CrossEntropy"
IN_FEATURES: ["plain5"]
ROI_HEADS:
NAME: "StandardROIHeads"
IN_FEATURES: ["plain5"]
# LOSS: "CrossEntropy"
NUM_CLASSES: 60
SOLVER:
LR_SCHEDULER_NAME: "WarmupMultiStepLR"
STEPS: (12000, 15000)
MAX_ITER: 18000
# IMG_PER_BATCH_LABEL: 16
# IMG_PER_BATCH_UNLABEL: 16
BASE_LR: 0.01
CHECKPOINT_PERIOD: 2000
DATASETS:
TRAIN: ("coco60_2017_train",)
TEST: ("coco60_2017_val",)
TEST:
EVAL_PERIOD: 1000
\ No newline at end of file
......@@ -152,6 +152,11 @@ VOC_WSIS = {
"voc_2012_seg_train_irn_plus_sbd": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance_irn_plus_sbd.json"),
}
COCO60 = {
"coco60_2017_train": ("coco2017/train2017", "coco2017/annotations/coco60_2017_train.json"),
"coco60_2017_val": ("coco2017/val2017", "coco2017/annotations/coco60_2017_val.json"),
}
# 注册弱监督的打好 pgt 标记的数据集
def register_all_coco_wsl(root):
for key, (image_root, json_file) in COCO_WSL.items():
......@@ -171,6 +176,16 @@ def register_all_voc_wsis(root):
os.path.join(root, image_root)
)
def register_all_coco60(root):
for key, (image_root, json_file) in COCO60.items():
register_coco_instances(
key,
_get_builtin_metadata("coco60"),
os.path.join(root, json_file) if "://" not in json_file else json_file,
os.path.join(root, image_root)
)
def register_all_coco(root):
for dataset_name, splits_per_dataset in _PREDEFINED_SPLITS_COCO.items():
for key, (image_root, json_file) in splits_per_dataset.items():
......@@ -577,3 +592,4 @@ if __name__.endswith(".builtin"):
register_all_pascal_voc_wsl_contain_keep_03(_root)
register_all_pascal_voc_wsl_teach_iter1(_root)
register_all_ade20k(_root)
register_all_coco60(_root)
......@@ -153,6 +153,18 @@ COCO_CATEGORIES = [
{"color": [250, 141, 255], "isthing": 0, "id": 200, "name": "rug-merged"},
]
COCO60_CLASSES = ['truck', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'elephant',
'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard',
'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'wine glass',
'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog',
'pizza', 'donut', 'cake', 'bed', 'toilet', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush']
COCO60_CATEGORIES = []
for i in COCO_CATEGORIES:
if i["name"] in COCO60_CLASSES:
COCO60_CATEGORIES.append(i)
# fmt: off
COCO_PERSON_KEYPOINT_NAMES = (
"nose",
......@@ -310,6 +322,20 @@ def _get_coco_instances_meta():
}
return ret
def _get_coco60_instances_meta():
thing_ids = [k["id"] for k in COCO60_CATEGORIES if k["isthing"] == 1]
thing_colors = [k["color"] for k in COCO60_CATEGORIES if k["isthing"] == 1]
assert len(thing_ids) == 60, len(thing_ids)
# Mapping from the incontiguous COCO 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 COCO60_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_panoptic_separated_meta():
"""
......@@ -349,6 +375,8 @@ def _get_builtin_metadata(dataset_name):
return _get_voc_instances_meta()
if dataset_name == "coco":
return _get_coco_instances_meta()
if dataset_name == "coco60":
return _get_coco60_instances_meta()
if dataset_name == "coco_wsl":
return _get_coco_instances_meta()
if dataset_name == "coco_panoptic_separated":
......
python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_gt.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/wsis/voc_gt \
SOLVER.BASE_LR 0.008
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60/ \
SOLVER.BASE_LR 0.01 SOLVER.IMS_PER_BATCH 16
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60_02/ \
SOLVER.BASE_LR 0.02 SOLVER.IMS_PER_BATCH 16
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60_015/ \
SOLVER.BASE_LR 0.015 SOLVER.IMS_PER_BATCH 16
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60_005/ \
SOLVER.BASE_LR 0.005 SOLVER.IMS_PER_BATCH 16
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60/ \
SOLVER.BASE_LR 0.01 SOLVER.IMS_PER_BATCH 16
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60_02/ \
SOLVER.BASE_LR 0.02 SOLVER.IMS_PER_BATCH 16
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60_015/ \
SOLVER.BASE_LR 0.015 SOLVER.IMS_PER_BATCH 16
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60_005/ \
SOLVER.BASE_LR 0.005 SOLVER.IMS_PER_BATCH 16
import json
from tqdm import tqdm
print("Loading COCO2017 json file...")
coco2017_train_path = "/home/suil/codes/github/unbias_old/unbias/datasets/coco2017/annotations/instances_train2017.json"
coco2017_train = json.load(open(coco2017_train_path))
# voc 中存在的类别对应的 coco 类别的 index (0-79)
# VOC_CLASSES = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car',
# 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike',
# 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
# COCO_CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
# 'train', 'truck', 'boat', 'traffic light', 'fire hydrant',
# 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',
# 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe',
# 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
# 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat',
# 'baseball glove', 'skateboard', 'surfboard', 'tennis racket',
# 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl',
# 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot',
# 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant',
# 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote',
# 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink',
# 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
# 'hair drier', 'toothbrush']
voc_classes = [4, 1, 14, 8, 39, 5, 2, 15, 56, 19, 60, 16, 17, 3, 0, 58, 18, 57, 6, 62]
# 标注信息中 catid 转化为 id
catid2id = {}
for i in range(len(coco2017_train["categories"])):
catid2id[coco2017_train["categories"][i]["id"]] = i
# 获取每个图片的 multi-label 信息
print("Recording multi-label message...")
imgid2class = {}
for ann in tqdm(coco2017_train["annotations"]):
img_id = ann["image_id"]
cat_id = catid2id[ann["category_id"]]
if img_id in imgid2class:
if cat_id not in imgid2class[img_id]:
imgid2class[img_id].append(cat_id)
else:
imgid2class[img_id] = [cat_id]
# 记录所有包含了 voc20 类别的图片
print("Recording images with voc20 category...")
imgidList_voc20 = []
imgidList_coco60 = []
for key in tqdm(imgid2class.keys()):
multi_class = imgid2class[key]
contain = False
for voc_cls in voc_classes:
if voc_cls in multi_class:
imgidList_voc20.append(key)
contain=True
break
if not contain:
imgidList_coco60.append(key)
assert len(imgidList_voc20) + len(imgidList_coco60) == 117266 # 有1021张图片没有物体
# 移除 imgidList_voc20 中的图像以及对应的 annotations
print("Recording new annoations...")
coco60_dataset = {}
coco60_dataset["info"] = coco2017_train["info"]
coco60_dataset["licenses"] = coco2017_train["licenses"]
coco60_dataset["categories"] = []
coco60_dataset["images"] = []
coco60_dataset["annotations"] = []
for cat_info in tqdm(coco2017_train["categories"]):
if catid2id[cat_info["id"]] not in voc_classes:
coco60_dataset["categories"].append(cat_info)
imgid2anns = {}
for img_info in tqdm(coco2017_train["images"]):
img_id = img_info["id"]
imgid2anns[img_id] = []
if img_id in imgidList_coco60:
coco60_dataset["images"].append(img_info)
# 构建 imgid2anns 的序列
for ann in tqdm(coco2017_train["annotations"]):
img_id = ann["image_id"]
imgid2anns[img_id].append(ann)
for img_id in tqdm(imgidList_coco60):
coco60_dataset["annotations"] += imgid2anns[img_id]
json.dump(coco60_dataset, open("/amax/opt/suil/dataset/coco2017/annotations/coco60_2017_train.json", "w"))
### 验证集
coco2017_train_path = "/home/suil/codes/github/unbias_old/unbias/datasets/coco2017/annotations/instances_val2017.json"
coco2017_train = json.load(open(coco2017_train_path))
# voc 中存在的类别对应的 coco 类别的 index (0-79)
# VOC_CLASSES = ['aeroplane', 'bicycle', 'bird', 'boat', 'bottle', 'bus', 'car',
# 'cat', 'chair', 'cow', 'diningtable', 'dog', 'horse', 'motorbike',
# 'person', 'pottedplant', 'sheep', 'sofa', 'train', 'tvmonitor']
# COCO_CLASSES = ['person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
# 'train', 'truck', 'boat', 'traffic light', 'fire hydrant',
# 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',
# 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe',
# 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
# 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat',
# 'baseball glove', 'skateboard', 'surfboard', 'tennis racket',
# 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl',
# 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot',
# 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch', 'potted plant',
# 'bed', 'dining table', 'toilet', 'tv', 'laptop', 'mouse', 'remote',
# 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink',
# 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear',
# 'hair drier', 'toothbrush']
voc_classes = [4, 1, 14, 8, 39, 5, 2, 15, 56, 19, 60, 16, 17, 3, 0, 58, 18, 57, 6, 62]
# 标注信息中 catid 转化为 id
catid2id = {}
for i in range(len(coco2017_train["categories"])):
catid2id[coco2017_train["categories"][i]["id"]] = i
# 获取每个图片的 multi-label 信息
print("Recording multi-label message...")
imgid2class = {}
for ann in tqdm(coco2017_train["annotations"]):
img_id = ann["image_id"]
cat_id = catid2id[ann["category_id"]]
if img_id in imgid2class:
if cat_id not in imgid2class[img_id]:
imgid2class[img_id].append(cat_id)
else:
imgid2class[img_id] = [cat_id]
# 记录所有包含了 voc20 类别的图片
print("Recording images with voc20 category...")
imgidList_voc20 = []
imgidList_coco60 = []
for key in tqdm(imgid2class.keys()):
multi_class = imgid2class[key]
contain = False
for voc_cls in voc_classes:
if voc_cls in multi_class:
imgidList_voc20.append(key)
contain=True
break
if not contain:
imgidList_coco60.append(key)
assert len(imgidList_voc20) + len(imgidList_coco60) == 4952 # 有1021张图片没有物体
# 移除 imgidList_voc20 中的图像以及对应的 annotations
print("Recording new annoations...")
coco60_dataset = {}
coco60_dataset["info"] = coco2017_train["info"]
coco60_dataset["licenses"] = coco2017_train["licenses"]
coco60_dataset["categories"] = []
coco60_dataset["images"] = []
coco60_dataset["annotations"] = []
for cat_info in tqdm(coco2017_train["categories"]):
if catid2id[cat_info["id"]] not in voc_classes:
coco60_dataset["categories"].append(cat_info)
imgid2anns = {}
for img_info in tqdm(coco2017_train["images"]):
img_id = img_info["id"]
imgid2anns[img_id] = []
if img_id in imgidList_coco60:
coco60_dataset["images"].append(img_info)
# 构建 imgid2anns 的序列
for ann in tqdm(coco2017_train["annotations"]):
img_id = ann["image_id"]
imgid2anns[img_id].append(ann)
for img_id in tqdm(imgidList_coco60):
coco60_dataset["annotations"] += imgid2anns[img_id]
json.dump(coco60_dataset, open("/amax/opt/suil/dataset/coco2017/annotations/coco60_2017_val.json", "w"))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment