Previous topic

nnet – Ops related to neural networks

Next topic

nnet – Ops for neural networks

This Page

conv – Ops for convolutional neural nets

Note

Two similar implementation exists for conv2d:

The former implements a traditional 2D convolution, while the latter implements the convolutional layers present in convolutional neural networks (where filters are 3D and pool over several input channels).

TODO: Give examples for how to use these things! They are pretty complicated.

theano.tensor.nnet.conv.conv2d(input, filters, image_shape=None, filter_shape=None, border_mode='valid', subsample=(1, 1), **kargs)

This function will build the symbolic graph for convolving a stack of input images with a set of filters. The implementation is modelled after Convolutional Neural Networks (CNN). It is simply a wrapper to the ConvOp but provides a much cleaner interface.

Parameters:
  • input (symbolic 4D tensor) – mini-batch of feature map stacks, of shape image_shape.
  • filters (symbolic 4D tensor) – set of filters used in CNN layer of shape filter_shape
  • border_mode
    ‘valid’– only apply filter to complete patches of the image. Generates
    output of shape: image_shape - filter_shape + 1
    ‘full’ – zero-pads image to multiple of filter shape to generate output of
    shape: image_shape + filter_shape - 1
  • subsample (tuple of len 2) – factor by which to subsample the output
  • image_shape (tuple of len 4 of int or Constant variable) – (batch size, stack size, nb row, nb col) Optional, used for optimization.
  • filter_shape (tuple of len 4 of int or Constant variable) – (nb filters, stack size, nb row, nb col) Optional, used for optimization.
  • kwargs

    kwargs are passed onto ConvOp. Can be used to set the following: unroll_batch, unroll_kern, unroll_patch, openmp (see ConvOp doc)

    openmp: By default have the same value as
    config.openmp. For small image, filter, batch size, nkern and stack size, it can be faster to disable manually openmp. A fast and incomplete test show that with image size 6x6, filter size 4x4, batch size==1, n kern==1 and stack size==1, it is faster to disable it in valid mode. But if we grow the batch size to 10, it is faster with openmp on a core 2 duo.
Return type:

symbolic 4D tensor

Returns:

set of feature maps generated by convolutional layer. Tensor is of shape (batch size, nb filters, output row, output col)

theano.tensor.nnet.Conv3D.conv3D(cls, *args, **kwargs)

3D “convolution” of multiple filters on a minibatch (does not flip the kernel, moves kernel with a user specified stride)

Parameters:
  • V – Visible unit, input. dimensions: (batch, row, column, time, in channel)
  • W – Weights, filter. dimensions: (out channel, row, column, time ,in channel)
  • b – bias, shape == (W.shape[0],)
  • d – strides when moving the filter over the input(dx, dy, dt)
Note :

The order of dimensions do not correspond with the one in conv2d. This is for optimization.