@@ -0,0 +1,2583 @@
+import numpy as np%0Aimport unittest%0A%0Aimport chainer%0Afrom chainer.iterators import SerialIterator%0Afrom chainer import testing%0A%0Afrom chainercv.utils import apply_prediction_to_iterator%0A%0A%0A@testing.parameterize(*testing.product(%7B%0A    'multi_pred_values': %5BFalse, True%5D,%0A    'with_gt_values': %5BFalse, True%5D,%0A    'with_hook': %5BFalse, True%5D,%0A%7D))%0Aclass TestApplyDetectionLink(unittest.TestCase):%0A%0A    def test_apply_prediction_to_iterator(self):%0A        if self.multi_pred_values:%0A            def predict(imgs):%0A                n_img = len(imgs)%0A                return (%0A                    %5Bnp.random.uniform(size=(10, 4)) for _ in range(n_img)%5D,%0A                    %5Bnp.random.uniform(size=10) for _ in range(n_img)%5D,%0A                    %5Bnp.random.uniform(size=10) for _ in range(n_img)%5D)%0A%0A            n_pred_values = 3%0A        else:%0A            def predict(imgs):%0A                n_img = len(imgs)%0A                return %5Bnp.random.uniform(size=(48, 64)) for _ in range(n_img)%5D%0A%0A            n_pred_values = 1%0A%0A        imgs = list()%0A        for _ in range(5):%0A            H, W = np.random.randint(8, 16, size=2)%0A            imgs.append(np.random.randint(0, 256, size=(3, H, W)))%0A%0A        strs = %5B'a', 'bc', 'def', 'ghij', 'klmno'%5D%0A        nums = %5B0, 1, 2, 3, 4%5D%0A        arrays = %5Bnp.random.uniform(size=10) for _ in range(5)%5D%0A%0A        if self.with_gt_values:%0A            dataset = chainer.datasets.TupleDataset(%0A                imgs, strs, nums, arrays)%0A            n_gt_values = 3%0A        else:%0A            dataset = imgs%0A            n_gt_values = 0%0A        iterator = SerialIterator(dataset, 2, repeat=False, shuffle=False)%0A%0A        if self.with_hook:%0A            def hook(imgs, pred_values, gt_values):%0A                self.assertEqual(len(pred_values), n_pred_values)%0A                for pred_vals in pred_values:%0A                    self.assertEqual(len(pred_vals), len(imgs))%0A%0A                self.assertEqual(len(gt_values), n_gt_values)%0A                for gt_vals in gt_values:%0A                    self.assertEqual(len(gt_vals), len(imgs))%0A        else:%0A            hook = None%0A%0A        pred_values, gt_values = apply_prediction_to_iterator(%0A            predict, iterator, hook=hook)%0A%0A        self.assertEqual(len(pred_values), n_pred_values)%0A        for pred_vals in pred_values:%0A            self.assertEqual(len(list(pred_vals)), len(imgs))%0A%0A        self.assertEqual(len(gt_values), n_gt_values)%0A        for gt_vals, expected_gt_vals in zip(gt_values, (strs, nums, arrays)):%0A            self.assertEqual(list(gt_vals), expected_gt_vals)%0A%0A%0Atesting.run_module(__name__, __file__)%0A

add test