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

update

上级 48236a72
_BASE_: "../Base-RCNN-FPN.yaml"
MODEL:
WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl"
MASK_ON: True
RESNETS:
DEPTH: 50
ROI_HEADS:
NUM_CLASSES: 20
DATASETS:
TRAIN: ("voc_2012_seg_train_irn_better_plus_sbd",)
TEST: ("voc_2012_seg_val",)
SOLVER:
BASE_LR: 0.008
WEIGHT_DECAY: 0.0001
IMS_PER_BATCH: 8
STEPS: (8000, 11000)
MAX_ITER: 14000
CHECKPOINT_PERIOD: 4000
TEST:
EVAL_PERIOD: 1000
INPUT:
MASK_FORMAT: "bitmask"
_BASE_: "../Base-RCNN-FPN.yaml"
MODEL:
WEIGHTS: "detectron2://ImageNetPretrained/MSRA/R-50.pkl"
MASK_ON: True
RESNETS:
DEPTH: 50
ROI_HEADS:
NUM_CLASSES: 20
DATASETS:
TRAIN: ("voc_2012_seg_train_liid_plus_sbd",)
TEST: ("voc_2012_seg_val",)
SOLVER:
BASE_LR: 0.008
WEIGHT_DECAY: 0.0001
IMS_PER_BATCH: 8
STEPS: (8000, 11000)
MAX_ITER: 14000
CHECKPOINT_PERIOD: 4000
TEST:
EVAL_PERIOD: 1000
INPUT:
MASK_FORMAT: "bitmask"
......@@ -4,8 +4,15 @@ MODEL:
MASK_ON: False
RESNETS:
DEPTH: 50
RPN:
IN_FEATURES: ["res5"]
PRE_NMS_TOPK_TEST: 6000
POST_NMS_TOPK_TEST: 1000
ROI_HEADS:
NUM_CLASSES: 20
BATCH_SIZE_PER_IMAGE: 4096
POSITIVE_FRACTION: 1.0
PROPOSAL_APPEND_GT: False
INPUT:
MIN_SIZE_TRAIN: (480, 512, 544, 576, 608, 640, 672, 704, 736, 768, 800)
MIN_SIZE_TEST: 800
......
......@@ -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, register_pascal_voc_wsl_casd_contain_all, register_pascal_voc_wsl_casd_contain
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, register_pascal_voc_wsl_gt
# ==== Predefined datasets and splits for COCO ==========
......@@ -150,6 +150,8 @@ VOC_WSIS = {
"voc_2012_seg_train_irn": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance_irn.json"),
"sbd_seg": ("VOC_SBD/images", "VOC2012/sbd_9118_instance.json"),
"voc_2012_seg_train_irn_plus_sbd": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance_irn_plus_sbd.json"),
"voc_2012_seg_train_liid_plus_sbd": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance_liid_plus_sbd.json"),
"voc_2012_seg_train_irn_better_plus_sbd": ("VOC2012/JPEGImages", "VOC2012/voc_2012_train_instance_irn_plus_sbd_better.json"),
}
COCO60 = {
......@@ -588,6 +590,18 @@ def register_all_pascal_voc_w2f_overlap(root):
register_pascal_voc_wsl_w2f_overlap(name, os.path.join(root, dirname), split, year)
MetadataCatalog.get(name).evaluator_type = "pascal_voc"
# wsl 形式的 gt, 为了方便加入 multi_label 标签去进行训练
def register_all_pascal_voc_wsl_gt(root):
SPLITS = [
("voc_2007_train_wsl_gt", "VOC2007", "train"),
("voc_2007_val_wsl_gt", "VOC2007", "val")
]
for name, dirname, split in SPLITS:
year = 2007 if "2007" in name else 2012
register_pascal_voc_wsl_gt(name, os.path.join(root, dirname), split, year)
MetadataCatalog.get(name).evaluator_type = "pascal_voc"
def register_all_ade20k(root):
root = os.path.join(root, "ADEChallengeData2016")
for name, dirname in [("train", "training"), ("val", "validation")]:
......@@ -646,3 +660,4 @@ if __name__.endswith(".builtin"):
register_all_voc_agnostic(_root)
register_all_pascal_voc_wsl_casd_contain_all(_root)
register_all_pascal_voc_wsl_casd_contain(_root)
register_all_pascal_voc_wsl_gt(_root)
......@@ -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", "register_pascal_voc_wsl_casd_contain", "register_pascal_voc_wsl_casd_contain_all"]
__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", "register_pascal_voc_wsl_gt"]
# fmt: off
......@@ -1441,6 +1441,69 @@ def load_voc_instances_wsl_thres(dirname: str, split: str, class_names: Union[Li
dicts.append(r)
return dicts
def load_voc_instances_wsl_gt(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)
# 获取 annotations, wsl 预测之后的结果会保存为 json 的格式
annotation_wsl = json.load(open(
"{}/voc_2007_{}_gt.json".format(dirname, split), "r"
))
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
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 register_pascal_voc(name, dirname, split, year, class_names=CLASS_NAMES):
DatasetCatalog.register(name, lambda: load_voc_instances(dirname, split, class_names))
MetadataCatalog.get(name).set(
......@@ -1554,4 +1617,10 @@ def register_pascal_voc_wsl_casd_contain_all(name, dirname, split, year, class_n
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
)
def register_pascal_voc_wsl_gt(name, dirname, split, year, class_names=CLASS_NAMES):
DatasetCatalog.register(name, lambda: load_voc_instances_wsl_gt(dirname, split, class_names))
MetadataCatalog.get(name).set(
thing_classes=list(class_names), dirname=dirname, year=year, split=split
)
......@@ -91,19 +91,19 @@ class PascalVOCDetectionEvaluator(DatasetEvaluator):
else:
all_prediction[key] = all_prediction[key] + p[key]
tide_result = []
for cls_id, class_name in enumerate(self._class_names):
lines = all_prediction[cls_id]
for line in lines:
message = line.split(" ")
tide_result.append(
{
"image_id": int(message[0]),
"category_id": cls_id+1,
"score": float(message[1]),
"bbox": [float(message[2]), float(message[3]), float(message[4]), float(message[5])]
}
)
# tide_result = []
# for cls_id, class_name in enumerate(self._class_names):
# lines = all_prediction[cls_id]
# for line in lines:
# message = line.split(" ")
# tide_result.append(
# {
# "image_id": int(message[0]),
# "category_id": cls_id+1,
# "score": float(message[1]),
# "bbox": [float(message[2]), float(message[3]), float(message[4]), float(message[5])]
# }
# )
# json.dump(tide_result, open("/mnt/data3/suilin/wsod/visual/{}.json".format(self._dataset_name), "w"))
# json.dump(tide_result, open("/home/suil/codes/github/vis/{}_teach_iter1.json".format(self._dataset_name), "w"))
......
......@@ -472,6 +472,7 @@ class Res5ROIHeads(ROIHeads):
box_features = self._shared_roi_transform(
[features[f] for f in self.in_features], proposal_boxes
)
# 这里相当于是一个 mean pool 了
predictions = self.box_predictor(box_features.mean(dim=[2, 3]))
if self.training:
......
#CUDA_VISIBLE_DEVICES=1,3,4,5 python tools/train_net.py \
#--config-file configs/COCO-InstanceSegmentation/voc_irn_better_plus.yaml \
#--num-gpus 4 --dist-url tcp://0.0.0.0:14192 \
#OUTPUT_DIR output/wsis/voc_irn_better_plus_1_4w_008 \
#SOLVER.BASE_LR 0.008
CUDA_VISIBLE_DEVICES=1,3,4,5 python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_irn_better_plus.yaml \
--num-gpus 4 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/wsis/voc_irn_better_plus_1_4w_004 \
SOLVER.BASE_LR 0.004
CUDA_VISIBLE_DEVICES=1,3,4,5 python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_irn_better_plus.yaml \
--num-gpus 4 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/wsis/voc_irn_better_plus_1_4w_01 \
SOLVER.BASE_LR 0.01
CUDA_VISIBLE_DEVICES=1,4 python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_irn_plus.yaml \
--num-gpus 2 --dist-url tcp://0.0.0.0:14192 --resume \
OUTPUT_DIR output/wsis/voc_plus_1_4w_008_gpu2 \
SOLVER.BASE_LR 0.008
CUDA_VISIBLE_DEVICES=1,4 python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_irn_plus.yaml \
--num-gpus 2 --dist-url tcp://0.0.0.0:14192 --resume \
OUTPUT_DIR output/wsis/voc_plus_1_4w_004_gpu2 \
SOLVER.BASE_LR 0.004
CUDA_VISIBLE_DEVICES=1,4 python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_irn_plus.yaml \
--num-gpus 2 --dist-url tcp://0.0.0.0:14192 --resume \
OUTPUT_DIR output/wsis/voc_plus_1_4w_01_gpu2 \
SOLVER.BASE_LR 0.01
CUDA_VISIBLE_DEVICES=1,3,4,5 python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_liid_plus.yaml \
--num-gpus 4 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/wsis/voc_liid_plus_1_4w_008 \
SOLVER.BASE_LR 0.008
CUDA_VISIBLE_DEVICES=1,3,4,5 python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_liid_plus.yaml \
--num-gpus 4 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/wsis/voc_liid_plus_1_4w_004 \
SOLVER.BASE_LR 0.004
CUDA_VISIBLE_DEVICES=1,3,4,5 python tools/train_net.py \
--config-file configs/COCO-InstanceSegmentation/voc_liid_plus.yaml \
--num-gpus 4 --dist-url tcp://0.0.0.0:14192 \
OUTPUT_DIR output/wsis/voc_liid_plus_1_4w_01 \
SOLVER.BASE_LR 0.01
CUDA_VISIBLE_DEVICES=1,4 python tools/train_net.py --config-file configs/COCO-InstanceSegmentation/voc_liid_plus.yaml --num-gpus 2 --dist-url tcp://0.0.0.0:14129 OUTPUT_DIR output/wsis/voc_liid_plus_1_4w_008
CUDA_VISIBLE_DEVICES=1,4 python tools/train_net.py --config-file configs/COCO-InstanceSegmentation/voc_liid_plus.yaml --num-gpus 2 --dist-url tcp://0.0.0.0:14129 OUTPUT_DIR output/wsis/voc_liid_plus_1_4w_004 SOLVER.BASE_LR 0.004
CUDA_VISIBLE_DEVICES=1,4 python tools/train_net.py --config-file configs/COCO-InstanceSegmentation/voc_liid_plus.yaml --num-gpus 2 --dist-url tcp://0.0.0.0:14129 OUTPUT_DIR output/wsis/voc_liid_plus_1_4w_01 SOLVER.BASE_LR 0.01
支持 Markdown
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册