Skip to content
This repository has been archived by the owner on Jul 2, 2021. It is now read-only.

FPN - Add min/max size params for pre-processing. #830

Merged
merged 8 commits into from
Mar 12, 2019
Merged
41 changes: 29 additions & 12 deletions tests/links_tests/model_tests/fpn_tests/test_faster_rcnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,35 @@ def __call__(self, x):

class DummyFasterRCNN(FasterRCNN):

def __init__(self, n_fg_class):
def __init__(self, n_fg_class, min_size, max_size):
extractor = DummyExtractor()
super(DummyFasterRCNN, self).__init__(
extractor=extractor,
rpn=RPN(extractor.scales),
head=Head(n_fg_class + 1, extractor.scales),
min_size=min_size, max_size=max_size,
)


@testing.parameterize(
{'n_fg_class': 1},
{'n_fg_class': 5},
{'n_fg_class': 20},
{'n_fg_class': 1, 'min_size': 200, 'max_size': 400,
'in_shape': (3, 200, 50), 'expected_shape': (3, 400, 100)},
{'n_fg_class': 1, 'min_size': 800, 'max_size': 133,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

133 is typo of 1333?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, a typo.

'in_shape': (3, 480, 640), 'expected_shape': (3, 800, 1088)},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prepare can accept a batch of images of different shapes.
How about 'in_sizes': [(480, 640), (320, 320)], 'expected_size': (800, 1088) ? (I omit 3 because it is not parameterized)

{'n_fg_class': 5, 'min_size': 200, 'max_size': 400,
'in_shape': (3, 200, 50), 'expected_shape': (3, 400, 100)},
{'n_fg_class': 5, 'min_size': 800, 'max_size': 133,
'in_shape': (3, 480, 640), 'expected_shape': (3, 800, 1088)},
{'n_fg_class': 20, 'min_size': 200, 'max_size': 400,
'in_shape': (3, 200, 50), 'expected_shape': (3, 400, 100)},
{'n_fg_class': 20, 'min_size': 800, 'max_size': 133,
'in_shape': (3, 480, 640), 'expected_shape': (3, 800, 1088)},
)
class TestFasterRCNN(unittest.TestCase):

def setUp(self):
self.link = DummyFasterRCNN(n_fg_class=self.n_fg_class)
self.link = DummyFasterRCNN(n_fg_class=self.n_fg_class,
min_size=self.min_size, max_size=self.max_size)

def test_use_preset(self):
self.link.nms_thresh = 0
Expand Down Expand Up @@ -117,13 +128,19 @@ def test_predict_gpu(self):
self.link.to_gpu()
assert_is_detection_link(self.link, self.n_fg_class)

def test_prepare(self):
imgs = [
np.random.randint(0, 255, size=(3, 480, 640)).astype(np.float32),
np.random.randint(0, 255, size=(3, 320, 320)).astype(np.float32),
]
x, scales = self.link.prepare(imgs)
self.assertEqual(x.shape, (2, 3, 800, 1088))
def check_prepare(self):
x = _random_array(np, self.in_shape)
out, scales = self.link.prepare(x)
self.assertIsInstance(out, np.ndarray)
self.assertEqual(out.shape, self.expected_shape)

def test_prepare_cpu(self):
self.check_prepare()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need to make _cpu/_gpu because prepare is not related cupy.


@attr.gpu
def test_prepare_gpu(self):
self.link.to_gpu()
self.check_prepare()


testing.run_module(__name__, __file__)