示例#1
0
def test_weighted_pool():

    # TODO: test with different stride values

    rng = numpy.random.RandomState(220)

    for ds in [9, 2]:
        for batch in [1, 10]:
            for ch in [1, 16]:
                stride = ds
                data = rng.uniform(size=(batch, ds, ds, ch)).astype('float32')

                # op
                x = theano.tensor.tensor4()
                w_max = weighted_max_pool_c01b(x, (ds, ds), (stride, stride))
                f = theano.function([x], w_max, mode=mode_with_gpu)
                op_val = numpy.asarray(f(data))

                # python
                norm = data / data.sum(2).sum(1)[:, numpy.newaxis,
                                                 numpy.newaxis, :]
                py_val = (data * norm).sum(2).sum(1)[:, numpy.newaxis,
                                                     numpy.newaxis, :]

                assert numpy.allclose(op_val, py_val)
def test_weighted_pool():

    # TODO: test with different stride values

    rng = numpy.random.RandomState(220)

    for ds in [9, 2]:
        for batch in [1, 10]:
            for ch in [1, 16]:
                stride = ds
                data = rng.uniform(size=(batch, ds, ds, ch)).astype('float32')

                # op
                x = theano.tensor.tensor4()
                w_max = weighted_max_pool_c01b(x, (ds, ds), (stride, stride))
                f = theano.function([x], w_max, mode=mode_with_gpu)
                op_val = numpy.asarray(f(data))

                # python
                norm = data / data.sum(2).sum(1)[:,
                                                 numpy.newaxis,
                                                 numpy.newaxis, :]
                py_val = (data * norm).sum(2).sum(1)[:, numpy.newaxis,
                                                     numpy.newaxis, :]

                assert numpy.allclose(op_val, py_val)