forked from tensorlayer/TensorLayer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_layers_resampling.py
82 lines (56 loc) · 2.26 KB
/
test_layers_resampling.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import unittest
import tensorflow as tf
import tensorlayer as tl
from tensorlayer.layers import *
from tests.utils import CustomTestCase
sys.path.append("/home/wurundi/workspace/tensorlayer2")
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
class Layer_Pooling_Test(CustomTestCase):
@classmethod
def setUpClass(cls):
## 1D ========================================================================
## 2D ========================================================================
x_2_input_shape = [None, 100, 100, 3]
nin_2 = Input(x_2_input_shape)
n6 = tl.layers.Conv2d(n_filter=32, filter_size=(3, 3), strides=(2, 2), name='test_conv2d')(nin_2)
n7 = tl.layers.UpSampling2d(scale=(2, 2), name='test_UpSampling2d_1')(n6)
n8 = tl.layers.UpSampling2d(scale=3, name='test_UpSampling2d_2')(n6)
n9 = tl.layers.DownSampling2d(scale=(2, 2), name='test_DownSampling2d_1')(n6)
n10 = tl.layers.DownSampling2d(scale=5, name='test_DownSampling2d_2')(n6)
cls.n6_shape = n6.get_shape().as_list()
cls.n7_shape = n7.get_shape().as_list()
cls.n8_shape = n8.get_shape().as_list()
cls.n9_shape = n9.get_shape().as_list()
cls.n10_shape = n10.get_shape().as_list()
print("Printing UpSampling2d")
print(nin_2._info[0].layer)
print(n6._info[0].layer)
print(n7._info[0].layer)
print(n8._info[0].layer)
print(n9._info[0].layer)
print(n10._info[0].layer)
@classmethod
def tearDownClass(cls):
pass
# tf.reset_default_graph()
def test_UpSampling2d(self):
self.assertEqual(self.n7_shape[1:3], [100, 100])
self.assertEqual(self.n8_shape[1:3], [150, 150])
try:
layer = tl.layers.UpSampling2d(scale=(2, 2, 2))
except Exception as e:
print(e)
def test_DownSampling2d(self):
self.assertEqual(self.n9_shape[1:3], [25, 25])
self.assertEqual(self.n10_shape[1:3], [10, 10])
try:
layer = tl.layers.DownSampling2d(scale=(2, 2, 2))
except Exception as e:
print(e)
if __name__ == '__main__':
tl.logging.set_verbosity(tl.logging.DEBUG)
unittest.main()