-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathtest_conv2d.py
40 lines (26 loc) · 1016 Bytes
/
test_conv2d.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
import numpy as np
from numpy_impl import conv2d
from test_util import assert_matrix_eq
########################
# Numpy part #
########################
feature_n_prev = 3
input_feature_map = np.random.rand(2,feature_n_prev,2,2)
# shape: (2,3,2,2)
filters = np.random.rand(2,feature_n_prev,2,2)
numpy_output = conv2d(input_feature_map, filters)
print numpy_output
########################
# Theano part#
########################
import theano
input_feature_map_sym = theano.tensor.dtensor4("input_feature_map")
filters_sym = theano.tensor.dtensor4("filters")
f = theano.function(inputs = [input_feature_map_sym, filters_sym],
outputs = theano.tensor.nnet.conv.conv2d(input_feature_map_sym,
filters_sym,
border_mode = "full")
)
theano_output = f(input_feature_map, filters)
print theano_output
assert_matrix_eq(numpy_output, theano_output, "Conv2d")