- Adding new imagesets

- Adding label filtering logic
pull/42/head
Joseph 2020-11-04 09:34:21 +05:30
parent 9ecd3801f0
commit 92312cc043
16 changed files with 157234 additions and 43 deletions

View File

@ -4,16 +4,13 @@ MODEL:
# WEIGHTS: "/home/fk1/workspace/OWOD/output/expr_training_with_unk_with_clustering_Z_DIMENSION_256/model_final.pth"
# WEIGHTS: "/home/fk1/workspace/OWOD/output/t1/model_final.pth"
DATASETS:
TRAIN: ('voc_2007_trainval', 'voc_2012_trainval', 't2_test_unk')
TEST: ('voc_2007_test_unk', )
# TEST: ('t2_all_test_unk', )
# TEST: ('voc_2007_test','t2_test_unk', 't3_test_unk', 't4_test_unk')
TRAIN: ('t1_voc_coco_2007_train', ) # t1_voc_coco_2007_train, t1_voc_coco_2007_ft
TEST: ('voc_coco_2007_test', ) # t1_voc_coco_2007_test, t1_voc_coco_2007_val
SOLVER:
STEPS: (12000, 16000)
MAX_ITER: 18000
MAX_ITER: 100
WARMUP_ITERS: 100
OUTPUT_DIR: "./output/expr_training_with_unk_with_clustering_cdist_10"
OUTPUT_DIR: "./output/t1_train"
OWOD:
PREV_INTRODUCED_CLS: 0
CUR_INTRODUCED_CLS: 20

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,100 @@
2010_000889
007089
004746
2009_004532
2011_000780
009287
2008_006382
2010_001934
2008_004036
2010_004173
2008_000176
002045
2011_001862
2011_000477
2011_002697
006233
2008_008725
2010_001036
007538
2009_002676
2008_002776
000997
005081
2009_001326
2011_000725
2011_000485
2008_006543
2009_003522
2008_008511
009603
2008_008206
006719
2009_002054
2009_001493
2011_002674
002891
007524
2009_002317
2009_003087
2008_001199
2011_001854
001858
2010_005922
2008_006282
002058
004867
003611
003301
2008_001649
2010_003779
2010_002873
2010_003467
2009_001812
009283
009773
2008_004431
002055
2011_000971
2009_003613
2010_005731
2010_001315
2008_004515
2010_005424
2008_006682
2008_000817
000294
2008_006433
2010_000602
2008_008043
2009_001848
2009_004986
2008_004106
2011_001611
006124
2008_007124
2009_002792
2008_006285
007868
2008_001070
2008_008671
2008_000626
2008_000078
009734
007809
2008_000815
2010_000254
2010_003630
006896
2011_003059
004033
002757
007040
009166
001110
2008_003881
2008_000619
2010_002747
2009_003507
009155
000492

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,200 @@
2010_000889
007089
004746
2009_004532
2011_000780
009287
2008_006382
2010_001934
2008_004036
2010_004173
2008_000176
002045
2011_001862
2011_000477
2011_002697
006233
2008_008725
2010_001036
007538
2009_002676
2008_002776
000997
005081
2009_001326
2011_000725
2011_000485
2008_006543
2009_003522
2008_008511
009603
2008_008206
006719
2009_002054
2009_001493
2011_002674
002891
007524
2009_002317
2009_003087
2008_001199
2011_001854
001858
2010_005922
2008_006282
002058
004867
003611
003301
2008_001649
2010_003779
2010_002873
2010_003467
2009_001812
009283
009773
2008_004431
002055
2011_000971
2009_003613
2010_005731
2010_001315
2008_004515
2010_005424
2008_006682
2008_000817
000294
2008_006433
2010_000602
2008_008043
2009_001848
2009_004986
2008_004106
2011_001611
006124
2008_007124
2009_002792
2008_006285
007868
2008_001070
2008_008671
2008_000626
2008_000078
009734
007809
2008_000815
2010_000254
2010_003630
006896
2011_003059
004033
002757
007040
009166
001110
2008_003881
2008_000619
2010_002747
2009_003507
009155
000492
000000288880
000000518293
000000223777
000000446461
000000507966
000000301432
000000579029
000000092014
000000024319
000000276549
000000489695
000000423919
000000316342
000000044054
000000109894
000000119600
000000024061
000000175142
000000158222
000000129247
000000382386
000000294348
000000429084
000000101772
000000256337
000000040705
000000433182
000000493048
000000362122
000000242739
000000220135
000000542594
000000317102
000000364139
000000467847
000000469658
000000519157
000000336040
000000451228
000000376875
000000332663
000000048641
000000421389
000000321427
000000293057
000000070255
000000366659
000000297009
000000162579
000000265324
000000353321
000000243773
000000093953
000000554750
000000312423
000000389634
000000219859
000000087007
000000052388
000000490857
000000471350
000000343860
000000215626
000000271280
000000033871
000000249288
000000167450
000000358359
000000463467
000000468341
000000162773
000000208381
000000095027
000000495860
000000533069
000000119358
000000048708
000000181296
000000079392
000000400983
000000508055
000000315232
000000067749
000000408672
000000125128
000000416936
000000147915
000000473651
000000280554
000000093331
000000266961
000000476104
000000094701
000000363549
000000295798
000000105757
000000435451
000000547089
000000061606
000000365282

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,300 @@
2010_000889
007089
004746
2009_004532
2011_000780
009287
2008_006382
2010_001934
2008_004036
2010_004173
2008_000176
002045
2011_001862
2011_000477
2011_002697
006233
2008_008725
2010_001036
007538
2009_002676
2008_002776
000997
005081
2009_001326
2011_000725
2011_000485
2008_006543
2009_003522
2008_008511
009603
2008_008206
006719
2009_002054
2009_001493
2011_002674
002891
007524
2009_002317
2009_003087
2008_001199
2011_001854
001858
2010_005922
2008_006282
002058
004867
003611
003301
2008_001649
2010_003779
2010_002873
2010_003467
2009_001812
009283
009773
2008_004431
002055
2011_000971
2009_003613
2010_005731
2010_001315
2008_004515
2010_005424
2008_006682
2008_000817
000294
2008_006433
2010_000602
2008_008043
2009_001848
2009_004986
2008_004106
2011_001611
006124
2008_007124
2009_002792
2008_006285
007868
2008_001070
2008_008671
2008_000626
2008_000078
009734
007809
2008_000815
2010_000254
2010_003630
006896
2011_003059
004033
002757
007040
009166
001110
2008_003881
2008_000619
2010_002747
2009_003507
009155
000492
000000288880
000000518293
000000223777
000000446461
000000507966
000000301432
000000579029
000000092014
000000024319
000000276549
000000489695
000000423919
000000316342
000000044054
000000109894
000000119600
000000024061
000000175142
000000158222
000000129247
000000382386
000000294348
000000429084
000000101772
000000256337
000000040705
000000433182
000000493048
000000362122
000000242739
000000220135
000000542594
000000317102
000000364139
000000467847
000000469658
000000519157
000000336040
000000451228
000000376875
000000332663
000000048641
000000421389
000000321427
000000293057
000000070255
000000366659
000000297009
000000162579
000000265324
000000353321
000000243773
000000093953
000000554750
000000312423
000000389634
000000219859
000000087007
000000052388
000000490857
000000471350
000000343860
000000215626
000000271280
000000033871
000000249288
000000167450
000000358359
000000463467
000000468341
000000162773
000000208381
000000095027
000000495860
000000533069
000000119358
000000048708
000000181296
000000079392
000000400983
000000508055
000000315232
000000067749
000000408672
000000125128
000000416936
000000147915
000000473651
000000280554
000000093331
000000266961
000000476104
000000094701
000000363549
000000295798
000000105757
000000435451
000000547089
000000061606
000000365282
000000394697
000000578055
000000086725
000000202923
000000252894
000000284893
000000330124
000000146710
000000458349
000000525619
000000290370
000000172420
000000405823
000000431383
000000206435
000000213577
000000095959
000000423234
000000293820
000000392632
000000321363
000000036828
000000338903
000000312591
000000138670
000000541691
000000220638
000000013983
000000250292
000000442441
000000555074
000000327590
000000015382
000000198923
000000287310
000000538320
000000344491
000000230884
000000253576
000000554340
000000351654
000000211593
000000093793
000000247976
000000104906
000000464188
000000064611
000000361375
000000012069
000000094885
000000457074
000000353884
000000324052
000000383111
000000076681
000000547284
000000193471
000000469768
000000045685
000000176477
000000496127
000000209794
000000502857
000000369889
000000269693
000000138100
000000447767
000000167494
000000361021
000000513861
000000394794
000000204137
000000167551
000000338061
000000074462
000000453959
000000130245
000000370145
000000559836
000000371322
000000112959
000000215558
000000561950
000000012754
000000237990
000000162882
000000479680
000000052484
000000192780
000000365911
000000581662
000000381208
000000059979
000000397184
000000308849
000000350842
000000489218
000000517084
000000275657
000000246197

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,400 @@
2010_000889
007089
004746
2009_004532
2011_000780
009287
2008_006382
2010_001934
2008_004036
2010_004173
2008_000176
002045
2011_001862
2011_000477
2011_002697
006233
2008_008725
2010_001036
007538
2009_002676
2008_002776
000997
005081
2009_001326
2011_000725
2011_000485
2008_006543
2009_003522
2008_008511
009603
2008_008206
006719
2009_002054
2009_001493
2011_002674
002891
007524
2009_002317
2009_003087
2008_001199
2011_001854
001858
2010_005922
2008_006282
002058
004867
003611
003301
2008_001649
2010_003779
2010_002873
2010_003467
2009_001812
009283
009773
2008_004431
002055
2011_000971
2009_003613
2010_005731
2010_001315
2008_004515
2010_005424
2008_006682
2008_000817
000294
2008_006433
2010_000602
2008_008043
2009_001848
2009_004986
2008_004106
2011_001611
006124
2008_007124
2009_002792
2008_006285
007868
2008_001070
2008_008671
2008_000626
2008_000078
009734
007809
2008_000815
2010_000254
2010_003630
006896
2011_003059
004033
002757
007040
009166
001110
2008_003881
2008_000619
2010_002747
2009_003507
009155
000492
000000288880
000000518293
000000223777
000000446461
000000507966
000000301432
000000579029
000000092014
000000024319
000000276549
000000489695
000000423919
000000316342
000000044054
000000109894
000000119600
000000024061
000000175142
000000158222
000000129247
000000382386
000000294348
000000429084
000000101772
000000256337
000000040705
000000433182
000000493048
000000362122
000000242739
000000220135
000000542594
000000317102
000000364139
000000467847
000000469658
000000519157
000000336040
000000451228
000000376875
000000332663
000000048641
000000421389
000000321427
000000293057
000000070255
000000366659
000000297009
000000162579
000000265324
000000353321
000000243773
000000093953
000000554750
000000312423
000000389634
000000219859
000000087007
000000052388
000000490857
000000471350
000000343860
000000215626
000000271280
000000033871
000000249288
000000167450
000000358359
000000463467
000000468341
000000162773
000000208381
000000095027
000000495860
000000533069
000000119358
000000048708
000000181296
000000079392
000000400983
000000508055
000000315232
000000067749
000000408672
000000125128
000000416936
000000147915
000000473651
000000280554
000000093331
000000266961
000000476104
000000094701
000000363549
000000295798
000000105757
000000435451
000000547089
000000061606
000000365282
000000394697
000000578055
000000086725
000000202923
000000252894
000000284893
000000330124
000000146710
000000458349
000000525619
000000290370
000000172420
000000405823
000000431383
000000206435
000000213577
000000095959
000000423234
000000293820
000000392632
000000321363
000000036828
000000338903
000000312591
000000138670
000000541691
000000220638
000000013983
000000250292
000000442441
000000555074
000000327590
000000015382
000000198923
000000287310
000000538320
000000344491
000000230884
000000253576
000000554340
000000351654
000000211593
000000093793
000000247976
000000104906
000000464188
000000064611
000000361375
000000012069
000000094885
000000457074
000000353884
000000324052
000000383111
000000076681
000000547284
000000193471
000000469768
000000045685
000000176477
000000496127
000000209794
000000502857
000000369889
000000269693
000000138100
000000447767
000000167494
000000361021
000000513861
000000394794
000000204137
000000167551
000000338061
000000074462
000000453959
000000130245
000000370145
000000559836
000000371322
000000112959
000000215558
000000561950
000000012754
000000237990
000000162882
000000479680
000000052484
000000192780
000000365911
000000581662
000000381208
000000059979
000000397184
000000308849
000000350842
000000489218
000000517084
000000275657
000000246197
000000251125
000000281756
000000094300
000000411330
000000157512
000000503978
000000523938
000000002531
000000115359
000000061693
000000210322
000000503137
000000468894
000000442724
000000560604
000000136988
000000389649
000000353130
000000515773
000000486936
000000022226
000000364738
000000167642
000000577413
000000288753
000000327761
000000008830
000000250720
000000379018
000000080369
000000081504
000000393760
000000556999
000000008568
000000288813
000000475906
000000079878
000000385378
000000356866
000000325873
000000543790
000000477434
000000549725
000000195840
000000368218
000000016125
000000208008
000000103778
000000450330
000000199224
000000470685
000000301817
000000045101
000000074517
000000483795
000000050945
000000436392
000000312997
000000425721
000000189915
000000326770
000000225704
000000140481
000000140028
000000515803
000000146561
000000511828
000000084648
000000257723
000000036953
000000091639
000000208963
000000375916
000000401336
000000330785
000000246474
000000182406
000000035266
000000168246
000000107860
000000276036
000000064822
000000552826
000000483837
000000227480
000000328588
000000434127
000000455339
000000166702
000000324490
000000141400
000000206841
000000306490
000000523297
000000541591
000000031885
000000203859
000000310450
000000459589
000000368321

File diff suppressed because it is too large Load Diff

View File

@ -199,7 +199,7 @@ def print_instances_class_histogram(dataset_dicts, class_names):
def get_detection_dataset_dicts(
dataset_names, filter_empty=True, min_keypoints=0, proposal_files=None
dataset_names, filter_empty=True, min_keypoints=0, proposal_files=None, cfg=None
):
"""
Load and prepare dataset dicts for instance detection/segmentation and semantic segmentation.
@ -236,6 +236,17 @@ def get_detection_dataset_dicts(
if min_keypoints > 0 and has_instances:
dataset_dicts = filter_images_with_few_keypoints(dataset_dicts, min_keypoints)
d_name = dataset_names[0]
if 'voc_coco' in d_name:
if 'train' in d_name:
dataset_dicts = remove_prev_class_and_unk_instances(cfg, dataset_dicts)
elif 'test' in d_name:
dataset_dicts = label_known_class_and_unknown(cfg, dataset_dicts)
elif 'val' in d_name:
dataset_dicts = label_known_class_and_unknown(cfg, dataset_dicts)
elif 'ft' in d_name:
dataset_dicts = remove_unknown_instances(cfg, dataset_dicts)
if has_instances:
try:
class_names = MetadataCatalog.get(dataset_names[0]).thing_classes
@ -247,6 +258,66 @@ def get_detection_dataset_dicts(
assert len(dataset_dicts), "No valid data found in {}.".format(",".join(dataset_names))
return dataset_dicts
def remove_prev_class_and_unk_instances(cfg, dataset_dicts):
# For training data.
prev_intro_cls = cfg.OWOD.PREV_INTRODUCED_CLS
curr_intro_cls = cfg.OWOD.CUR_INTRODUCED_CLS
valid_classes = range(prev_intro_cls, curr_intro_cls)
logger = logging.getLogger(__name__)
logger.info("Valid classes: " + str(valid_classes))
logger.info("Removing earlier seen class objects and the unknown objects...")
for entry in copy.copy(dataset_dicts):
annos = entry["annotations"]
for annotation in copy.copy(annos):
if annotation["category_id"] not in valid_classes:
annos.remove(annotation)
if len(annos) == 0:
dataset_dicts.remove(entry)
return dataset_dicts
def remove_unknown_instances(cfg, dataset_dicts):
# For finetune data.
prev_intro_cls = cfg.OWOD.PREV_INTRODUCED_CLS
curr_intro_cls = cfg.OWOD.CUR_INTRODUCED_CLS
valid_classes = range(0, prev_intro_cls+curr_intro_cls)
logger = logging.getLogger(__name__)
logger.info("Valid classes: " + str(valid_classes))
logger.info("Removing the unknown objects...")
for entry in copy.copy(dataset_dicts):
annos = entry["annotations"]
for annotation in copy.copy(annos):
if annotation["category_id"] not in valid_classes:
annos.remove(annotation)
if len(annos) == 0:
dataset_dicts.remove(entry)
return dataset_dicts
def label_known_class_and_unknown(cfg, dataset_dicts):
# For test and validation data.
# Label known instances the corresponding label and unknown instances as unknown.
prev_intro_cls = cfg.OWOD.PREV_INTRODUCED_CLS
curr_intro_cls = cfg.OWOD.CUR_INTRODUCED_CLS
total_num_class = cfg.MODEL.ROI_HEADS.NUM_CLASSES
known_classes = range(0, prev_intro_cls+curr_intro_cls)
logger = logging.getLogger(__name__)
logger.info("Known classes: " + str(known_classes))
logger.info("Labelling known instances the corresponding label, and unknown instances as unknown...")
for entry in dataset_dicts:
annos = entry["annotations"]
for annotation in annos:
if annotation["category_id"] not in known_classes:
annotation["category_id"] = total_num_class
return dataset_dicts
def build_batch_data_loader(
dataset, sampler, total_batch_size, *, aspect_ratio_grouping=False, num_workers=0
@ -326,6 +397,7 @@ def build_detection_train_loader(cfg, mapper=None):
if cfg.MODEL.KEYPOINT_ON
else 0,
proposal_files=cfg.DATASETS.PROPOSAL_FILES_TRAIN if cfg.MODEL.LOAD_PROPOSALS else None,
cfg=cfg,
)
dataset = DatasetFromList(dataset_dicts, copy=False)
@ -380,6 +452,7 @@ def build_detection_test_loader(cfg, dataset_name, mapper=None):
]
if cfg.MODEL.LOAD_PROPOSALS
else None,
cfg=cfg
)
dataset = DatasetFromList(dataset_dicts)

View File

@ -214,7 +214,16 @@ def register_all_pascal_voc(root):
("voc_2012_trainval", "VOC2012", "trainval"),
("voc_2012_train", "VOC2012", "train"),
("voc_2012_val", "VOC2012", "val"),
("voc_2007_test_unk", "VOC2007", "test_unk"),
("t1_voc_coco_2007_train", "VOC2007", "t1_train"),
("voc_coco_2007_test", "VOC2007", "all_task_test"),
("voc_coco_2007_val", "VOC2007", "all_task_val"),
("t1_voc_coco_2007_ft", "VOC2007", "t1_ft"),
("t2_voc_coco_2007_train", "VOC2007", "t2_train"),
("t2_voc_coco_2007_ft", "VOC2007", "t2_ft"),
("t3_voc_coco_2007_train", "VOC2007", "t3_train"),
("t3_voc_coco_2007_ft", "VOC2007", "t3_ft"),
("t4_voc_coco_2007_train", "VOC2007", "t4_train"),
("t4_voc_coco_2007_ft", "VOC2007", "t4_ft"),
]
for name, dirname, split in SPLITS:
year = 2007 if "2007" in name else 2012
@ -222,23 +231,23 @@ def register_all_pascal_voc(root):
MetadataCatalog.get(name).evaluator_type = "pascal_voc"
def register_all_voc_style_coco(root):
SPLITS = [
("t2_train", "coco17_voc_style"),
("t2_test", "coco17_voc_style"),
("t2_test_unk", "coco17_voc_style"),
("t3_train", "coco17_voc_style"),
("t3_test", "coco17_voc_style"),
("t3_test_unk", "coco17_voc_style"),
("t4_train", "coco17_voc_style"),
("t4_test", "coco17_voc_style"),
("t4_test_unk", "coco17_voc_style"),
("t2_all_test_unk", "coco17_voc_style")
]
for name, dirname in SPLITS:
year = 2007
register_voc_style_coco(name, os.path.join(root, dirname), name, year)
MetadataCatalog.get(name).evaluator_type = "pascal_voc"
# def register_all_voc_style_coco(root):
# SPLITS = [
# ("t2_train", "coco17_voc_style"),
# ("t2_test", "coco17_voc_style"),
# ("t2_test_unk", "coco17_voc_style"),
# ("t3_train", "coco17_voc_style"),
# ("t3_test", "coco17_voc_style"),
# ("t3_test_unk", "coco17_voc_style"),
# ("t4_train", "coco17_voc_style"),
# ("t4_test", "coco17_voc_style"),
# ("t4_test_unk", "coco17_voc_style"),
# ("t2_all_test_unk", "coco17_voc_style")
# ]
# for name, dirname in SPLITS:
# year = 2007
# register_voc_style_coco(name, os.path.join(root, dirname), name, year)
# MetadataCatalog.get(name).evaluator_type = "pascal_voc"
def register_all_ade20k(root):
@ -270,5 +279,5 @@ if __name__.endswith(".builtin"):
# register_all_pascal_voc(_root)
# register_all_pascal_voc('/home/joseph/workspace/OWOD/datasets')
register_all_pascal_voc('/home/fk1/workspace/OWOD/datasets')
register_all_voc_style_coco('/home/fk1/workspace/OWOD/datasets')
# register_all_voc_style_coco('/home/fk1/workspace/OWOD/datasets')
register_all_ade20k(_root)

View File

@ -19,12 +19,53 @@ __all__ = ["load_voc_instances", "register_pascal_voc"]
# "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person",
# "pottedplant", "sheep", "sofa", "train", "tvmonitor"
# )
CLASS_NAMES = (
# CLASS_NAMES = (
# "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat",
# "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person",
# "pottedplant", "sheep", "sofa", "train", "tvmonitor", "unknown"
# )
# fmt: on
VOC_CLASS_NAMES_COCOFIED = [
"airplane", "dining table", "motorcycle",
"potted plant", "couch", "tv"
]
BASE_VOC_CLASS_NAMES = [
"aeroplane", "diningtable", "motorbike",
"pottedplant", "sofa", "tvmonitor"
]
VOC_CLASS_NAMES = [
"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat",
"chair", "cow", "diningtable", "dog", "horse", "motorbike", "person",
"pottedplant", "sheep", "sofa", "train", "tvmonitor", "unknown"
)
# fmt: on
"pottedplant", "sheep", "sofa", "train", "tvmonitor"
]
T2_CLASS_NAMES = [
"truck", "traffic light", "fire hydrant", "stop sign", "parking meter",
"bench", "elephant", "bear", "zebra", "giraffe",
"backpack", "umbrella", "handbag", "tie", "suitcase",
"microwave", "oven", "toaster", "sink", "refrigerator"
]
T3_CLASS_NAMES = [
"frisbee", "skis", "snowboard", "sports ball", "kite",
"baseball bat", "baseball glove", "skateboard", "surfboard", "tennis racket",
"banana", "apple", "sandwich", "orange", "broccoli",
"carrot", "hot dog", "pizza", "donut", "cake"
]
T4_CLASS_NAMES = [
"bed", "toilet", "laptop", "mouse",
"remote", "keyboard", "cell phone", "book", "clock",
"vase", "scissors", "teddy bear", "hair drier", "toothbrush",
"wine glass", "cup", "fork", "knife", "spoon", "bowl"
]
UNK_CLASS = ["unknown"]
VOC_COCO_CLASS_NAMES = tuple(itertools.chain(VOC_CLASS_NAMES, T2_CLASS_NAMES, T3_CLASS_NAMES, T4_CLASS_NAMES, UNK_CLASS))
def load_voc_instances(dirname: str, split: str, class_names: Union[List[str], Tuple[str, ...]]):
"""
@ -42,11 +83,6 @@ def load_voc_instances(dirname: str, split: str, class_names: Union[List[str], T
annotation_dirname = PathManager.get_local_path(os.path.join(dirname, "Annotations/"))
dicts = []
for fileid in fileids:
has_unk = False
if 'unk' in fileid:
has_unk = True
fileid = fileid.replace('_unk','')
anno_file = os.path.join(annotation_dirname, fileid + ".xml")
jpeg_file = os.path.join(dirname, "JPEGImages", fileid + ".jpg")
@ -63,11 +99,8 @@ def load_voc_instances(dirname: str, split: str, class_names: Union[List[str], T
for obj in tree.findall("object"):
cls = obj.find("name").text
if has_unk:
if cls not in class_names:
cls = 'unknown'
# else:
# continue
if cls in VOC_CLASS_NAMES_COCOFIED:
cls = BASE_VOC_CLASS_NAMES[VOC_CLASS_NAMES_COCOFIED.index(cls)]
# We include "difficult" samples in training.
# Based on limited experiments, they don't hurt accuracy.
# difficult = int(obj.find("difficult").text)
@ -89,7 +122,11 @@ def load_voc_instances(dirname: str, split: str, class_names: Union[List[str], T
return dicts
def register_pascal_voc(name, dirname, split, year, class_names=CLASS_NAMES):
def register_pascal_voc(name, dirname, split, year):
if "voc_coco" in name:
class_names = VOC_COCO_CLASS_NAMES
else:
class_names = tuple(VOC_CLASS_NAMES)
DatasetCatalog.register(name, lambda: load_voc_instances(dirname, split, class_names))
MetadataCatalog.get(name).set(
thing_classes=list(class_names), dirname=dirname, year=year, split=split

View File

@ -0,0 +1,96 @@
# -*- coding: utf-8 -*-
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
import numpy as np
import os
import xml.etree.ElementTree as ET
from typing import List, Tuple, Union
from fvcore.common.file_io import PathManager
from detectron2.data import DatasetCatalog, MetadataCatalog
from detectron2.structures import BoxMode
__all__ = ["load_voc_instances", "register_pascal_voc"]
# fmt: off
# CLASS_NAMES = (
# "aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat",
# "chair", "cow", "diningtable", "dog", "horse", "motorbike", "person",
# "pottedplant", "sheep", "sofa", "train", "tvmonitor"
# )
CLASS_NAMES = (
"aeroplane", "bicycle", "bird", "boat", "bottle", "bus", "car", "cat",
"chair", "cow", "diningtable", "dog", "horse", "motorbike", "person",
"pottedplant", "sheep", "sofa", "train", "tvmonitor", "unknown"
)
# fmt: on
def load_voc_instances(dirname: str, split: str, class_names: Union[List[str], Tuple[str, ...]]):
"""
Load Pascal VOC detection annotations to Detectron2 format.
Args:
dirname: Contain "Annotations", "ImageSets", "JPEGImages"
split (str): one of "train", "test", "val", "trainval"
class_names: list or tuple of class names
"""
with PathManager.open(os.path.join(dirname, "ImageSets", "Main", split + ".txt")) as f:
fileids = np.loadtxt(f, dtype=np.str)
# Needs to read many small annotation files. Makes sense at local
annotation_dirname = PathManager.get_local_path(os.path.join(dirname, "Annotations/"))
dicts = []
for fileid in fileids:
has_unk = False
if 'unk' in fileid:
has_unk = True
fileid = fileid.replace('_unk','')
anno_file = os.path.join(annotation_dirname, fileid + ".xml")
jpeg_file = os.path.join(dirname, "JPEGImages", fileid + ".jpg")
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 = []
for obj in tree.findall("object"):
cls = obj.find("name").text
if has_unk:
if cls not in class_names:
cls = 'unknown'
# else:
# continue
# We include "difficult" samples in training.
# Based on limited experiments, they don't hurt accuracy.
# difficult = int(obj.find("difficult").text)
# if difficult == 1:
# continue
bbox = obj.find("bndbox")
bbox = [float(bbox.find(x).text) for x in ["xmin", "ymin", "xmax", "ymax"]]
# Original annotations are integers in the range [1, W or H]
# Assuming they mean 1-based pixel indices (inclusive),
# a box with annotation (xmin=1, xmax=W) covers the whole image.
# In coordinate space this is represented by (xmin=0, xmax=W)
bbox[0] -= 1.0
bbox[1] -= 1.0
instances.append(
{"category_id": class_names.index(cls), "bbox": bbox, "bbox_mode": BoxMode.XYXY_ABS}
)
r["annotations"] = instances
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(
thing_classes=list(class_names), dirname=dirname, year=year, split=split
)

View File

@ -627,7 +627,7 @@ class FastRCNNOutputLayers(nn.Module):
if item == None:
all_means[i] = torch.zeros((length))
distances = torch.cdist(fg_features, torch.stack(all_means).cuda(), p=2.0)
distances = torch.cdist(fg_features, torch.stack(all_means).cuda(), p=10.0)
labels = []
for index, feature in enumerate(fg_features):