diff --git a/PaddleCV/object_detection/configs/cascade_rcnn_r50_fpn_1x.yml b/PaddleCV/object_detection/configs/cascade_rcnn_r50_fpn_1x.yml index 259c54914faf5be4d368372a93016648d80e84f0..a950e612fc10e9691130c9fda669f2db0b6e2258 100644 --- a/PaddleCV/object_detection/configs/cascade_rcnn_r50_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/cascade_rcnn_r50_fpn_1x.yml @@ -136,7 +136,6 @@ FasterRCNNTestFeed: dataset: annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt drop_last: false num_workers: 2 shuffle: false diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r101_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r101_1x.yml index 82350c9ba66e813d1ab2c02db6801441c7363993..b779dc021592398520ed30cd6b48e914503182e8 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r101_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r101_1x.yml @@ -115,5 +115,3 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r101_fpn_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r101_fpn_1x.yml index 1855863ebed84d3c76c840cc92162d52895835e1..81c496d89f44a13ef5a44e864299eb49c1293105 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r101_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r101_fpn_1x.yml @@ -138,6 +138,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r101_fpn_2x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r101_fpn_2x.yml index 7179c43c31b2d241e4e7b605f6b7c45a076176ca..4352ce058f65883ac80124ec89b4094fd95611ca 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r101_fpn_2x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r101_fpn_2x.yml @@ -138,6 +138,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r101_vd_fpn_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r101_vd_fpn_1x.yml index 120250b32daeb7624bc823d36d43c3cdd57c0460..3e709f50a102913323c163d4ba3c976ffad505d1 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r101_vd_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r101_vd_fpn_1x.yml @@ -139,6 +139,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r101_vd_fpn_2x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r101_vd_fpn_2x.yml index ad55f1899b61acb5f85da4c0c33f59092557f994..7321afd9223e10296713c549a8212d99a79b2a2a 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r101_vd_fpn_2x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r101_vd_fpn_2x.yml @@ -139,6 +139,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r50_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r50_1x.yml index efe582a992038507b22fdc7e78eba3b6a7855528..c18191ef19a47b1ce591cbd966358df3279ef3f7 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r50_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r50_1x.yml @@ -115,5 +115,3 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r50_2x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r50_2x.yml index c5aac7f294cb01ee051349c06e1db7d72d95b3e8..03b4336af42b99fb68ad000add92e552559558b5 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r50_2x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r50_2x.yml @@ -115,5 +115,3 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_1x.yml index b8fc954e3a9e8073ab80fe510077dfc41308a6c4..cc0dea95e8bf657cb4970b337557ee5f2147e94b 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r50_fpn_1x.yml @@ -136,7 +136,6 @@ FasterRCNNTestFeed: dataset: annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt drop_last: false num_workers: 2 shuffle: false diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r50_vd_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r50_vd_1x.yml index 11c0133794cd064e9c0f114853817a172b2d306a..bad322394a2b0aed0d4d09992b9519469d7b3c46 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r50_vd_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r50_vd_1x.yml @@ -117,5 +117,3 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/configs/faster_rcnn_r50_vd_fpn_2x.yml b/PaddleCV/object_detection/configs/faster_rcnn_r50_vd_fpn_2x.yml index cf356728aab5409b5d15c66793c27248667c5452..72e0d781859341b991f722a4cf95644ec4290b1e 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_r50_vd_fpn_2x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_r50_vd_fpn_2x.yml @@ -139,6 +139,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_se154_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_se154_1x.yml index a9a9890d805e85f036b012c2425e118217775f22..564ac8c7111e19edce1d5f33dc48ccca17b4aeae 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_se154_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_se154_1x.yml @@ -124,6 +124,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_se154_fpn_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_se154_fpn_1x.yml index e350b99c291d865f417cfdf1a3ac86a9803f0cfd..bfd00e434a8e88c656d6198ad326e48d785aacbe 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_se154_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_se154_fpn_1x.yml @@ -141,6 +141,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_se154_fpn_s1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_se154_fpn_s1x.yml index baf57b579c701516ce3d491c503ff9cc7b7aab08..1864ad7a7656c5d57b3c3752e46c7390862e669f 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_se154_fpn_s1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_se154_fpn_s1x.yml @@ -141,6 +141,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_x101_64x4d_fpn_1x.yml b/PaddleCV/object_detection/configs/faster_rcnn_x101_64x4d_fpn_1x.yml index afea710d118118f9a5d584db2e4bc254d7d804f5..00ce33876b328a9061eebe882ba4ee0fb6f7f2bc 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_x101_64x4d_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_x101_64x4d_fpn_1x.yml @@ -140,6 +140,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/faster_rcnn_x101_64x4d_fpn_2x.yml b/PaddleCV/object_detection/configs/faster_rcnn_x101_64x4d_fpn_2x.yml index 0dfff305748fa6be73627d2f1913c504bf33665e..6940c38cb0be88f0fb75002b7a0185a26b1078ed 100644 --- a/PaddleCV/object_detection/configs/faster_rcnn_x101_64x4d_fpn_2x.yml +++ b/PaddleCV/object_detection/configs/faster_rcnn_x101_64x4d_fpn_2x.yml @@ -140,6 +140,5 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 shuffle: False diff --git a/PaddleCV/object_detection/configs/mask_rcnn_r101_fpn_1x.yml b/PaddleCV/object_detection/configs/mask_rcnn_r101_fpn_1x.yml index 6bad5aac7310ca16b325a8a6ec0af0377054171d..4da7f6c1b076ad37bd2e12b718abce3d5657f047 100644 --- a/PaddleCV/object_detection/configs/mask_rcnn_r101_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/mask_rcnn_r101_fpn_1x.yml @@ -147,7 +147,5 @@ MaskRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 num_workers: 2 use_padded_im_info: True diff --git a/PaddleCV/object_detection/configs/mask_rcnn_r101_fpn_2x.yml b/PaddleCV/object_detection/configs/mask_rcnn_r101_fpn_2x.yml index e44850b64d9327c403d2504fc2807a3e38e7cdcf..78876a51d5699e7db6f29143a7be2f9c6488adc6 100644 --- a/PaddleCV/object_detection/configs/mask_rcnn_r101_fpn_2x.yml +++ b/PaddleCV/object_detection/configs/mask_rcnn_r101_fpn_2x.yml @@ -147,7 +147,5 @@ MaskRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 num_workers: 2 use_padded_im_info: True diff --git a/PaddleCV/object_detection/configs/mask_rcnn_r50_1x.yml b/PaddleCV/object_detection/configs/mask_rcnn_r50_1x.yml index 3d8b45964ec4a9bfa764dc7438b1332922a5a9b5..0358a3bfa72dee553efc9ea0840164a5aa561186 100644 --- a/PaddleCV/object_detection/configs/mask_rcnn_r50_1x.yml +++ b/PaddleCV/object_detection/configs/mask_rcnn_r50_1x.yml @@ -128,5 +128,3 @@ MaskRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/configs/mask_rcnn_r50_2x.yml b/PaddleCV/object_detection/configs/mask_rcnn_r50_2x.yml index becd8a7faddb6b97a5a709fbd0e8ce1133ee5ada..1c67e59a209709c9bee74b54eaa7d16b300a127f 100644 --- a/PaddleCV/object_detection/configs/mask_rcnn_r50_2x.yml +++ b/PaddleCV/object_detection/configs/mask_rcnn_r50_2x.yml @@ -129,5 +129,3 @@ MaskRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/configs/mask_rcnn_r50_fpn_1x.yml b/PaddleCV/object_detection/configs/mask_rcnn_r50_fpn_1x.yml index 91342fd117200d7c3f1a50eb504d1b028047ded0..753fcd62339a9f2a6e5d39d4904a467e8878d4ac 100644 --- a/PaddleCV/object_detection/configs/mask_rcnn_r50_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/mask_rcnn_r50_fpn_1x.yml @@ -147,7 +147,5 @@ MaskRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 num_workers: 2 use_padded_im_info: True diff --git a/PaddleCV/object_detection/configs/mask_rcnn_r50_fpn_2x.yml b/PaddleCV/object_detection/configs/mask_rcnn_r50_fpn_2x.yml index 6fcd13d503a8777bcc97b83d4e50f8d7a06a7ed5..623bdf11812aa31972708ae1e466024558372349 100644 --- a/PaddleCV/object_detection/configs/mask_rcnn_r50_fpn_2x.yml +++ b/PaddleCV/object_detection/configs/mask_rcnn_r50_fpn_2x.yml @@ -147,7 +147,5 @@ MaskRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt - samples: 5 num_workers: 2 use_padded_im_info: True diff --git a/PaddleCV/object_detection/configs/mask_rcnn_r50_vd_fpn_2x.yml b/PaddleCV/object_detection/configs/mask_rcnn_r50_vd_fpn_2x.yml index e33ca596987925c744425cda764c1e2e9e3ee45b..e49c42c641faa475c4e4ebe1f7168d50572037c8 100644 --- a/PaddleCV/object_detection/configs/mask_rcnn_r50_vd_fpn_2x.yml +++ b/PaddleCV/object_detection/configs/mask_rcnn_r50_vd_fpn_2x.yml @@ -150,6 +150,5 @@ MaskRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt num_workers: 2 use_padded_im_info: True diff --git a/PaddleCV/object_detection/configs/retinanet_r50_fpn_1x.yml b/PaddleCV/object_detection/configs/retinanet_r50_fpn_1x.yml index dc697f7363dea91c8aa3159ae76f675ca206070d..188c06dfcc2401670167d5d826542cb86eb35b44 100644 --- a/PaddleCV/object_detection/configs/retinanet_r50_fpn_1x.yml +++ b/PaddleCV/object_detection/configs/retinanet_r50_fpn_1x.yml @@ -151,7 +151,6 @@ FasterRCNNTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: val2017.txt drop_last: false image_shape: [3, 1333, 800] num_workers: 2 diff --git a/PaddleCV/object_detection/configs/ssd_mobilenet_v1_voc.yml b/PaddleCV/object_detection/configs/ssd_mobilenet_v1_voc.yml index e57564f60d4eac7922f39f2d64f648ac6798c282..eb033192a0790f2d0f73986b31e017df151c675d 100644 --- a/PaddleCV/object_detection/configs/ssd_mobilenet_v1_voc.yml +++ b/PaddleCV/object_detection/configs/ssd_mobilenet_v1_voc.yml @@ -84,4 +84,3 @@ SSDTestFeed: image_dir: VOCdevkit/VOC_all/JPEGImages use_default_label: false drop_last: false - test_file: data/voc/VOCdevkit/VOC_all/ImageSets/Main/test.txt diff --git a/PaddleCV/object_detection/configs/yolov3_darknet.yml b/PaddleCV/object_detection/configs/yolov3_darknet.yml index 3888a1e45b3162beee5b72fe3c28ce8d6cfbbf96..f9f9bfa5f63d679ff444f57117f6397a9afeb298 100644 --- a/PaddleCV/object_detection/configs/yolov3_darknet.yml +++ b/PaddleCV/object_detection/configs/yolov3_darknet.yml @@ -80,5 +80,3 @@ YoloTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: ../val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/configs/yolov3_mobilenet_v1.yml b/PaddleCV/object_detection/configs/yolov3_mobilenet_v1.yml index 280a3ed359cc5b52c671edd3a33d9c179d80dd9b..f6658d36d4d7131a537048b5cc1d55d63aa55d5b 100644 --- a/PaddleCV/object_detection/configs/yolov3_mobilenet_v1.yml +++ b/PaddleCV/object_detection/configs/yolov3_mobilenet_v1.yml @@ -81,5 +81,3 @@ YoloTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: ../val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/configs/yolov3_r34.yml b/PaddleCV/object_detection/configs/yolov3_r34.yml index e78f18a23a6149b3811512f1b14613a2bd2260ba..2c53d14105e5ea73b4aa8e707e4da172024c56fa 100644 --- a/PaddleCV/object_detection/configs/yolov3_r34.yml +++ b/PaddleCV/object_detection/configs/yolov3_r34.yml @@ -17,6 +17,8 @@ YOLOv3: ResNet: norm_type: sync_bn + freeze_at: 0 + freeze_norm: False norm_decay: 0. depth: 34 feature_maps: [3, 4, 5] @@ -81,5 +83,3 @@ YoloTestFeed: dataset_dir: data/coco annotation: annotations/instances_val2017.json image_dir: val2017 - test_file: ../val2017.txt - samples: 5 diff --git a/PaddleCV/object_detection/ppdet/data/data_feed.py b/PaddleCV/object_detection/ppdet/data/data_feed.py index 528f8c6c1df84ba83e6e7b98341b6573c5803d7a..3aaed5adac7b5fa86eb23967a8152fa75c017ea8 100644 --- a/PaddleCV/object_detection/ppdet/data/data_feed.py +++ b/PaddleCV/object_detection/ppdet/data/data_feed.py @@ -81,9 +81,9 @@ def create_reader(feed, max_iter=0): 'TYPE': type(feed.dataset).__source__ } } - - if mode == 'TEST': - data_config[mode]['TEST_FILE'] = feed.test_file + + if len(getattr(feed.dataset, 'images', [])) > 0: + data_config[mode]['IMAGES'] = feed.dataset.images transform_config = { 'WORKER_CONF': { @@ -244,12 +244,16 @@ class SimpleDataSet(DataSet): __source__ = 'SimpleSource' def __init__(self, - dataset_dir=VOC_DATASET_DIR, - annotation=VOC_TEST_ANNOTATION, - image_dir=VOC_IMAGE_DIR, - use_default_label=VOC_USE_DEFAULT_LABEL): + dataset_dir=None, + annotation=None, + image_dir=None, + use_default_label=None): super(SimpleDataSet, self).__init__( dataset_dir=dataset_dir, annotation=annotation, image_dir=image_dir) + self.images = [] + + def add_images(self, images): + self.images.extend(images) @serializable @@ -281,7 +285,6 @@ class DataFeed(object): samples=-1, drop_last=False, with_background=True, - test_file=None, num_workers=2, bufsize=10, use_process=False, @@ -296,7 +299,6 @@ class DataFeed(object): self.samples = samples self.drop_last = drop_last self.with_background = with_background - self.test_file = test_file self.num_workers = num_workers self.bufsize = bufsize self.use_process = use_process @@ -385,7 +387,6 @@ class TestFeed(DataFeed): shuffle=False, drop_last=False, with_background=True, - test_file=None, num_workers=2): super(TestFeed, self).__init__( dataset, @@ -397,7 +398,6 @@ class TestFeed(DataFeed): shuffle=shuffle, drop_last=drop_last, with_background=with_background, - test_file=test_file, num_workers=num_workers) @@ -522,7 +522,6 @@ class FasterRCNNEvalFeed(DataFeed): shuffle=False, samples=-1, drop_last=False, - test_file=None, num_workers=2, use_padded_im_info=True): sample_transforms.append(ArrangeTestRCNN()) @@ -536,7 +535,6 @@ class FasterRCNNEvalFeed(DataFeed): shuffle=shuffle, samples=samples, drop_last=drop_last, - test_file=test_file, num_workers=num_workers, use_padded_im_info=use_padded_im_info) self.mode = 'VAL' @@ -564,7 +562,6 @@ class FasterRCNNTestFeed(DataFeed): shuffle=False, samples=-1, drop_last=False, - test_file=None, num_workers=2, use_padded_im_info=True): sample_transforms.append(ArrangeTestRCNN()) @@ -580,7 +577,6 @@ class FasterRCNNTestFeed(DataFeed): shuffle=shuffle, samples=samples, drop_last=drop_last, - test_file=test_file, num_workers=num_workers, use_padded_im_info=use_padded_im_info) self.mode = 'TEST' @@ -612,7 +608,6 @@ class MaskRCNNEvalFeed(DataFeed): shuffle=False, samples=-1, drop_last=False, - test_file=None, num_workers=2, use_process=False, use_padded_im_info=True): @@ -627,7 +622,6 @@ class MaskRCNNEvalFeed(DataFeed): shuffle=shuffle, samples=samples, drop_last=drop_last, - test_file=test_file, num_workers=num_workers, use_process=use_process, use_padded_im_info=use_padded_im_info) @@ -657,7 +651,6 @@ class MaskRCNNTestFeed(DataFeed): shuffle=False, samples=-1, drop_last=False, - test_file=None, num_workers=2, use_process=False, use_padded_im_info=True): @@ -674,7 +667,6 @@ class MaskRCNNTestFeed(DataFeed): shuffle=shuffle, samples=samples, drop_last=drop_last, - test_file=test_file, num_workers=num_workers, use_process=use_process, use_padded_im_info=use_padded_im_info) @@ -805,7 +797,6 @@ class SSDTestFeed(DataFeed): shuffle=False, samples=-1, drop_last=False, - test_file=None, num_workers=8, bufsize=10, use_process=False): @@ -822,7 +813,6 @@ class SSDTestFeed(DataFeed): shuffle=shuffle, samples=samples, drop_last=drop_last, - test_file=test_file, num_workers=num_workers) self.mode = 'TEST' @@ -961,10 +951,9 @@ class YoloTestFeed(DataFeed): batch_transforms=[], batch_size=1, shuffle=False, - samples=1, + samples=-1, drop_last=False, with_background=False, - test_file=None, num_workers=8, num_max_boxes=50, use_process=False): @@ -982,7 +971,6 @@ class YoloTestFeed(DataFeed): samples=samples, drop_last=drop_last, with_background=with_background, - test_file=test_file, num_workers=num_workers, use_process=use_process) self.num_max_boxes = num_max_boxes diff --git a/PaddleCV/object_detection/ppdet/data/source/simple_source.py b/PaddleCV/object_detection/ppdet/data/source/simple_source.py index 659ab879c20d52c5e6c9bd05df37dec5a85b20d6..a65dd054e369d97b303b9018facac3381440dfec 100644 --- a/PaddleCV/object_detection/ppdet/data/source/simple_source.py +++ b/PaddleCV/object_detection/ppdet/data/source/simple_source.py @@ -30,26 +30,23 @@ class SimpleSource(Dataset): Load image files for testing purpose Args: - test_file (str): list of image file names, relative to `image_dir` - image_dir (str): root dir for images + images (list): list of path of images samples (int): number of samples to load, -1 means all load_img (bool): should images be loaded """ def __init__(self, - test_file='', - image_dir=None, + images=[], samples=-1, load_img=True, **kwargs): super(SimpleSource, self).__init__() self._epoch = -1 - assert test_file != '' and os.path.isfile(test_file), \ - "test file not found: " + test_file - self._fname = test_file - self._image_dir = image_dir - assert image_dir is not None and os.path.isdir(image_dir), \ - "image directory not found: " + image_dir + for image in images: + assert image != '' and os.path.isfile(image), \ + "Image {} not found".format(image) + self._images = images + self._fname = None self._simple = None self._pos = -1 self._drained = False @@ -68,32 +65,25 @@ class SimpleSource(Dataset): sample = copy.deepcopy(self._simple[self._pos]) if self._load_img: sample['image'] = self._load_image(sample['im_file']) - else: - sample['im_file'] = os.path.join(self._image_dir, - sample['im_file']) + self._pos += 1 return sample def _load(self): - assert os.path.isfile(self._fname) and self._fname.endswith('.txt'), \ - "invalid test file path" ct = 0 records = [] - with open(self._fname, 'r') as fr: - while True: - line = fr.readline().strip() - if not line or (self._samples > 0 and ct >= self._samples): - break - rec = {'im_id': np.array([ct]), 'im_file': line} - self._imid2path[ct] = line - ct += 1 - records.append(rec) - assert len(records) > 0, "no image file found in " + self._fname + for image in self._images: + if self._samples > 0 and ct >= self._samples: + break + rec = {'im_id': np.array([ct]), 'im_file': image} + self._imid2path[ct] = image + ct += 1 + records.append(rec) + assert len(records) > 0, "no image file found" return records def _load_image(self, where): - fn = os.path.join(self._image_dir, where) - with open(fn, 'rb') as f: + with open(where, 'rb') as f: return f.read() def reset(self): diff --git a/PaddleCV/object_detection/ppdet/utils/cli.py b/PaddleCV/object_detection/ppdet/utils/cli.py index 54a43b76c27731c354e3e3ddfe1446167d97ed01..e6f5cd55250a23714c65121a2ec0e70bf333410b 100644 --- a/PaddleCV/object_detection/ppdet/utils/cli.py +++ b/PaddleCV/object_detection/ppdet/utils/cli.py @@ -61,6 +61,16 @@ def parse_args(): action='store_true', default=False, help="Whether perform evaluation in train") + parser.add_argument( + "--infer_dir", + type=str, + default=None, + help="Image directory path to perform inference.") + parser.add_argument( + "--infer_img", + type=str, + default=None, + help="Image path to perform inference, --infer-img has a higher priority than --image-dir") parser.add_argument( "-o", "--opt", nargs=REMAINDER, help="set configuration options") args = parser.parse_args() diff --git a/PaddleCV/object_detection/ppdet/utils/visualizer.py b/PaddleCV/object_detection/ppdet/utils/visualizer.py index 4924ab030f21b30a085bae0b45d6b5e4d2915899..4e83c9a2e69c3ed9bb594582568a3b60faa7adc3 100644 --- a/PaddleCV/object_detection/ppdet/utils/visualizer.py +++ b/PaddleCV/object_detection/ppdet/utils/visualizer.py @@ -38,22 +38,27 @@ def visualize_results(image_path, bbox_results=None, mask_results=None): """ - TODO(dengkaipeng): add more comments Visualize bbox and mask results """ - image = None + if not os.path.exists(SAVE_HOME): + os.makedirs(SAVE_HOME) + + logger.info("Image {} detect: ".format(image_path)) + image = Image.open(image_path) if mask_results: - image = draw_mask(image_path, mask_results, threshold) + image = draw_mask(image, mask_results, threshold) if bbox_results: - draw_bbox(image_path, catid2name, bbox_results, threshold, image) + image = draw_bbox(image, catid2name, bbox_results, threshold) + + save_name = get_save_image_name(image_path) + logger.info("Detection results save in {}\n".format(save_name)) + image.save(save_name) -def draw_mask(image_path, segms, threshold, alpha=0.7, save_image=False): +def draw_mask(image, segms, threshold, alpha=0.7): """ - TODO(dengkaipeng): add more comments Draw mask on image """ - image = Image.open(image_path) im_width, im_height = image.size mask_color_id = 0 w_ratio = .4 @@ -72,23 +77,13 @@ def draw_mask(image_path, segms, threshold, alpha=0.7, save_image=False): image[idx[0], idx[1], :] *= 1.0 - alpha image[idx[0], idx[1], :] += alpha * color_mask image = Image.fromarray(image.astype('uint8')) - - if not os.path.exists(SAVE_HOME): - os.makedirs(SAVE_HOME) - if save_image: - save_name = get_save_image_name(image_path) - logger.info("Detection mask results save in {}".format(save_name)) - image.save(save_name) return image -def draw_bbox(image_path, catid2name, bboxes, threshold, image=None): +def draw_bbox(image, catid2name, bboxes, threshold): """ - TODO(dengkaipeng): add more comments Draw bbox on image """ - if image is None: - image = Image.open(image_path) draw = ImageDraw.Draw(image) im_width, im_height = image.size @@ -106,13 +101,12 @@ def draw_bbox(image_path, catid2name, bboxes, threshold, image=None): fill='red') if image.mode == 'RGB': draw.text((xmin, ymin), catid2name[catid], (255, 255, 0)) + logger.info("\t {:15s} at {:25} score: {:.5f}".format( + catid2name[catid], + str(list(map(int, [xmin, ymin, xmax, ymax]))), + score)) - if not os.path.exists(SAVE_HOME): - os.makedirs(SAVE_HOME) - save_name = get_save_image_name(image_path) - logger.info("Detection bbox results save in {}".format(save_name)) - image.save(save_name) - + return image def get_save_image_name(image_path): """ diff --git a/PaddleCV/object_detection/tools/infer.py b/PaddleCV/object_detection/tools/infer.py index a811d2d5820b878796bc42306ddef3431b578802..3abf0022aaa38a29aee75316fbf08d315d12127c 100644 --- a/PaddleCV/object_detection/tools/infer.py +++ b/PaddleCV/object_detection/tools/infer.py @@ -17,6 +17,7 @@ from __future__ import division from __future__ import print_function import os +import glob import numpy as np @@ -37,6 +38,32 @@ logging.basicConfig(level=logging.INFO, format=FORMAT) logger = logging.getLogger(__name__) +def get_test_images(infer_dir, infer_img): + """ + Get image path list in TEST mode + """ + assert infer_img is not None or infer_dir is not None, \ + "--infer-img or --infer-dir should be set" + images = [] + + # infer_img has a higher priority + if infer_img and os.path.isfile(infer_img): + images.append(infer_img) + return images + + infer_dir = os.path.abspath(infer_dir) + assert os.path.isdir(infer_dir), \ + "infer_dir {} is not a directory".format(infer_dir) + for fmt in ['jpg', 'jpeg', 'png', 'bmp']: + images.extend(glob.glob('{}/*.{}'.format(infer_dir, fmt))) + + assert len(images) > 0, "no image found in {} with " \ + "extension {}".format(infer_dir, image_ext) + logger.info("Found {} inference images in total.".format(len(images))) + + return images + + def main(): args = parse_args() cfg = load_config(args.config) @@ -53,6 +80,9 @@ def main(): else: test_feed = create(cfg['test_feed']) + test_images = get_test_images(args.infer_dir, args.infer_img) + test_feed.dataset.add_images(test_images) + place = fluid.CUDAPlace(0) if cfg['use_gpu'] else fluid.CPUPlace() exe = fluid.Executor(place) @@ -103,7 +133,7 @@ def main(): logger.info('Infer iter {}'.format(iter_id)) im_id = int(res['im_id'][0]) - image_path = os.path.join(test_feed.dataset.image_dir, imid2path[im_id]) + image_path = imid2path[im_id] if cfg['metric'] == 'COCO': bbox_results = None mask_results = None