예제 #1
0
    def test_variable_kernel_size(self):
        width = 32
        cv = networks.ConvChain(self.c, ksize=[3, 5, 3], depth=3, width=width)

        # Check sizes and children length is correct
        self.assertListEqual(list(cv.conv0.conv.weight.shape),
                             [width, self.c, 3, 3])
        self.assertListEqual(list(cv.conv1.conv.weight.shape),
                             [width, width, 5, 5])
        self.assertListEqual(list(cv.conv2.conv.weight.shape),
                             [width, width, 3, 3])
예제 #2
0
파일: models.py 프로젝트: sutkarsh/ttools
    def __init__(self, depth=2):
        super(BasicModel, self).__init__()

        assert depth > 1, "depth should be > 1"

        self.net = networks.ConvChain(3,
                                      width=16,
                                      ksize=3,
                                      depth=depth,
                                      activation='leaky_relu')
        self.regressor = networks.ConvModule(16, 3, ksize=1)
예제 #3
0
 def test_even_no_padding(self):
     w = 32
     k = 4
     depth = 2
     cv = networks.ConvChain(self.c,
                             depth=depth,
                             width=w,
                             ksize=k,
                             pad=False)
     out_ = cv(self.in_data)
     self.assertEqual(out_.shape[2], self.h - depth * (k - 1))
     self.assertEqual(out_.shape[3], self.w - depth * (k - 1))
예제 #4
0
    def test_normalization(self):
        w = 32
        k = 3
        cv = networks.ConvChain(self.c,
                                depth=4,
                                width=w,
                                ksize=k,
                                norm_layer="batch")
        self.assertEqual(len(list(cv.conv0.children())), 3)
        self.assertEqual(len(list(cv.conv1.children())), 3)
        self.assertEqual(len(list(cv.conv2.children())), 3)
        self.assertEqual(len(list(cv.conv3.children())), 3)

        self.assertIsNotNone(cv.conv0.norm)
        self.assertIsNotNone(cv.conv1.norm)
        self.assertIsNotNone(cv.conv2.norm)
        self.assertIsNotNone(cv.conv3.norm)
예제 #5
0
    def test_variable_width(self):
        # Width should have 3-1 = 2 values
        self.assertRaises(AssertionError,
                          networks.ConvChain,
                          self.c,
                          depth=3,
                          width=[12])

        k = 3
        cv = networks.ConvChain(self.c, ksize=k, depth=3, width=[12, 24, 21])

        # Check sizes and children length is correct
        self.assertListEqual(list(cv.conv0.conv.weight.shape),
                             [12, self.c, k, k])
        self.assertListEqual(list(cv.conv1.conv.weight.shape), [24, 12, k, k])
        self.assertListEqual(list(cv.conv2.conv.weight.shape), [21, 24, k, k])
        self.assertRaises(AttributeError, getattr, cv, "conv3")
        self.assertEqual(len(list(cv.children())), 3)
예제 #6
0
    def test_strided(self):
        k = 3
        # 3 strides should be passed
        self.assertRaises(AssertionError,
                          networks.ConvChain,
                          self.c,
                          ksize=k,
                          depth=3,
                          width=32,
                          strides=[1, 2])

        cv = networks.ConvChain(self.c,
                                ksize=k,
                                depth=3,
                                width=32,
                                strides=[1, 2, 2])

        # Check sizes and children length is correct
        self.assertEqual(cv.conv0.conv.stride[0], 1)
        self.assertEqual(cv.conv1.conv.stride[0], 2)
        self.assertEqual(cv.conv2.conv.stride[0], 2)
예제 #7
0
    def test_default(self):
        w = 32
        k = 3
        cv = networks.ConvChain(self.c, depth=5, width=w, ksize=k)

        self.assertListEqual(list(cv.conv0.conv.weight.shape),
                             [w, self.c, k, k])
        self.assertListEqual(list(cv.conv1.conv.weight.shape), [w, w, k, k])
        self.assertListEqual(list(cv.conv2.conv.weight.shape), [w, w, k, k])
        self.assertListEqual(list(cv.conv3.conv.weight.shape), [w, w, k, k])
        self.assertListEqual(list(cv.conv4.conv.weight.shape), [w, w, k, k])
        self.assertRaises(AttributeError, getattr, cv, "conv5")
        self.assertEqual(len(list(cv.children())), 5)

        self.assertEqual(len(list(cv.conv0.children())), 2)
        self.assertEqual(len(list(cv.conv1.children())), 2)
        self.assertEqual(len(list(cv.conv2.children())), 2)
        self.assertEqual(len(list(cv.conv3.children())), 2)
        self.assertEqual(len(list(cv.conv4.children())), 2)

        out_ = cv(self.in_data)
        self.assertListEqual(list(out_.shape), [self.bs, w, self.h, self.w])
예제 #8
0
 def test_output_activation(self):
     w = 32
     k = 3
     cv = networks.ConvChain(self.c, depth=5, width=w, ksize=k)
     self.assertEqual(len(list(cv.conv4.children())), 2)
예제 #9
0
 def test_even_padding(self):
     w = 32
     k = 4
     cv = networks.ConvChain(self.c, depth=3, width=w, ksize=k)
     out_ = cv(self.in_data)
     self.assertEqual(out_.shape[1], w)