Commit 48236a72 authored by suilin0432's avatar suilin0432
Browse files

update

parent 9fd3ef38
_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: 1
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_agnostic_2017_train",)
TEST: ("coco60_agnostic_2017_val",)
TEST:
EVAL_PERIOD: 1000
\ No newline at end of file
_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: 1
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: ("voc_2007_train_agnostic", "voc_2007_val_agnostic")
TEST: ("voc_2007_test_agnostic", "voc_2007_train_agnostic", "voc_2007_val_agnostic")
TEST:
EVAL_PERIOD: 1000
\ No newline at end of file
......@@ -687,3 +687,20 @@ _C.MODEL.RESNETS.AVG_DOWN = True
_C.MODEL.RESNETS.RADIX = 2
# Bottleneck_width in ResNeSt
_C.MODEL.RESNETS.BOTTLENECK_WIDTH = 64
# Swin Transformer 的相关配置
_C.MODEL.SWINT = CN()
_C.MODEL.SWINT.EMBED_DIM = 96
_C.MODEL.SWINT.OUT_FEATURES = ["stage2", "stage3", "stage4", "stage5"]
_C.MODEL.SWINT.DEPTHS = [2, 2, 6, 2]
_C.MODEL.SWINT.NUM_HEADS = [3, 6, 12, 24]
_C.MODEL.SWINT.WINDOW_SIZE = 7
_C.MODEL.SWINT.MLP_RATIO = 4
_C.MODEL.SWINT.DROP_PATH_RATE = 0.2
_C.MODEL.SWINT.APE = False
_C.MODEL.FPN.TOP_LEVELS = 2
_C.SOLVER.OPTIMIZER = "SGD"
# Swin Transformer 非自身的相关 config, 最好在 config 文件中添加, 否则会覆盖原本的配置
# _C.MODEL.BACKBONE.FREEZE_AT = -1
\ No newline at end of file
......@@ -27,7 +27,7 @@ from .cityscapes_panoptic import register_all_cityscapes_panoptic
from .coco import load_sem_seg, register_coco_instances, register_coco_instances_wsl
from .coco_panoptic import register_coco_panoptic, register_coco_panoptic_separated
from .lvis import get_lvis_instances_meta, register_lvis_instances
from .pascal_voc import register_pascal_voc, register_pascal_voc_wsl, register_pascal_voc_wsl_top1, register_pascal_voc_wsl_thres, register_pascal_voc_wsl_contain, register_pascal_voc_wsl_contain_total, register_pascal_voc_wsl_mist, register_pascal_voc_wsl_mist_contain, register_pascal_voc_wsl_contain_all, register_pascal_voc_wsl_contain_w2f, register_pascal_voc_wsl_oicr_contain, register_pascal_voc_wsl_oicr_contain_all, register_pascal_voc_wsl_w2f_overlap, register_pascal_voc_wsl_contain_all_adaptive, register_pascal_voc_wsl_contain_adaptive, register_pascal_voc_wsl_contain_keep, register_pascal_voc_wsl_teach_iter
from .pascal_voc import register_pascal_voc, register_pascal_voc_wsl, register_pascal_voc_wsl_top1, register_pascal_voc_wsl_thres, register_pascal_voc_wsl_contain, register_pascal_voc_wsl_contain_total, register_pascal_voc_wsl_mist, register_pascal_voc_wsl_mist_contain, register_pascal_voc_wsl_contain_all, register_pascal_voc_wsl_contain_w2f, register_pascal_voc_wsl_oicr_contain, register_pascal_voc_wsl_oicr_contain_all, register_pascal_voc_wsl_w2f_overlap, register_pascal_voc_wsl_contain_all_adaptive, register_pascal_voc_wsl_contain_adaptive, register_pascal_voc_wsl_contain_keep, register_pascal_voc_wsl_teach_iter, register_pascal_voc_wsl_casd_contain_all, register_pascal_voc_wsl_casd_contain
# ==== Predefined datasets and splits for COCO ==========
......@@ -157,6 +157,17 @@ COCO60 = {
"coco60_2017_val": ("coco2017/val2017", "coco2017/annotations/coco60_2017_val.json"),
}
COCO60_AGNOSTIC = {
"coco60_agnostic_2017_train": ("coco2017/train2017", "coco2017/annotations/coco60_agnostic_2017_train.json"),
"coco60_agnostic_2017_val": ("coco2017/val2017", "coco2017/annotations/coco60_agnostic_2017_val.json"),
}
VOC_AGNOSTIC = {
"voc_2007_train_agnostic": ("VOC2007/JPEGImages", "VOC2007/train_agnostic.json"),
"voc_2007_val_agnostic": ("VOC2007/JPEGImages", "VOC2007/val_agnostic.json"),
"voc_2007_test_agnostic": ("VOC2007/JPEGImages", "VOC2007/test_agnostic.json")
}
# 注册弱监督的打好 pgt 标记的数据集
def register_all_coco_wsl(root):
for key, (image_root, json_file) in COCO_WSL.items():
......@@ -185,6 +196,24 @@ def register_all_coco60(root):
os.path.join(root, image_root)
)
def register_all_coco60_agnostic(root):
for key, (image_root, json_file) in COCO60_AGNOSTIC.items():
register_coco_instances(
key,
_get_builtin_metadata("coco60_agnostic"),
os.path.join(root, json_file) if "://" not in json_file else json_file,
os.path.join(root, image_root)
)
def register_all_voc_agnostic(root):
for key, (image_root, json_file) in VOC_AGNOSTIC.items():
register_coco_instances(
key,
_get_builtin_metadata("coco60_agnostic"),
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():
......@@ -488,6 +517,26 @@ def register_all_pascal_voc_wsl_oicr_contain(root):
year = 2007 if "2007" in name else 2012
register_pascal_voc_wsl_oicr_contain(name, os.path.join(root, dirname), split, year)
MetadataCatalog.get(name).evaluator_type = "pascal_voc"
def register_all_pascal_voc_wsl_casd_contain_all(root):
SPLITS = [
("voc_2007_train_wsl_casd_contain_all", "VOC2007", "train"),
("voc_2007_val_wsl_casd_contain_all", "VOC2007", "val")
]
for name, dirname, split in SPLITS:
year = 2007 if "2007" in name else 2012
register_pascal_voc_wsl_casd_contain_all(name, os.path.join(root, dirname), split, year)
MetadataCatalog.get(name).evaluator_type = "pascal_voc"
def register_all_pascal_voc_wsl_casd_contain(root):
SPLITS = [
("voc_2007_train_wsl_casd_contain", "VOC2007", "train"),
("voc_2007_val_wsl_casd_contain", "VOC2007", "val")
]
for name, dirname, split in SPLITS:
year = 2007 if "2007" in name else 2012
register_pascal_voc_wsl_casd_contain(name, os.path.join(root, dirname), split, year)
MetadataCatalog.get(name).evaluator_type = "pascal_voc"
def register_all_pascal_voc_wsl_contain_all(root):
SPLITS = [
......@@ -593,3 +642,7 @@ if __name__.endswith(".builtin"):
register_all_pascal_voc_wsl_teach_iter1(_root)
register_all_ade20k(_root)
register_all_coco60(_root)
register_all_coco60_agnostic(_root)
register_all_voc_agnostic(_root)
register_all_pascal_voc_wsl_casd_contain_all(_root)
register_all_pascal_voc_wsl_casd_contain(_root)
......@@ -164,6 +164,9 @@ for i in COCO_CATEGORIES:
if i["name"] in COCO60_CLASSES:
COCO60_CATEGORIES.append(i)
COCO60_AGNOSTIC_CATEGORIES = [
{"color": [220, 20, 60], "isthing": 1, "id": 1, "name": "fg"},
]
# fmt: off
COCO_PERSON_KEYPOINT_NAMES = (
......@@ -336,6 +339,20 @@ def _get_coco60_instances_meta():
}
return ret
def _get_coco60_agnostic_instances_meta():
thing_ids = [k["id"] for k in COCO60_AGNOSTIC_CATEGORIES if k["isthing"] == 1]
thing_colors = [k["color"] for k in COCO60_AGNOSTIC_CATEGORIES if k["isthing"] == 1]
assert len(thing_ids) == 1, 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_AGNOSTIC_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():
"""
......@@ -381,6 +398,8 @@ def _get_builtin_metadata(dataset_name):
return _get_coco_instances_meta()
if dataset_name == "coco_panoptic_separated":
return _get_coco_panoptic_separated_meta()
if dataset_name == "coco60_agnostic":
return _get_coco60_agnostic_instances_meta()
elif dataset_name == "coco_panoptic_standard":
meta = {}
# The following metadata maps contiguous id from [0, #thing categories +
......
......@@ -12,7 +12,7 @@ from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.structures import BoxMode
from detectron2.utils.file_io import PathManager
__all__ = ["load_voc_instances", "register_pascal_voc", "register_pascal_voc_wsl", "register_pascal_voc_wsl_top1", "register_pascal_voc_wsl_thres", "register_pascal_voc_wsl_mist", "register_pascal_voc_wsl_mist_contain", "register_pascal_voc_wsl_contain_all", "register_pascal_voc_wsl_contain_w2f", "register_pascal_voc_wsl_oicr_contain", "register_pascal_voc_wsl_oicr_contain_all", "register_pascal_voc_wsl_w2f_overlap", "register_pascal_voc_wsl_contain_all_adaptive", "register_pascal_voc_wsl_contain_adaptive", "register_pascal_voc_wsl_contain_keep", "register_pascal_voc_wsl_teach_iter"]
__all__ = ["load_voc_instances", "register_pascal_voc", "register_pascal_voc_wsl", "register_pascal_voc_wsl_top1", "register_pascal_voc_wsl_thres", "register_pascal_voc_wsl_mist", "register_pascal_voc_wsl_mist_contain", "register_pascal_voc_wsl_contain_all", "register_pascal_voc_wsl_contain_w2f", "register_pascal_voc_wsl_oicr_contain", "register_pascal_voc_wsl_oicr_contain_all", "register_pascal_voc_wsl_w2f_overlap", "register_pascal_voc_wsl_contain_all_adaptive", "register_pascal_voc_wsl_contain_adaptive", "register_pascal_voc_wsl_contain_keep", "register_pascal_voc_wsl_teach_iter", "register_pascal_voc_wsl_casd_contain", "register_pascal_voc_wsl_casd_contain_all"]
# fmt: off
......@@ -1229,6 +1229,160 @@ def load_voc_instances_wsl_oicr_contain(dirname: str, split: str, class_names: U
dicts.append(r)
return dicts
def load_voc_instances_wsl_casd_contain_all(dirname: str, split: str, class_names: Union[List[str], Tuple[str, ...]]):
# 获取 数据集对应划分(train, val, test) 图片 ids
with PathManager.open(os.path.join(dirname, "ImageSets", "Main", split + ".txt")) as f:
fileids = np.loadtxt(f, dtype=np.str)
# 针对 single-input 的文件
# print("load from {}/single_voc07_wsl_{}_contain.json".format(dirname, split))
# annotation_wsl = json.load(open(
# "{}/single_voc07_wsl_{}_contain.json".format(dirname, split), "r"
# ))
# 获取 annotations, wsl 预测之后的结果会保存为 json 的格式
if "07" in dirname:
annotation_wsl = json.load(open(
"{}/voc07_wsl_{}_casd_contain_all.json".format(dirname, split), "r"
))
elif "12" in dirname:
annotation_wsl = json.load(open(
"{}/casd_voc12_wsl_{}_casd_contain_all.json".format(dirname, split), "r"
))
else:
assert False, "Wrong dirname: {}".format(dirname)
multi_class_labels = None
if "multi_label" in annotation_wsl:
multi_class_labels = annotation_wsl.pop("multi_label")
annotation_dirname = PathManager.get_local_path(os.path.join(dirname, "Annotations/"))
dicts = []
for fileid in fileids:
anno = annotation_wsl[str(int(fileid))]
jpeg_file = os.path.join(dirname, "JPEGImages", fileid + ".jpg")
anno_file = os.path.join(annotation_dirname, fileid + ".xml")
if not os.path.isfile(anno_file):
with Image.open(jpeg_file) as img:
width, height = img.size
r = {"file_name": jpeg_file, "image_id": fileid, "height": height, "width": width}
instances = []
for obj in anno:
bbox = obj["bbox"]
bbox = [int(i) for i in bbox] # 因为 predict 出来的 bbox 是float, 要转化为 int list
category_id = obj["category_id"] - 1 # 因为保存统计时将 index + 1 了从而方便 TIDE 统计了, 因此这里需要 - 1
instances.append(
{
"category_id": category_id, "bbox": bbox, "bbox_mode": BoxMode.XYXY_ABS
}
)
r["annotations"] = instances
if multi_class_labels is not None:
r["multi_label"] = multi_class_labels[str(int(fileid))]
dicts.append(r)
continue
with PathManager.open(anno_file) as f:
tree = ET.parse(f)
r = {
"file_name": jpeg_file,
"image_id": fileid,
"height": int(tree.findall("./size/height")[0].text),
"width": int(tree.findall("./size/width")[0].text),
}
instances = []
# 这里是从 annotation_wsl 中进行 gt 信息的提取, 而不是 从 anno file 中提取真正的 gt 信息出来
for obj in anno:
bbox = obj["bbox"]
bbox = [int(i) for i in bbox]
category_id = obj["category_id"] - 1
instances.append(
{
"category_id": category_id, "bbox": bbox, "bbox_mode": BoxMode.XYXY_ABS
}
)
r["annotations"] = instances
if multi_class_labels is not None:
r["multi_label"] = multi_class_labels[str(int(fileid))]
dicts.append(r)
return dicts
def load_voc_instances_wsl_casd_contain(dirname: str, split: str, class_names: Union[List[str], Tuple[str, ...]]):
# 获取 数据集对应划分(train, val, test) 图片 ids
with PathManager.open(os.path.join(dirname, "ImageSets", "Main", split + ".txt")) as f:
fileids = np.loadtxt(f, dtype=np.str)
# 针对 single-input 的文件
# print("load from {}/single_voc07_wsl_{}_contain.json".format(dirname, split))
# annotation_wsl = json.load(open(
# "{}/single_voc07_wsl_{}_contain.json".format(dirname, split), "r"
# ))
# 获取 annotations, wsl 预测之后的结果会保存为 json 的格式
if "07" in dirname:
annotation_wsl = json.load(open(
"{}/voc07_wsl_{}_casd_contain.json".format(dirname, split), "r"
))
elif "12" in dirname:
annotation_wsl = json.load(open(
"{}/casd_voc12_wsl_{}_casd_contain.json".format(dirname, split), "r"
))
else:
assert False, "Wrong dirname: {}".format(dirname)
multi_class_labels = None
if "multi_label" in annotation_wsl:
multi_class_labels = annotation_wsl.pop("multi_label")
annotation_dirname = PathManager.get_local_path(os.path.join(dirname, "Annotations/"))
dicts = []
for fileid in fileids:
anno = annotation_wsl[str(int(fileid))]
jpeg_file = os.path.join(dirname, "JPEGImages", fileid + ".jpg")
anno_file = os.path.join(annotation_dirname, fileid + ".xml")
if not os.path.isfile(anno_file):
with Image.open(jpeg_file) as img:
width, height = img.size
r = {"file_name": jpeg_file, "image_id": fileid, "height": height, "width": width}
instances = []
for obj in anno:
bbox = obj["bbox"]
bbox = [int(i) for i in bbox] # 因为 predict 出来的 bbox 是float, 要转化为 int list
category_id = obj["category_id"] - 1 # 因为保存统计时将 index + 1 了从而方便 TIDE 统计了, 因此这里需要 - 1
instances.append(
{
"category_id": category_id, "bbox": bbox, "bbox_mode": BoxMode.XYXY_ABS
}
)
r["annotations"] = instances
if multi_class_labels is not None:
r["multi_label"] = multi_class_labels[str(int(fileid))]
dicts.append(r)
continue
with PathManager.open(anno_file) as f:
tree = ET.parse(f)
r = {
"file_name": jpeg_file,
"image_id": fileid,
"height": int(tree.findall("./size/height")[0].text),
"width": int(tree.findall("./size/width")[0].text),
}
instances = []
# 这里是从 annotation_wsl 中进行 gt 信息的提取, 而不是 从 anno file 中提取真正的 gt 信息出来
for obj in anno:
bbox = obj["bbox"]
bbox = [int(i) for i in bbox]
category_id = obj["category_id"] - 1
instances.append(
{
"category_id": category_id, "bbox": bbox, "bbox_mode": BoxMode.XYXY_ABS
}
)
r["annotations"] = instances
if multi_class_labels is not None:
r["multi_label"] = multi_class_labels[str(int(fileid))]
dicts.append(r)
return dicts
def load_voc_instances_wsl_thres(dirname: str, split: str, class_names: Union[List[str], Tuple[str, ...]]):
# 获取 数据集对应划分(train, val, test) 图片 ids
with PathManager.open(os.path.join(dirname, "ImageSets", "Main", split + ".txt")) as f:
......@@ -1386,6 +1540,18 @@ def register_pascal_voc_wsl_oicr_contain(name, dirname, split, year, class_names
def register_pascal_voc_wsl_oicr_contain_all(name, dirname, split, year, class_names=CLASS_NAMES):
DatasetCatalog.register(name, lambda: load_voc_instances_wsl_oicr_contain_all(dirname, split, class_names))
MetadataCatalog.get(name).set(
thing_classes=list(class_names), dirname=dirname, year=year, split=split
)
def register_pascal_voc_wsl_casd_contain(name, dirname, split, year, class_names=CLASS_NAMES):
DatasetCatalog.register(name, lambda: load_voc_instances_wsl_casd_contain(dirname, split, class_names))
MetadataCatalog.get(name).set(
thing_classes=list(class_names), dirname=dirname, year=year, split=split
)
def register_pascal_voc_wsl_casd_contain_all(name, dirname, split, year, class_names=CLASS_NAMES):
DatasetCatalog.register(name, lambda: load_voc_instances_wsl_casd_contain_all(dirname, split, class_names))
MetadataCatalog.get(name).set(
thing_classes=list(class_names), dirname=dirname, year=year, split=split
)
\ No newline at end of file
......@@ -15,6 +15,7 @@ from .regnet import RegNet, build_regnet_backbone
from .vgg16 import build_vgg_backbone
from .vgg_torch import vgg16_bn, build_vgg16
from .resnest import build_resnest_backbone, build_resnest_fpn_backbone, ResNeSt
from .swin import build_swint_backbone, build_swint_fpn_backbone, build_retinanet_swint_fpn_backbone
__all__ = [k for k in globals().keys() if not k.startswith("_")]
# TODO can expose more resnet blocks after careful consideration
This diff is collapsed.
......@@ -74,6 +74,13 @@ def find_top_rpn_proposals(
# sort is faster than topk: https://github.com/pytorch/pytorch/issues/22812
# topk_scores_i, topk_idx = logits_i.topk(num_proposals_i, dim=1)
# try:
# logits_i, idx = logits_i.sort(descending=True, dim=1)
# except:
# import detectron2.utils.comm as comm
# print(comm.get_local_rank(), logits_i.shape)
# print(comm.get_local_rank(), logits_i)
# exit()
logits_i, idx = logits_i.sort(descending=True, dim=1)
topk_scores_i = logits_i.narrow(1, 0, num_proposals_i)
topk_idx = idx.narrow(1, 0, num_proposals_i)
......
......@@ -135,10 +135,18 @@ def fast_rcnn_inference_single_image(
Same as `fast_rcnn_inference`, but for only one image.
"""
valid_mask = torch.isfinite(boxes).all(dim=1) & torch.isfinite(scores).all(dim=1)
# try:
# if not valid_mask.all():
# boxes = boxes[valid_mask]
# scores = scores[valid_mask]
# except:
# import detectron2.utils.comm as comm
# print(comm.get_local_rank(), valid_mask.shape)
# print(comm.get_local_rank(), valid_mask)
# exit()
if not valid_mask.all():
boxes = boxes[valid_mask]
scores = scores[valid_mask]
scores = scores[:, :-1]
num_bbox_reg_classes = boxes.shape[1] // 4
# Convert to Boxes to use the `clip` function ...
......
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg_agnostic.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60_agnostic/ \
SOLVER.BASE_LR 0.01 SOLVER.IMS_PER_BATCH 16
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg_agnostic.yaml \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_coco60_agnostic_015/ \
SOLVER.BASE_LR 0.015 SOLVER.IMS_PER_BATCH 16
\ No newline at end of file
python tools/train_net.py \
--config-file configs/COCO60-Detection/vgg_voc_agnostic.yaml --eval \
--num-gpus 8 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/fsod/vgg_voc_agnostic/ \
SOLVER.BASE_LR 0.01 SOLVER.IMS_PER_BATCH 8 MODEL.WEIGHTS output/fsod/vgg_coco60_agnostic/model_final.pth
\ No newline at end of file
import json
from tqdm import tqdm
# train
coco60_2017_train_path = "/amax/opt/suil/dataset/coco2017/annotations/coco60_2017_train.json"
coco60_2017_train = json.load(open(coco60_2017_train_path))
for i in tqdm(range(len(coco60_2017_train["annotations"]))):
coco60_2017_train["annotations"][i]["category_id"] = 1
coco60_2017_train["categories"] = [coco60_2017_train["categories"][0]]
coco60_2017_train["categories"][0]["id"] = 1
coco60_2017_train["categories"][0]["name"] = "fg"
json.dump(coco60_2017_train, open("/amax/opt/suil/dataset/coco2017/annotations/coco60_agnostic_2017_train.json", "w"))
# val
coco60_2017_train_path = "/amax/opt/suil/dataset/coco2017/annotations/coco60_2017_val.json"
coco60_2017_train = json.load(open(coco60_2017_train_path))
for i in tqdm(range(len(coco60_2017_train["annotations"]))):
coco60_2017_train["annotations"][i]["category_id"] = 1
coco60_2017_train["categories"] = [coco60_2017_train["categories"][0]]
coco60_2017_train["categories"][0]["id"] = 1
coco60_2017_train["categories"][0]["name"] = "fg"
json.dump(coco60_2017_train, open("/amax/opt/suil/dataset/coco2017/annotations/coco60_agnostic_2017_val.json", "w"))
\ No newline at end of file
import os
import argparse
import torch
def parse_args():
parser = argparse.ArgumentParser("D2 model converter")
parser.add_argument("--source_model", default="", type=str, help="Path or url to the model to convert")
parser.add_argument("--output_model", default="", type=str, help="Path where to save the converted model")
return parser.parse_args()
def main():
args = parse_args()
source_weights = torch.load(args.source_model, map_location="cpu")["model"]
converted_weights = {}
keys = list(source_weights.keys())
prefix = 'backbone.bottom_up.'
for key in keys:
converted_weights[prefix+key] = source_weights[key]
torch.save(converted_weights, args.output_model)
if __name__ == "__main__":
main()
\ No newline at end of file
# copy from https://github.com/Tony607/voc2coco/blob/master/voc2coco.py
# 将 dataset 全部的图片的标注信息转化到一个 coco 文件中
import sys
import os
import json
import xml.etree.ElementTree as ET
import glob
START_BOUNDING_BOX_ID = 1
PRE_DEFINE_CATEGORIES = None
# If necessary, pre-define category and its id
# PRE_DEFINE_CATEGORIES = {"aeroplane": 1, "bicycle": 2, "bird": 3, "boat": 4,
# "bottle":5, "bus": 6, "car": 7, "cat": 8, "chair": 9,
# "cow": 10, "diningtable": 11, "dog": 12, "horse": 13,
# "motorbike": 14, "person": 15, "pottedplant": 16,
# "sheep": 17, "sofa": 18, "train": 19, "tvmonitor": 20}
def get(root, name):
vars = root.findall(name)
return vars
def get_and_check(root, name, length):
vars = root.findall(name)
if len(vars) == 0:
raise ValueError("Can not find %s in %s." % (name, root.tag))
if length > 0 and len(vars) != length:
raise ValueError(
"The size of %s is supposed to be %d, but is %d."
% (name, length, len(vars))
)
if length == 1:
vars = vars[0]
return vars
def get_filename_as_int(filename):
try:
filename = filename.replace("\\", "/")