forked from PlasmaControl/keras2c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pooling_layers.py
206 lines (187 loc) · 7.47 KB
/
test_pooling_layers.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
"""test_pooling_layers.py
This file is part of the test suite for keras2c
Implements tests for pooling layers
"""
#!/usr/bin/env python3
import unittest
import tensorflow.keras as keras
from keras2c import keras2c_main
import subprocess
import time
import os
from test_core_layers import build_and_run
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
__author__ = "Rory Conlin"
__copyright__ = "Copyright 2020, Rory Conlin"
__license__ = "MIT"
__maintainer__ = "Rory Conlin, https://github.com/f0uriest/keras2c"
__email__ = "wconlin@princeton.edu"
class TestPoolingLayers(unittest.TestCase):
"""tests for pooling layers"""
def test_MaxPooling1D1(self):
inshp = (23, 29)
pool_size = 3
strides = 2
padding = 'valid'
a = keras.layers.Input(inshp)
b = keras.layers.MaxPooling1D(pool_size=pool_size,
strides=strides,
padding=padding)(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___MaxPooling1D1' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_MaxPooling1D2(self):
inshp = (13, 19)
pool_size = 2
strides = 2
padding = 'same'
a = keras.layers.Input(inshp)
b = keras.layers.MaxPooling1D(pool_size=pool_size,
strides=strides,
padding=padding)(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___MaxPooling1D2' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_AveragePooling1D1(self):
inshp = (23, 29)
pool_size = 2
strides = 3
padding = 'valid'
a = keras.layers.Input(inshp)
b = keras.layers.AveragePooling1D(pool_size=pool_size,
strides=strides,
padding=padding)(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___AveragePooling1D1' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_AveragePooling1D2(self):
inshp = (13, 19)
pool_size = 3
strides = 1
padding = 'same'
a = keras.layers.Input(inshp)
b = keras.layers.AveragePooling1D(pool_size=pool_size,
strides=strides,
padding=padding)(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___AveragePooling1D2' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_MaxPooling2D1(self):
inshp = (23, 29, 7)
pool_size = (3, 2)
strides = (2, 1)
padding = 'valid'
a = keras.layers.Input(inshp)
b = keras.layers.MaxPooling2D(pool_size=pool_size,
strides=strides,
padding=padding)(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___MaxPooling2D1' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_MaxPooling2D2(self):
inshp = (13, 19, 4)
pool_size = (2, 4)
strides = (2, 3)
padding = 'same'
a = keras.layers.Input(inshp)
b = keras.layers.MaxPooling2D(pool_size=pool_size,
strides=strides,
padding=padding)(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___MaxPooling2D2' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_AveragePooling2D1(self):
inshp = (18, 25, 7)
pool_size = (2, 3)
strides = (2, 2)
padding = 'valid'
a = keras.layers.Input(inshp)
b = keras.layers.AveragePooling2D(pool_size=pool_size,
strides=strides,
padding=padding)(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___AveragePooling2D1' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_AveragePooling2D2(self):
inshp = (23, 29, 5)
pool_size = (2, 4)
strides = (3, 1)
padding = 'same'
a = keras.layers.Input(inshp)
b = keras.layers.AveragePooling2D(pool_size=pool_size,
strides=strides,
padding=padding)(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___AveragePooling2D2' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_GlobalAveragePooling1D(self):
inshp = (16, 11)
a = keras.layers.Input(inshp)
b = keras.layers.GlobalAveragePooling1D()(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___GlobalAveragePooling1D' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_GlobalMaxPooling1D(self):
inshp = (31, 21)
a = keras.layers.Input(inshp)
b = keras.layers.GlobalMaxPooling1D()(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___GlobalMaxPooling1D' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_GlobalAveragePooling2D(self):
inshp = (16, 11, 13)
a = keras.layers.Input(inshp)
b = keras.layers.GlobalAveragePooling2D()(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___GlobalAveragePooling2D' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_GlobalMaxPooling2D(self):
inshp = (31, 21, 5)
a = keras.layers.Input(inshp)
b = keras.layers.GlobalMaxPooling2D()(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___GlobalMaxPooling2D' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_GlobalAveragePooling3D(self):
inshp = (16, 11, 4, 5)
a = keras.layers.Input(inshp)
b = keras.layers.GlobalAveragePooling3D()(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___GlobalAveragePooling3D' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)
def test_GlobalMaxPooling3D(self):
inshp = (31, 21, 6, 7)
a = keras.layers.Input(inshp)
b = keras.layers.GlobalMaxPooling3D()(a)
model = keras.models.Model(inputs=a, outputs=b)
name = 'test___GlobalMaxPooling3D' + str(int(time.time()))
keras2c_main.k2c(model, name)
rcode = build_and_run(name)
self.assertEqual(rcode, 0)