Esempio n. 1
0
 def test_padding(self):
     inp = nplike(A([[[2, 3], [5, 7]], [[0.2, 0.3], [0.5, 0.7]]]))
     w = nplike(np.zeros((2, 2, 3, 3), dtype=theano.config.floatX))
     w[0, 0, 0, 0] = nplike(1.0)
     w[0, 0, 0, 2] = nplike(2.0)
     w[0, 0, 2, 0] = nplike(3.0)
     w[0, 0, 1, 1] = nplike(4.0)
     w[1, 0, 0, 0] = nplike(5.0)
     w[1, 0, 0, 2] = nplike(6.0)
     w[1, 0, 2, 0] = nplike(7.0)
     w[1, 0, 2, 2] = nplike(8.0)
     w[0, 1, 1, 1] = nplike(9.0)
     w[0, 1, 1, 2] = nplike(10.0)
     w[0, 1, 2, 1] = nplike(11.0)
     w[0, 1, 2, 2] = nplike(12.0)
     w[1, 1, 0, 0] = nplike(13.0)
     w[1, 1, 2, 0] = nplike(14.0)
     w[1, 1, 0, 1] = nplike(15.0)
     w[1, 1, 2, 1] = nplike(16.0)
     w_flipped = w[:, :, ::-1, ::-1]
     b = nplike(A([[[13]], [[23]]]))
     f_shp = (w.shape[0], w.shape[2], w.shape[3])
     res = a_conv(inp, inp.shape, w_flipped, f_shp, b, padding=(1, 1))
     array_almost_equal(
         res.eval(),
         A([[[39.7, 50.4], [50.5, 49.3]], [[87.0, 76.2], [44.0, 40.1]]]))
Esempio n. 2
0
 def test_1_channel_input_1_conv_feature(self):
     inp = nplike(A([[[0, 0], [2, 3]]]))
     w = nplike(A([[[[7, 5], [3, 2]]]]))
     b = nplike(A([4]))
     f_shp = (w.shape[0], w.shape[2], w.shape[3])
     res = a_conv(inp, inp.shape, w, f_shp, b)
     array_almost_equal(res.eval(), A([[[35]]]))
Esempio n. 3
0
 def test_trivial(self):
     inp = nplike(A([[[1]]]))
     w = nplike(A([[[[2]]]]))
     b = nplike(A([3]))
     f_shp = (w.shape[0], w.shape[2], w.shape[3])
     res = a_conv(inp, inp.shape, w, f_shp, b)
     array_almost_equal(res.eval(), A([[[5]]]))
Esempio n. 4
0
 def test_1_channel_input_1_conv_feature2(self):
     inp = nplike(np.zeros((1, 3, 3), dtype=theano.config.floatX))
     inp[0, 2, 1] = nplike(2)
     inp[0, 2, 2] = nplike(3)
     w = nplike([[[[7, 5], [3, 2]]]])
     b = nplike(A([4]))
     f_shp = (w.shape[0], w.shape[2], w.shape[3])
     res = a_conv(inp, inp.shape, w, f_shp, b)
     array_almost_equal(res.eval(), A([[[4, 4], [18, 35]]]))
Esempio n. 5
0
 def test_group_2_in_1_out(self):
     inp = nplike([[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[2, 3], [4, 5]],
                   [[6, 7], [8, 9]]])
     w = nplike([[[[1, 2], [3, 4]], [[5, 6], [7, 8]]],
                 [[[3, 4], [5, 6]], [[7, 8], [9, 1]]]])
     w_flipped = w[:, :, ::-1, ::-1]
     f_shp = (w.shape[0], w.shape[2], w.shape[3])
     b = nplike([[[0]]])
     res = a_conv(inp, inp.shape, w_flipped, f_shp, b, n_groups=2)
     array_almost_equal(res.eval(), A([[[204.0]], [[247.0]]]))
Esempio n. 6
0
 def test_group_1_in_2_out(self):
     inp = nplike([[[2, 3], [5, 7]], [[2, 3], [5, 7]]])
     w = nplike([[[[1, 2], [3, 4]]], [[[5, 6], [7, 8]]], [[[5, 6], [7, 8]]],
                 [[[1, 2], [3, 4]]]])
     w_flipped = w[:, :, ::-1, ::-1]
     f_shp = (w.shape[0], w.shape[2], w.shape[3])
     b = nplike([[[0]]])
     res = a_conv(inp, inp.shape, w_flipped, f_shp, b, n_groups=2)
     array_almost_equal(res.eval(),
                        A([[[51.0]], [[119.0]], [[119.0]], [[51.0]]]))
Esempio n. 7
0
 def test_stride(self):
     inp = nplike([[[2, 3], [5, 7]]])
     w = nplike([[[[1, 2], [3, 4]]]])
     w_flipped = w[:, :, ::-1, ::-1]
     f_shp = (w.shape[0], w.shape[2], w.shape[3])
     b = nplike([[[0]]])
     res = a_conv(inp,
                  inp.shape,
                  w_flipped,
                  f_shp,
                  b,
                  padding=(1, 1),
                  stride=(2, 2))
     array_almost_equal(res.eval(), A([[[8, 9], [10, 7]]]))