提交 c45d0df4 authored 作者: gdesjardins's avatar gdesjardins

renamed conv.py to conv2d and changed interface slightly

上级 7f17dde5
...@@ -14,33 +14,49 @@ def getFilterOutShp(inshp, kshp, (dx,dy)=(1,1), mode='valid'): ...@@ -14,33 +14,49 @@ def getFilterOutShp(inshp, kshp, (dx,dy)=(1,1), mode='valid'):
N.array([dx,dy], dtype='float'))) N.array([dx,dy], dtype='float')))
def conv(border_mode, subsample=(1,1), imshp=None, kshp=None, **kargs): def conv2d(input, filters, border_mode='valid', subsample=(1,1),
image_shape=None, filter_shape=None, **kargs):
""" """
This fct return an instanciated ConvOp but give better name for some param. This fct return an instanciated ConvOp but give better name for some param.
We do this instead of changing the ConvOp interface to don't change all code We do this instead of changing the ConvOp interface to don't change all code
used up to now. used up to now.
:type input: symbolic 4D tensor
:param input: tensor containing mini-batch of input feature maps
:type filters: symbolic 4D tensor
:param filters: tensor containing filters for convolutional neural net
:type border_mode: string :type border_mode: string
:param border_mode:'valid'(only apply kernel over complete patch of the image) :param border_mode:'valid'(only apply kernel over complete patch of the image)
or 'full'(padd the image with 0 and apply the kernel over all full patch and partial patch of the image or 'full'(padd the image with 0 and apply the kernel over all full patch and partial patch of the image
:type subsample: tuple of len 2 :type subsample: tuple of len 2
:param subsample: how many pixel we move in the (row,col) direction of the image when we change of patch :param subsample: how many pixel we move in the (row,col) direction of the image when we change of patch
:type imshp: tuple of len 4 :type image_shape: tuple of len 4
:param imshp: (batch size, stack size, nb row, nb col) :param image_shape: (batch size, stack size, nb row, nb col)
:type kshp: tuple of len 4 :type filter_shape: tuple of len 4
:param kshp: (nb kernel, stack size, nb row, nb col) :param filter_shape: (nb kernel, stack size, nb row, nb col)
""" """
if imshp is not None and kshp is not None:
assert imshp[1]==kshp[1] if image_shape and filter_shape:
nkern = kshp[0] assert image_shape[1]==filter_shape[1]
bsize = imshp[0]
kshp = kshp[:2] if filter_shape is not None:
nkern = filter_shape[0]
kshp = filter_shape[2:]
else:
nkern, kshp = None, None
if image_shape is not None:
bsize = image_shape[0]
imshp = imshp[1:] imshp = imshp[1:]
else: else:
nkern, bsize = None, None bsize, imshp = None, None
return ConvOp(output_mode=border_mode, dx=subsample[0], dy=subsample[1],
imshp=imshp, kshp=kshp, nkern=nkern, bsize=bsize,**kargs) op = ConvOp(output_mode=border_mode, dx=subsample[0], dy=subsample[1],
imshp=imshp, kshp=kshp, nkern=nkern, bsize=bsize,**kargs)
return op(input, filters)
class ConvOp(Op): class ConvOp(Op):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论