コード例 #1
0
def test_neibs_gpu():
    if cuda.cuda_available == False:
        raise SkipTest('Optional package cuda disabled')
    for shape, pshape in [((100, 40, 18, 18), (2, 2)),
                          ((100, 40, 6, 18), (3, 2)),
                          ((10, 40, 66, 66), (33, 33)),
                          ((10, 40, 68, 66), (34, 33))
                          ]:

        images = shared(numpy.arange(numpy.prod(shape),
                                     dtype='float32').reshape(shape))
        neib_shape = T.as_tensor_variable(pshape)

        f = function([], images2neibs(images, neib_shape),
                     mode=mode_with_gpu)
        f_gpu = function([], images2neibs(images, neib_shape),
                     mode=mode_with_gpu)
        assert any([isinstance(node.op, GpuImages2Neibs)
                    for node in f_gpu.maker.env.toposort()])
        #print images.get_value(borrow=True)
        neibs = numpy.asarray(f_gpu())
        assert numpy.allclose(neibs, f())
        #print neibs
        g = function([], neibs2images(neibs, neib_shape, images.shape),
                     mode=mode_with_gpu)
        assert any([isinstance(node.op, GpuImages2Neibs)
                    for node in f.maker.env.toposort()])
        #print numpy.asarray(g())
        assert numpy.allclose(images.get_value(borrow=True), g())
コード例 #2
0
ファイル: test_neighbours.py プロジェクト: yarikoptic/Theano
    def test_neibs_manual(self):
        shape = (2, 3, 4, 4)
        for dtype in self.dtypes:
            images = shared(
                numpy.arange(numpy.prod(shape), dtype=dtype).reshape(shape))
            neib_shape = T.as_tensor_variable((2, 2))

            for border in ['valid', 'ignore_borders']:
                f = function([],
                             images2neibs(images, neib_shape, mode=border),
                             mode=self.mode)

                #print images.get_value(borrow=True)
                neibs = f()
                #print neibs
                assert numpy.allclose(
                    neibs,
                    [[0, 1, 4, 5], [2, 3, 6, 7], [8, 9, 12, 13],
                     [10, 11, 14, 15], [16, 17, 20, 21], [18, 19, 22, 23],
                     [24, 25, 28, 29], [26, 27, 30, 31], [32, 33, 36, 37],
                     [34, 35, 38, 39], [40, 41, 44, 45], [42, 43, 46, 47],
                     [48, 49, 52, 53], [50, 51, 54, 55], [56, 57, 60, 61],
                     [58, 59, 62, 63], [64, 65, 68, 69], [66, 67, 70, 71],
                     [72, 73, 76, 77], [74, 75, 78, 79], [80, 81, 84, 85],
                     [82, 83, 86, 87], [88, 89, 92, 93], [90, 91, 94, 95]])
                g = function([],
                             neibs2images(neibs, neib_shape, images.shape),
                             mode=self.mode)

                assert numpy.allclose(images.get_value(borrow=True), g())
コード例 #3
0
ファイル: test_neighbours.py プロジェクト: yarikoptic/Theano
    def test_neibs(self):
        for shape, pshape in [((10, 7, 18, 18), (2, 2)),
                              ((10, 7, 6, 18), (3, 2)),
                              ((5, 7, 66, 66), (33, 33)),
                              ((5, 7, 68, 66), (34, 33))]:
            for border in ['valid', 'ignore_borders']:
                for dtype in self.dtypes:
                    images = shared(
                        numpy.arange(numpy.prod(shape),
                                     dtype=dtype).reshape(shape))
                    neib_shape = T.as_tensor_variable(pshape)

                    f = function([],
                                 images2neibs(images, neib_shape, mode=border),
                                 mode=self.mode)

                    #print images.get_value(borrow=True)
                    neibs = f()
                    #print neibs
                    g = function([],
                                 neibs2images(neibs, neib_shape, images.shape),
                                 mode=self.mode)
                    if border in ['valid']:
                        assert any([
                            isinstance(node.op, self.op)
                            for node in f.maker.fgraph.toposort()
                        ])

                    #print g()
                    assert numpy.allclose(images.get_value(borrow=True), g())
コード例 #4
0
ファイル: test_neighbours.py プロジェクト: SinaHonari/Theano
    def test_neibs(self):
        for shape, pshape in [((100, 40, 18, 18), (2, 2)),
                              ((100, 40, 6, 18), (3, 2)),
                              ((10, 40, 66, 66), (33, 33)),
                              ((10, 40, 68, 66), (34, 33))
                                  ]:
            for border in ['valid', 'ignore_borders']:
                for dtype in self.dtypes:
                    images = shared(
                            numpy.arange(numpy.prod(shape), dtype=dtype
                            ).reshape(shape))
                    neib_shape = T.as_tensor_variable(pshape)

                    f = function([],
                                 images2neibs(images, neib_shape, mode=border),
                                 mode=self.mode)

                    #print images.get_value(borrow=True)
                    neibs = f()
                    #print neibs
                    g = function([],
                                 neibs2images(neibs, neib_shape, images.shape),
                                 mode=self.mode)
                    if border in ['valid']:
                        assert any([isinstance(node.op, self.op)
                                    for node in f.maker.fgraph.toposort()])

                    #print g()
                    assert numpy.allclose(images.get_value(borrow=True), g())
コード例 #5
0
def test_neibs_gpu():
    if cuda.cuda_available == False:
        raise SkipTest('Optional package cuda disabled')
    for shape, pshape in [((100, 40, 18, 18), (2, 2)),
                          ((100, 40, 6, 18), (3, 2)),
                          ((10, 40, 66, 66), (33, 33)),
                          ((10, 40, 68, 66), (34, 33))]:

        images = shared(
            numpy.arange(numpy.prod(shape), dtype='float32').reshape(shape))
        neib_shape = T.as_tensor_variable(pshape)

        f = function([], images2neibs(images, neib_shape), mode=mode_with_gpu)
        f_gpu = function([],
                         images2neibs(images, neib_shape),
                         mode=mode_with_gpu)
        assert any([
            isinstance(node.op, GpuImages2Neibs)
            for node in f_gpu.maker.env.toposort()
        ])
        #print images.get_value(borrow=True)
        neibs = numpy.asarray(f_gpu())
        assert numpy.allclose(neibs, f())
        #print neibs
        g = function([],
                     neibs2images(neibs, neib_shape, images.shape),
                     mode=mode_with_gpu)
        assert any([
            isinstance(node.op, GpuImages2Neibs)
            for node in f.maker.env.toposort()
        ])
        #print numpy.asarray(g())
        assert numpy.allclose(images.get_value(borrow=True), g())
コード例 #6
0
def tes_neibs2images_crash_on_grad():
    # say we had images of size (2, 3, 20, 20)
    # then we extracted 2x2 neighbors on this, we get (2 * 3 * 10 * 10, 4)
    neibs = T.dmatrix()
    neibs_val = numpy.random.rand(600, 4)
    to_images = T.sum(neibs2images(neibs, (2, 2), (2, 3, 20, 20)))
    g = T.grad(to_images, neibs)
    fn = theano.function([neibs], to_images, mode=mode_without_gpu)
    #print "Compiled"
    fn(neibs_val)
コード例 #7
0
def tes_neibs2images_crash_on_grad():
    # say we had images of size (2, 3, 20, 20)
    # then we extracted 2x2 neighbors on this, we get (2 * 3 * 10 * 10, 4)
    neibs = T.dmatrix()
    neibs_val = numpy.random.rand(600, 4)
    to_images = T.sum(neibs2images(neibs, (2, 2), (2, 3, 20, 20)))
    g = T.grad(to_images, neibs)
    fn = theano.function([neibs], to_images, mode=mode_without_gpu)
    print "Compiled"
    fn(neibs_val)
コード例 #8
0
ファイル: test_neighbours.py プロジェクト: glorotxa/Theano
def test_neibs():
    shape = (100,40,18,18)
    images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
    neib_shape = T.as_tensor_variable((2,2))#(array((2,2), dtype='float32'))

    f = function([], images2neibs(images, neib_shape), mode=mode_without_gpu)

    #print images.get_value(borrow=True)
    neibs = f()
    #print neibs
    g = function([], neibs2images(neibs, neib_shape, images.shape), mode=mode_without_gpu)

    #print g()
    assert numpy.allclose(images.get_value(borrow=True),g())
コード例 #9
0
def test_neibs():
    shape = (100, 40, 18, 18)
    images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
    neib_shape = T.as_tensor_variable((2, 2))

    f = function([], images2neibs(images, neib_shape), mode=mode_without_gpu)

    #print images.get_value(borrow=True)
    neibs = f()
    #print neibs
    g = function([],
                 neibs2images(neibs, neib_shape, images.shape),
                 mode=mode_without_gpu)

    #print g()
    assert numpy.allclose(images.get_value(borrow=True), g())
コード例 #10
0
ファイル: test_neighbours.py プロジェクト: AI-Cdrone/Theano
    def test_neibs_manual(self):
        shape = (2, 3, 4, 4)
        for dtype in self.dtypes:
            images = shared(
                    numpy.arange(numpy.prod(shape), dtype=dtype
                    ).reshape(shape))
            neib_shape = T.as_tensor_variable((2, 2))

            for border in ['valid', 'ignore_borders']:
                f = function([], images2neibs(images, neib_shape, mode=border),
                             mode=self.mode)
                assert any([isinstance(node.op, self.op)
                            for node in f.maker.fgraph.toposort()])

                #print images.get_value(borrow=True)
                neibs = f()
                #print neibs
                assert numpy.allclose(neibs,
                   [[ 0,  1,  4,  5],
                   [ 2,  3,  6,  7],
                   [ 8,  9, 12, 13],
                   [10, 11, 14, 15],
                   [16, 17, 20, 21],
                   [18, 19, 22, 23],
                   [24, 25, 28, 29],
                   [26, 27, 30, 31],
                   [32, 33, 36, 37],
                   [34, 35, 38, 39],
                   [40, 41, 44, 45],
                   [42, 43, 46, 47],
                   [48, 49, 52, 53],
                   [50, 51, 54, 55],
                   [56, 57, 60, 61],
                   [58, 59, 62, 63],
                   [64, 65, 68, 69],
                   [66, 67, 70, 71],
                   [72, 73, 76, 77],
                   [74, 75, 78, 79],
                   [80, 81, 84, 85],
                   [82, 83, 86, 87],
                   [88, 89, 92, 93],
                   [90, 91, 94, 95]])
                g = function([], neibs2images(neibs, neib_shape, images.shape),
                             mode=self.mode)

                assert numpy.allclose(images.get_value(borrow=True), g())
コード例 #11
0
def test_neibs_manual():
    shape = (2, 3, 4, 4)
    images = shared(numpy.arange(numpy.prod(shape)).reshape(shape))
    neib_shape = T.as_tensor_variable((2, 2))

    f = function([], images2neibs(images, neib_shape), mode=mode_without_gpu)

    #print images.get_value(borrow=True)
    neibs = f()
    #print neibs
    assert numpy.allclose(neibs,[[ 0,  1,  4,  5],
       [ 2,  3,  6,  7],
       [ 8,  9, 12, 13],
       [10, 11, 14, 15],
       [16, 17, 20, 21],
       [18, 19, 22, 23],
       [24, 25, 28, 29],
       [26, 27, 30, 31],
       [32, 33, 36, 37],
       [34, 35, 38, 39],
       [40, 41, 44, 45],
       [42, 43, 46, 47],
       [48, 49, 52, 53],
       [50, 51, 54, 55],
       [56, 57, 60, 61],
       [58, 59, 62, 63],
       [64, 65, 68, 69],
       [66, 67, 70, 71],
       [72, 73, 76, 77],
       [74, 75, 78, 79],
       [80, 81, 84, 85],
       [82, 83, 86, 87],
       [88, 89, 92, 93],
       [90, 91, 94, 95]])
    g = function([], neibs2images(neibs, neib_shape, images.shape),
                 mode=mode_without_gpu)

    #print g()
    assert numpy.allclose(images.get_value(borrow=True), g())
コード例 #12
0
ファイル: test_neighbours.py プロジェクト: yarikoptic/Theano
 def fn(neibs):
     return neibs2images(neibs, (2, 2), (2, 3, 10, 10))
コード例 #13
0
ファイル: test_neighbours.py プロジェクト: SinaHonari/Theano
 def fn(neibs):
     return neibs2images(neibs, (2, 2), (2, 3, 20, 20))
コード例 #14
0
ファイル: test_neighbours.py プロジェクト: AI-Cdrone/Theano
 def fn(neibs):
     return neibs2images(neibs, (2, 2), (2, 3, 10, 10))
コード例 #15
0
ファイル: test_neighbours.py プロジェクト: xinfanmeng/Theano
 def fn(neibs):
     return neibs2images(neibs, (2, 2), (2, 3, 20, 20))