-
Notifications
You must be signed in to change notification settings - Fork 86
/
test_numpy_convfoldpool.py
59 lines (47 loc) · 1.76 KB
/
test_numpy_convfoldpool.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
import theano
import numpy as np
from dcnn import ConvFoldingPoolLayer
from test_util import assert_matrix_eq
#########################
# NUMPY PART
#########################
filter_shape = (3, 2, 2, 2)
W = np.asarray(np.random.rand(3, 2, 2, 2),
dtype=theano.config.floatX)
b = np.asarray(np.random.rand(3),
dtype=theano.config.floatX)
k = 4
fold = False
np_layer = ConvFoldingPoolLayer(k = k,
fold = fold,
W = W,
b = b)
#########################
## THEANO PART
#########################
from dcnn_train import ConvFoldingPoolLayer as TheanoConvFoldingPoolLayer
x_symbol = theano.tensor.dtensor4('x')
layer = TheanoConvFoldingPoolLayer(rng = np.random.RandomState(1234),
input = x_symbol,
filter_shape = filter_shape,
k = k,
activation = "tanh",
norm_w = True,
fold = fold,
W = theano.shared(value = W,
borrow = True,
name="W"
),
b = theano.shared(value = b,
borrow = True,
name="b"
)
)
f = theano.function(inputs = [x_symbol],
outputs = layer.output)
########## Test ################
x = np.asarray(np.random.rand(2,2,3,3),
dtype=theano.config.floatX)
actual = np_layer.output(x)
expected = f(x)
assert_matrix_eq(actual, expected, "Conv")