<commit_before><commit_msg>fix test<commit_after>import numpy as np
import unittest

import chainer
from chainer import testing
from chainer.testing import attr

from chainercv.experimental.links import YOLOv2Tiny


@testing.parameterize(*testing.product({
    'n_fg_class': [1, 5, 20],
}))
class TestYOLOv2Tiny(unittest.TestCase):

    def setUp(self):
        self.link = YOLOv2Tiny(n_fg_class=self.n_fg_class)
        self.insize = 416
        self.n_bbox = 13 * 13 * 5

    def _check_call(self):
        x = self.link.xp.array(
            np.random.uniform(-1, 1, size=(1, 3, self.insize, self.insize)),
            dtype=np.float32)

        locs, objs, confs = self.link(x)

        self.assertIsInstance(locs, chainer.Variable)
        self.assertIsInstance(locs.array, self.link.xp.ndarray)
        self.assertEqual(locs.shape, (1, self.n_bbox, 4))

        self.assertIsInstance(objs, chainer.Variable)
        self.assertIsInstance(objs.array, self.link.xp.ndarray)
        self.assertEqual(objs.shape, (1, self.n_bbox))

        self.assertIsInstance(confs, chainer.Variable)
        self.assertIsInstance(confs.array, self.link.xp.ndarray)
        self.assertEqual(confs.shape, (1, self.n_bbox, self.n_fg_class))

    @attr.slow
    def test_call_cpu(self):
        self._check_call()

    @attr.gpu
    @attr.slow
    def test_call_gpu(self):
        self.link.to_gpu()
        self._check_call()


@testing.parameterize(*testing.product({
    'n_fg_class': [None, 10, 20],
    'pretrained_model': ['voc0712'],
}))
class TestYOLOv2TinyPretrained(unittest.TestCase):

    @attr.slow
    def test_pretrained(self):
        kwargs = {
            'n_fg_class': self.n_fg_class,
            'pretrained_model': self.pretrained_model,
        }

        if self.pretrained_model == 'voc0712':
            valid = self.n_fg_class in {None, 20}

        if valid:
            YOLOv2Tiny(**kwargs)
        else:
            with self.assertRaises(ValueError):
                YOLOv2Tiny(**kwargs)


testing.run_module(__name__, __file__)
{'fraction_non_alphanumeric': 0.12084148727984344, 'fraction_numerical': 0.02054794520547945, 'mean_word_length': 2.7522935779816513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4048129', 'n_tokens_mistral': 746, 'n_tokens_neox': 704, 'n_words': 120}