提交 e7964cbd authored 作者: Frederic Bastien's avatar Frederic Bastien

fix neighbours test and add speed test.

上级 5b976b3e
......@@ -41,32 +41,33 @@ def test_neibs_gpu():
f = function([], images2neibs(images,neib_shape),
mode=mode_with_gpu)
assert any([isinstance(node.op,GpuImages2Neibs) for node in f.maker.env.toposort()])
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.value
res1=[[[[ 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.]]]]
neibs = numpy.asarray(f())
numpy.allclose(neibs,res1)
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.value,g())
def speed_neibs():
shape = (100,40,18,18)
images = shared(numpy.arange(numpy.prod(shape), dtype='float32').reshape(shape))
neib_shape = T.as_tensor_variable((2,2))#(array((2,2), dtype='float32'))
from theano.sandbox.cuda.basic_ops import gpu_from_host
f = function([], images2neibs(images,neib_shape))#, mode=mode_without_gpu)
for i in range(1000):
f()
if __name__ == '__main__':
test_neibs_gpu()
test_neibs()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论