未验证 提交 2aed7f63 编写于 作者: Q qingqing01 提交者: GitHub

Fix dtype of feed_vars in Yolov3 and add eval for some detector (#2497)

* Fix dtype for Yolov3.
* Clean unit testing.
* Add eval() for COCO-based algo.
上级 2239ecbf
......@@ -246,7 +246,8 @@ class SimpleDataSet(DataSet):
def __init__(self,
dataset_dir=VOC_DATASET_DIR,
annotation=VOC_TEST_ANNOTATION,
image_dir=VOC_IMAGE_DIR):
image_dir=VOC_IMAGE_DIR,
use_default_label=VOC_USE_DEFAULT_LABEL):
super(SimpleDataSet, self).__init__(
dataset_dir=dataset_dir, annotation=annotation, image_dir=image_dir)
......
......@@ -159,5 +159,8 @@ class CascadeRCNN(object):
def train(self, feed_vars):
return self.build(feed_vars, 'train')
def eval(self, feed_vars):
return self.build(feed_vars, 'test')
def test(self, feed_vars):
return self.build(feed_vars, 'test')
......@@ -116,5 +116,8 @@ class FasterRCNN(object):
def train(self, feed_vars):
return self.build(feed_vars, 'train')
def eval(self, feed_vars):
return self.build(feed_vars, 'test')
def test(self, feed_vars):
return self.build(feed_vars, 'test')
......@@ -187,3 +187,6 @@ class MaskRCNN(object):
fluid.layers.assign(input=mask_out, output=mask_pred)
return {'bbox': bbox_pred, 'mask': mask_pred}
def eval(self, feed_vars):
self.test(feed_vars)
......@@ -71,5 +71,8 @@ class RetinaNet(object):
def train(self, feed_vars):
return self._forward(feed_vars, 'train')
def eval(self, feed_vars):
return self._forward(feed_vars, 'test')
def test(self, feed_vars):
return self._forward(feed_vars, 'test')
......@@ -65,5 +65,8 @@ class YOLOv3(object):
def train(self, feed_vars):
return self._forward(feed_vars, mode='train')
def eval(self, feed_vars):
return self._forward(feed_vars, mode='test')
def test(self, feed_vars):
return self._forward(feed_vars, mode='test')
......@@ -56,7 +56,7 @@ def create_feeds(feed, use_pyreader=True):
feed_var_map['gt_score']['lod_level'] = 0
feed_var_map['gt_box']['lod_level'] = 0
feed_var_map['im_shape']['shape'] = [2]
feed_var_map['im_shape']['dtype'] = ['int32']
feed_var_map['im_shape']['dtype'] = 'int32'
feed_vars = OrderedDict([(key, fluid.layers.data(
name=feed_var_map[key]['name'],
......
......@@ -26,12 +26,15 @@ from ppdet.core.workspace import load_config, merge_config, create
from ppdet.modeling.model_input import create_feeds
class TestDetectorFasterRCNN(unittest.TestCase):
class TestFasterRCNN(unittest.TestCase):
def setUp(self):
cfg_file = 'config_demo/faster_rcnn_r50_1x.yml'
self.cfg = load_config(cfg_file)
self.set_config()
self.cfg = load_config(self.cfg_file)
self.detector_type = self.cfg['architecture']
def set_config(self):
self.cfg_file = 'configs/faster_rcnn_r50_1x.yml'
@prog_scope()
def test_train(self):
train_feed = create(self.cfg['train_feed'])
......@@ -41,10 +44,35 @@ class TestDetectorFasterRCNN(unittest.TestCase):
@prog_scope()
def test_test(self):
test_feed = create(self.cfg['test_feed'])
test_feed = create(self.cfg['eval_feed'])
model = create(self.detector_type)
_, feed_vars = create_feeds(test_feed)
test_fetches = model.test(feed_vars)
test_fetches = model.eval(feed_vars)
class TestMaskRCNN(TestFasterRCNN):
def set_config(self):
self.cfg_file = 'configs/mask_rcnn_r50_1x.yml'
class TestCascadeRCNN(TestFasterRCNN):
def set_config(self):
self.cfg_file = 'configs/cascade_rcnn_r50_fpn_1x.yml'
class TestYolov3(TestFasterRCNN):
def set_config(self):
self.cfg_file = 'configs/yolov3_darknet.yml'
class TestRetinaNet(TestFasterRCNN):
def set_config(self):
self.cfg_file = 'configs/retinanet_r50_fpn_1x.yml'
class TestSSD(TestFasterRCNN):
def set_config(self):
self.cfg_file = 'configs/ssd_mobilenet_v1_voc.yml'
if __name__ == '__main__':
......
"""
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
import numpy as np
import paddle.fluid as fluid
from ppdet.modeling.tests.decorator_helper import prog_scope
from ppdet.core.config import load_cfg, merge_cfg
from ppdet.modeling.registry import Detectors
class TestDetectorCascadeRCNN(unittest.TestCase):
"""
CacadeRCNN's unit-test
"""
def setUp(self):
cfg_file = 'configs/debug_cascade-rcnn_ResNet50-FPN_1x.yml'
self.cfg = load_cfg(cfg_file)
self.detector_type = 'CascadeRCNN'
@prog_scope()
def test_train(self):
"""
test train process
"""
merge_cfg({'IS_TRAIN': True}, self.cfg)
assert self.cfg.IS_TRAIN
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.train()
#print(fluid.default_main_program())
#TODO(dangqingqing): add more check
@prog_scope()
def test_test(self):
"""
test infer process
"""
merge_cfg({'IS_TRAIN': False}, self.cfg)
assert not self.cfg.IS_TRAIN
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.test()
#TODO(dangqingqing): add more check
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
import numpy as np
import paddle.fluid as fluid
from ppdet.modeling.tests.decorator_helper import prog_scope
from ppdet.core.config import load_cfg, merge_cfg
from ppdet.modeling.registry import Detectors
class TestDetectorFasterRCNN(unittest.TestCase):
def setUp(self):
cfg_file = 'configs/mask-rcnn_ResNet50-C4_1x.yml'
self.cfg = load_cfg(cfg_file)
self.detector_type = 'MaskRCNN'
@prog_scope()
def test_train(self):
merge_cfg({'IS_TRAIN': True}, self.cfg)
assert self.cfg.IS_TRAIN
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.train()
#TODO(dangqingqing): add more check
@prog_scope()
def test_test(self):
merge_cfg({'IS_TRAIN': False}, self.cfg)
assert not self.cfg.IS_TRAIN
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.test()
#TODO(dangqingqing): add more check
if __name__ == '__main__':
unittest.main()
"""
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
# TODO(luoqianhui): change comment stype above in github
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
from ppdet.modeling.tests.decorator_helper import prog_scope
from ppdet.core.config import load_cfg, merge_cfg
from ppdet.modeling.registry import Detectors
class TestDetectorRetinaNet(unittest.TestCase):
"""
Test the detector: retinanet
"""
def setUp(self):
cfg_file = 'configs/retinanet_ResNet50-FPN_1x.yml'
self.cfg = load_cfg(cfg_file)
self.detector_type = 'RetinaNet'
@prog_scope()
def test_train(self):
"""
Test the training stage of retinanet
"""
merge_cfg({'IS_TRAIN': True}, self.cfg)
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.train()
# TODO(luoqianhui): add more check
@prog_scope()
def test_test(self):
"""
Test the testing stage of retinanet
"""
merge_cfg({'IS_TRAIN': False}, self.cfg)
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.test()
# TODO(luoqianhui): add more check
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
import numpy as np
import paddle.fluid as fluid
from ppdet.modeling.tests.decorator_helper import prog_scope
from ppdet.core.config import load_cfg, merge_cfg
from ppdet.modeling.registry import Detectors
class TestDetectorFasterRCNN(unittest.TestCase):
def setUp(self):
cfg_file = "configs/ssd_MobileNet_1x.yml"
self.cfg = load_cfg(cfg_file)
self.detector_type = 'SSD'
@prog_scope()
def test_train(self):
merge_cfg({'MODE': 'train'}, self.cfg)
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.train()
#TODO(sunyanfang): add more check
@prog_scope()
def test_val(self):
merge_cfg({'MODE': 'val'}, self.cfg)
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.val()
#TODO(sunyanfang): add more check
@prog_scope()
def test_val(self):
merge_cfg({'MODE': 'test'}, self.cfg)
self.detector = Detectors.get(self.detector_type)(self.cfg)
self.detector.test()
#TODO(sunyanfang): add more check
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import unittest
import numpy as np
import paddle.fluid as fluid
from ppdet.modeling.tests.decorator_helper import prog_scope
from ppdet.core.config import load_cfg, merge_cfg
from ppdet.modeling.registry import Detectors
class TestDetectorYOLOv3(unittest.TestCase):
def setUp(self):
cfg_file = 'configs/yolov3_DarkNet53_1x_syncbn.yml'
self.cfg = load_cfg(cfg_file)
self.detector_type = 'YOLOv3'
@prog_scope()
def test_train(self):
self.detector = Detectors.get(self.detector_type)(self.cfg)
loss = self.detector.train()
assert loss is not None
@prog_scope()
def test_test(self):
self.detector = Detectors.get(self.detector_type)(self.cfg)
pred = self.detector.test()
assert pred is not None
if __name__ == '__main__':
unittest.main()
......@@ -70,10 +70,7 @@ def main():
with fluid.program_guard(eval_prog, startup_prog):
with fluid.unique_name.guard():
pyreader, feed_vars = create_feeds(eval_feed)
if cfg['metric'] == 'COCO':
fetches = model.test(feed_vars)
else:
fetches = model.eval(feed_vars)
fetches = model.eval(feed_vars)
eval_prog = eval_prog.clone(True)
reader = create_reader(eval_feed)
......
......@@ -96,10 +96,7 @@ def main():
with fluid.program_guard(eval_prog, startup_prog):
with fluid.unique_name.guard():
eval_pyreader, feed_vars = create_feeds(eval_feed)
if cfg['metric'] == 'COCO':
fetches = model.test(feed_vars)
else:
fetches = model.eval(feed_vars)
fetches = model.eval(feed_vars)
eval_prog = eval_prog.clone(True)
eval_reader = create_reader(eval_feed)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册