def conv2d_grad(topgrad, output_shape, filters, border_mode, strides):
if (border_mode==BorderMode.same):
#'half' kernel width padding results in outputs of the same
#dimensions as input
border_mode=BorderMode.half
assert filters.shape[2]%2 == 1 and filters.shape[3]%2 == 1,\
"haven't handled even filter shapes for border mode 'half'"
op = T.nnet.abstract_conv.AbstractConv2d_gradInputs(
imshp=output_shape,
kshp=filters.shape,
subsample=strides,
border_mode=border_mode,
filter_flip=True)
topgrad=T.cast(topgrad, dtype=theano.config.floatX)
belowgrad = op(kern=filters, topgrad=topgrad, shape=output_shape[2:])
return belowgrad
评论列表
文章目录