提交 61a1c69f authored 作者: Frederic Bastien's avatar Frederic Bastien

crash fix. Fix gh-4929.

上级 5718f0b7
...@@ -1282,6 +1282,11 @@ def dnn_pool(img, ws, stride=(1, 1), mode='max', pad=(0, 0)): ...@@ -1282,6 +1282,11 @@ def dnn_pool(img, ws, stride=(1, 1), mode='max', pad=(0, 0)):
""" """
img = gpu_contiguous(img) img = gpu_contiguous(img)
if mode == "sum":
ret = GpuDnnPool(mode="average_inc_pad")(img, ws, stride, pad)
context_name = ret.type.context_name
window_elem = numpy.prod(ws).astype(ret.dtype)
return as_gpuarray_variable(ret * window_elem, context_name)
return GpuDnnPool(mode=mode)(img, ws, stride, pad) return GpuDnnPool(mode=mode)(img, ws, stride, pad)
......
...@@ -356,6 +356,18 @@ def test_pooling_opt(): ...@@ -356,6 +356,18 @@ def test_pooling_opt():
f(numpy.zeros((10, 10), dtype='float32')) f(numpy.zeros((10, 10), dtype='float32'))
# Test sum pooling
f = theano.function(
[x],
pool_2d(x, ds=(2, 3), mode='sum',
ignore_border=True),
mode=mode_with_gpu)
assert any([isinstance(n.op, dnn.GpuDnnPool)
for n in f.maker.fgraph.toposort()])
data = numpy.random.rand(10, 10).astype('float32')
f(data)
def test_dnn_tag(): def test_dnn_tag():
""" """
......
...@@ -2005,6 +2005,11 @@ def dnn_pool(img, ws, stride=(1, 1), mode='max', pad=(0, 0)): ...@@ -2005,6 +2005,11 @@ def dnn_pool(img, ws, stride=(1, 1), mode='max', pad=(0, 0)):
""" """
img = gpu_contiguous(img) img = gpu_contiguous(img)
if mode == "sum":
ret = GpuDnnPool(mode="average_inc_pad")(img, ws, stride, pad)
window_elem = numpy.prod(ws).astype(ret.dtype)
return as_cuda_ndarray_variable(ret * window_elem)
return GpuDnnPool(mode=mode)(img, ws, stride, pad) return GpuDnnPool(mode=mode)(img, ws, stride, pad)
......
...@@ -545,6 +545,17 @@ def test_pooling_opt(): ...@@ -545,6 +545,17 @@ def test_pooling_opt():
for n in f.maker.fgraph.toposort()]) for n in f.maker.fgraph.toposort()])
f(numpy.zeros((10, 10), dtype='float32')) f(numpy.zeros((10, 10), dtype='float32'))
# Test sum pooling
f = theano.function(
[x],
pool_2d(x, ds=(2, 3), mode='sum',
ignore_border=True),
mode=mode_with_gpu)
assert any([isinstance(n.op, dnn.GpuDnnPool)
for n in f.maker.fgraph.toposort()])
data = numpy.random.rand(10, 10).astype('float32')
f(data)
class test_DnnSoftMax(test_nnet.test_SoftMax): class test_DnnSoftMax(test_nnet.test_SoftMax):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论