def test_neg_output(self): inpl = theano_var([[[[1, 1], [1, 1]]]]) inpu = theano_var([[[[2, 2], [2, 2]]]]) iinp = TheanoInterval(inpl, inpu) idout = theano_interval([[[[-3]]]]) shp = (1, 1, 2, 2) din = d_pool(idout, iinp, shp, poolsize=(2, 2), mode='max') l, u = din.eval() array_almost_equal(l, A([[[[-3, -3], [-3, -3]]]])) array_almost_equal(u, A([[[[0, 0], [0, 0]]]]))
def test_channels_batch(self): inpl = theano_var([[ [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [3, 0, 0]] ], [ [[0, 3, 3], [4, 5, 6], [7, 8, 4]], [[-3, -3, -3], [-3, -3, -3], [3, 3, 3]] ]]) inpu = theano_var([[ [[1, 1, 1], [1, 1, 1], [1, 1, 1]], [[1, 1, 1], [1, 1, 1], [4, 1, 1]] ], [ [[2, 4, 4], [9, 9, 9], [9, 9, 9]], [[2, 2, 2], [2, 2, 2], [5, 5, 5]] ]]) iinp = TheanoInterval(inpl, inpu) doutl = theano_var([[ [[-1, -2], [-3, -4]], [[1, 2], [-3, -2]] ], [ [[1, 2], [-3, -2]], [[-1, 1], [-1, 1]] ]]) doutu = theano_var([[ [[5, 4], [3, 2]], [[4, 4], [4, 4]], ], [ [[4, 5], [0, 1]], [[0, 2], [0, 2]] ]]) idout = TheanoInterval(doutl, doutu) shp = (2, 2, 3, 3) din = d_pool(idout, iinp, shp, poolsize=(2, 2), mode='avg') l, u = din.eval() array_almost_equal(l, A([[ [[-1, -3, -2], [-4, -10, -6], [-3, -7, -4]], [[1, 3, 2], [-2, -2, 0], [-3, -5, -2]] ], [ [[1, 3, 2], [-2, -2, 0], [-3, -5, -2]], [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]] ]]) / 4.0) array_almost_equal(u, A([[ [[5, 9, 4], [8, 14, 6], [3, 5, 2]], [[4, 8, 4], [8, 16, 8], [4, 8, 4]] ], [ [[4, 9, 5], [4, 10, 6], [0, 1, 1]], [[0, 2, 2], [0, 4, 4], [0, 2, 2]] ]]) / 4.0)
def test_simple(self): inpl = theano_var([[[[0, 0, 0], [0, 0, 0], [0, 0, 0]]]]) inpu = theano_var([[[[1, 1, 1], [1, 1, 1], [1, 1, 1]]]]) iinp = TheanoInterval(inpl, inpu) doutl = theano_var([[[[-1, -2], [-3, -4]]]]) doutu = theano_var([[[[5, 4], [3, 2]]]]) idout = TheanoInterval(doutl, doutu) shp = (1, 1, 3, 3) din = d_pool(idout, iinp, shp, poolsize=(2, 2), mode='avg') l, u = din.eval() array_almost_equal(l, A([[[[-1, -3, -2], [-4, -10, -6], [-3, -7, -4]]]]) / 4.0) array_almost_equal(u, A([[[[5, 9, 4], [8, 14, 6], [3, 5, 2]]]]) / 4.0)
def test_padding(self): inpl = theano_var([[[[0, 0, 0], [0, 0, 0], [0, 0, 0]]]]) inpu = theano_var([[[[1, 1, 1], [1, 1, 1], [1, 1, 1]]]]) iinp = TheanoInterval(inpl, inpu) doutl = theano_var([[[[-1, -2], [-3, -4]]]]) doutu = theano_var([[[[5, 4], [3, 2]]]]) idout = TheanoInterval(doutl, doutu) shp = (1, 1, 3, 3) din = d_pool(idout, iinp, shp, poolsize=(2, 2), padding=(1, 1), stride=(3, 3), mode='max') l, u = din.eval() array_almost_equal(l, A([[[[-1, 0, -2], [0, 0, 0], [-3, 0, -4]]]])) array_almost_equal(u, A([[[[5, 0, 4], [0, 0, 0], [3, 0, 2]]]]))
def test_stride(self): tinpl = theano.shared(np.arange(25).reshape((1, 1, 5, 5))) tinpu = theano.shared(np.arange(25).reshape((1, 1, 5, 5)) + 2) iinp = TheanoInterval(tinpl, tinpu) idout = theano_interval([[[[-1, 2], [-3, 4]]]]) shp = (1, 1, 5, 5) din = d_pool(idout, iinp, shp, poolsize=(2, 2), stride=(3, 3), mode='avg') l, u = din.eval() array_almost_equal(l, A([[[[-1, -1, 0, 2, 2], [-1, -1, 0, 2, 2], [0, 0, 0, 0, 0], [-3, -3, 0, 4, 4], [-3, -3, 0, 4, 4]]]]) / 4.0) array_almost_equal(u, A([[[[-1, -1, 0, 2, 2], [-1, -1, 0, 2, 2], [0, 0, 0, 0, 0], [-3, -3, 0, 4, 4], [-3, -3, 0, 4, 4]]]]) / 4.0)