提交 81f0f196 authored 作者: Alexander Matyasko's avatar Alexander Matyasko

Add tests for gpu max pooling rop

上级 877ad271
...@@ -8,13 +8,13 @@ import numpy ...@@ -8,13 +8,13 @@ import numpy
import theano import theano
from theano import gradient from theano import gradient
from theano import tensor from theano import tensor
from theano.tensor.signal.pool import (Pool, MaxPoolGrad, AveragePoolGrad, from theano.tensor.signal.pool import (Pool, MaxPoolGrad, AveragePoolGrad, MaxPoolRop,
DownsampleFactorMaxGradGrad) DownsampleFactorMaxGradGrad)
from theano.tests import unittest_tools as utt from theano.tests import unittest_tools as utt
from .config import mode_with_gpu, mode_without_gpu from .config import mode_with_gpu, mode_without_gpu
from .test_basic_ops import rand from .test_basic_ops import rand
from ..pool import (GpuPool, GpuMaxPoolGrad, GpuAveragePoolGrad, from ..pool import (GpuPool, GpuMaxPoolGrad, GpuAveragePoolGrad, GpuMaxPoolRop,
GpuDownsampleFactorMaxGradGrad) GpuDownsampleFactorMaxGradGrad)
...@@ -133,11 +133,26 @@ def test_pool2d(): ...@@ -133,11 +133,26 @@ def test_pool2d():
assert numpy.allclose(g(), g2()), (shp, ws, st, pad, mode, ignore_border) assert numpy.allclose(g(), g2()), (shp, ws, st, pad, mode, ignore_border)
# test grad grad for max pooling # test rop and grad grad for max pooling
# for average pooling grad grad is just average pooling grad # for average pooling grad grad is just average pooling grad
if mode != 'max': if mode != 'max':
continue continue
ea = theano.shared(rand(*shp), 'ea')
gr = theano.function([], tensor.Rop(a_pooled, a, ea), mode=gpu_mode)
gr2 = theano.function([], tensor.Rop(a_pooled, a, ea), mode=ref_mode)
assert any([
isinstance(node.op, GpuMaxPoolRop)
for node in gr.maker.fgraph.toposort()
])
assert any([
isinstance(node.op, MaxPoolRop)
for node in gr2.maker.fgraph.toposort()
])
assert numpy.allclose(gr(), gr2()), (shp, ws, st, pad, mode, ignore_border)
ggf = gradient.Lop(tensor.grad((a_pooled**2).sum(), a), a, a) ggf = gradient.Lop(tensor.grad((a_pooled**2).sum(), a), a, a)
gg = theano.function([], ggf, mode=gpu_mode) gg = theano.function([], ggf, mode=gpu_mode)
...@@ -228,11 +243,26 @@ def test_pool3d(): ...@@ -228,11 +243,26 @@ def test_pool3d():
assert numpy.allclose(g(), g2()), (shp, ws, st, pad, mode, ignore_border) assert numpy.allclose(g(), g2()), (shp, ws, st, pad, mode, ignore_border)
# test grad grad for max pooling # test rop and grad grad for max pooling
# for average pooling grad grad is just average pooling grad # for average pooling grad grad is just average pooling grad
if mode != 'max': if mode != 'max':
continue continue
ea = theano.shared(rand(*shp), 'ea')
gr = theano.function([], tensor.Rop(a_pooled, a, ea), mode=gpu_mode)
gr2 = theano.function([], tensor.Rop(a_pooled, a, ea), mode=ref_mode)
assert any([
isinstance(node.op, GpuMaxPoolRop)
for node in gr.maker.fgraph.toposort()
])
assert any([
isinstance(node.op, MaxPoolRop)
for node in gr2.maker.fgraph.toposort()
])
assert numpy.allclose(gr(), gr2()), (shp, ws, st, pad, mode, ignore_border)
ggf = gradient.Lop(tensor.grad((a_pooled**2).sum(), a), a, a) ggf = gradient.Lop(tensor.grad((a_pooled**2).sum(), a), a, a)
gg = theano.function([], ggf, mode=gpu_mode) gg = theano.function([], ggf, mode=gpu_mode)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论