提交 e12c29d8 authored 作者: Frederic's avatar Frederic

Fix equilibrium opt error recently introduced

上级 cd3979e5
......@@ -387,6 +387,19 @@ class Shape_i(gof.Op):
return [None]
def shape_i(var, i):
"""This is useful in optimization that need to get the shape. This
remove the need of the following shape_feature optimization that
convert it. So this speed up optimization and remove Equilibrium
max iteration problems.
"""
if (hasattr(var, 'fgraph') and
hasattr(node.outputs[0].fgraph, 'shape_feature')):
return node.outputs[0].fgraph.shape_feature.shape_of[var][i]
return Shape_i(i)(var)
def register_shape_i_c_code(typ, code, check_input, version=()):
""" Tell Shape_i how to generate C code for a Theano Type
......
......@@ -7,6 +7,7 @@ from theano.gradient import DisconnectedType
from theano.gof import Optimizer, local_optimizer, COp
from theano.gof.type import CDataType, Generic
from theano.compat import PY3
from theano.compile.ops import shape_i
from theano.tensor.nnet import SoftmaxGrad
from theano.tensor.basic import ShapeError
from theano.sandbox.cuda.type import CudaNdarrayType
......@@ -601,9 +602,10 @@ def dnn_conv(img, kerns, border_mode='valid', subsample=(1, 1),
img = gpu_contiguous(img)
kerns = gpu_contiguous(kerns.dimshuffle(1, 0, 2, 3))
conv_mode = 'cross' if conv_mode == 'conv' else 'conv'
shape = theano.tensor.stack(img.shape[0], kerns.shape[1],
img.shape[2] + kerns.shape[2] - 1,
img.shape[3] + kerns.shape[3] - 1)
shape = theano.tensor.stack(shape_i(img, 0), shape_i(kerns, 1),
shape_i(img, 2) + shape_i(kerns, 2) - 1,
shape_i(img, 3) + shape_i(kerns, 3)- 1)
desc = GpuDnnConvDesc(border_mode='valid', subsample=(1, 1),
conv_mode=conv_mode)(shape, kerns.shape)
return GpuDnnConvGradI()(kerns, img, desc, shape[2], shape[3])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论