-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathtest_layers_deformable_convolution.py
60 lines (41 loc) · 1.92 KB
/
test_layers_deformable_convolution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import unittest
import tensorflow as tf
import tensorlayer as tl
from tensorlayer.layers import *
from tensorlayer.models import *
from tests.utils import CustomTestCase
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
class Layer_Convolution_2D_Test(CustomTestCase):
@classmethod
def setUpClass(cls):
print("\n#################################")
cls.batch_size = 5
cls.inputs_shape = [cls.batch_size, 10, 10, 16]
cls.input_layer = Input(cls.inputs_shape, name='input_layer')
cls.offset1 = tl.layers.Conv2d(n_filter=18, filter_size=(3, 3), strides=(1, 1), padding='SAME',
name='offset1')(cls.input_layer)
cls.deformconv1 = tl.layers.DeformableConv2d(
offset_layer=cls.offset1, n_filter=32, filter_size=(3, 3), act=tf.nn.relu, name='deformable1'
)(cls.input_layer)
cls.offset2 = tl.layers.Conv2d(n_filter=18, filter_size=(3, 3), strides=(1, 1), padding='SAME',
name='offset2')(cls.deformconv1)
cls.deformconv2 = tl.layers.DeformableConv2d(
offset_layer=cls.offset2, n_filter=64, filter_size=(3, 3), act=tf.nn.relu, name='deformable2'
)(cls.deformconv1)
cls.model = Model(cls.input_layer, cls.deformconv2)
print("Testing Deformable Conv2d model: \n", cls.model)
@classmethod
def tearDownClass(cls):
pass
def test_layer_n1(self):
self.assertEqual(len(self.deformconv1._info[0].layer.all_weights), 2)
self.assertEqual(self.deformconv1.get_shape().as_list()[1:], [10, 10, 32])
def test_layer_n2(self):
self.assertEqual(len(self.deformconv2._info[0].layer.all_weights), 2)
self.assertEqual(self.deformconv2.get_shape().as_list()[1:], [10, 10, 64])
if __name__ == '__main__':
tl.logging.set_verbosity(tl.logging.DEBUG)
unittest.main()