|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import absolute_import |
|
|
from __future__ import division |
|
|
from __future__ import print_function |
|
|
|
|
|
import os |
|
|
import unittest |
|
|
from ppdet.core.workspace import load_config |
|
|
from ppdet.engine import Trainer |
|
|
|
|
|
|
|
|
class TestMultiScaleInference(unittest.TestCase): |
|
|
def setUp(self): |
|
|
self.set_config() |
|
|
|
|
|
def set_config(self): |
|
|
self.mstest_cfg_file = 'configs/faster_rcnn/faster_rcnn_r34_fpn_multiscaletest_1x_coco.yml' |
|
|
|
|
|
|
|
|
def test_eval_mstest(self): |
|
|
cfg = load_config(self.mstest_cfg_file) |
|
|
trainer = Trainer(cfg, mode='eval') |
|
|
|
|
|
cfg.weights = 'https://paddledet.bj.bcebos.com/models/faster_rcnn_r34_fpn_1x_coco.pdparams' |
|
|
trainer.load_weights(cfg.weights) |
|
|
|
|
|
trainer.evaluate() |
|
|
|
|
|
|
|
|
def test_infer_mstest(self): |
|
|
cfg = load_config(self.mstest_cfg_file) |
|
|
trainer = Trainer(cfg, mode='test') |
|
|
|
|
|
cfg.weights = 'https://paddledet.bj.bcebos.com/models/faster_rcnn_r34_fpn_1x_coco.pdparams' |
|
|
trainer.load_weights(cfg.weights) |
|
|
tests_img_root = os.path.join(os.path.dirname(__file__), 'imgs') |
|
|
|
|
|
|
|
|
imgs = [ |
|
|
'coco2017_val2017_000000000139.jpg', |
|
|
'coco2017_val2017_000000000724.jpg' |
|
|
] |
|
|
imgs = [os.path.join(tests_img_root, img) for img in imgs] |
|
|
trainer.predict( |
|
|
imgs, draw_threshold=0.5, output_dir='output', save_results=False) |
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
unittest.main() |
|
|
|