提交 a43a8425 authored 作者: Alexander Matyasko's avatar Alexander Matyasko

Add pool grad grad tests

上级 76aa8972
......@@ -2,21 +2,26 @@ from __future__ import absolute_import, print_function, division
from unittest import TestCase
from nose.plugins.skip import SkipTest
import itertools
import copy
import numpy
import theano
from theano import gradient
from theano import tensor
from theano.tests import unittest_tools as utt
from theano.tensor.blas import gemv_inplace, gemm_inplace, _dot22, batched_dot
from theano.tensor.tests.test_blas import TestGer, BaseGemv
from theano.tensor.signal.pool import Pool, DownsampleFactorMaxGradGrad
from .. import gpuarray_shared_constructor
from .config import mode_with_gpu
from .config import mode_with_gpu, mode_without_gpu
from .test_basic_ops import makeTester, rand
from ..blas import (gpugemv_inplace, gpugemv_no_inplace,
gpugemm_inplace, gpugemmbatch_no_inplace,
gpuger_inplace, gpuger_no_inplace,
GpuGer, gpu_dot22)
GpuGer, gpu_dot22, GpuDownsampleFactorMaxGradGrad)
GpuGemvTester = makeTester(
......@@ -128,3 +133,71 @@ GpuDot22Tester = makeTester(
# test9=[rand(0, 0), rand(0, 0)],
)
)
def test_downsample_max_grad_grad():
shps = [(1, 12),
(1, 1, 12),
(1, 1, 1, 12),
(1, 1, 2, 2),
(1, 1, 1, 1),
(1, 1, 4, 4),
(1, 1, 10, 11),
(1, 2, 2, 2),
(3, 5, 4, 4),
(25, 1, 7, 7),
(1, 1, 12, 12),
(1, 1, 2, 14),
(1, 1, 12, 14),
(1, 1, 14, 14),
(1, 1, 16, 16),
(1, 1, 18, 18),
(1, 1, 24, 24),
(1, 6, 24, 24),
(10, 1, 24, 24),
(10, 6, 24, 24),
(30, 6, 12, 12),
(30, 2, 24, 24),
(30, 6, 24, 24),
(10, 10, 10, 11),
(1, 1, 10, 1025),
(1, 1, 10, 1023),
(1, 1, 1025, 10),
(1, 1, 1023, 10), ]
numpy.random.RandomState(utt.fetch_seed()).shuffle(shps)
test_ds = (2, 2), (3, 2), (1, 1)
test_st = (2, 2), (3, 2), (1, 1)
for shp in shps:
for ds, st in itertools.product(test_ds, test_st):
if ds[0] > shp[-2]:
continue
if ds[1] > shp[-1]:
continue
for ignore_border in (True, False):
# print 'test_downsample', shp, ds, st, ignore_border
ds_op = Pool(ndim=len(ds), ignore_border=ignore_border)
a = theano.shared(rand(*shp), 'a')
ggf = gradient.Lop(tensor.grad((ds_op(
tensor.as_tensor_variable(a), ds, st)**2).sum(), a), a, a)
ref_mode = copy.copy(mode_without_gpu)
ref_mode.check_py_code = False
gpu_mode = copy.copy(mode_with_gpu)
gpu_mode.check_py_code = False
gg = theano.function([], ggf, mode=gpu_mode)
gg2 = theano.function([], ggf, mode=ref_mode)
assert any([
isinstance(node.op, GpuDownsampleFactorMaxGradGrad)
for node in gg.maker.fgraph.toposort()
])
assert any([
isinstance(node.op, DownsampleFactorMaxGradGrad)
for node in gg2.maker.fgraph.toposort()
])
assert numpy.allclose(gg(), gg2()), (shp, ds, st,
ignore_border)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论