Пример #1
0
def make_random_conv2D(irange, input_channels, input_axes, output_axes,
        output_channels,
        kernel_shape,
        kernel_stride = (1,1), pad=0, message = "", rng = None,
        partial_sum = None, sparse_init = None):
    """
    .. todo::

        WRITEME properly

    Creates a Conv2D with random kernels.
    Should be functionally equivalent to
    pylearn2.linear.conv2d.make_random_conv2D
    """

    if rng is None:
        rng = default_rng()

    W = sharedX( rng.uniform(-irange,irange,(input_channels, \
            kernel_shape[0], kernel_shape[1], output_channels)))

    return Conv2D(filters = W,
        input_axes = input_axes,
        output_axes = output_axes,
        kernel_stride = kernel_stride, pad=pad,
        message = message, partial_sum=partial_sum)
Пример #2
0
def make_random_conv2D(irange,
                       input_channels,
                       input_axes,
                       output_axes,
                       output_channels,
                       kernel_shape,
                       kernel_stride=(1, 1),
                       pad=0,
                       message="",
                       rng=None,
                       partial_sum=None):
    """ Creates a Conv2D with random kernels.
        Should be functionally equivalent to
        pylearn2.linear.conv2d.make_random_conv2D
    """

    if rng is None:
        rng = default_rng()

    W = sharedX( rng.uniform(-irange,irange,(input_channels, \
            kernel_shape[0], kernel_shape[1], output_channels)))

    return Conv2D(filters=W,
                  input_axes=input_axes,
                  output_axes=output_axes,
                  kernel_stride=kernel_stride,
                  pad=pad,
                  message=message,
                  partial_sum=partial_sum)
Пример #3
0
def make_random_conv3D(
    irange,
    input_axes,
    output_axes,
    signal_shape,
    filter_shape,
    kernel_stride=(1, 1),
    pad=0,
    message="",
    rng=None,
    partial_sum=None,
):
    """ Creates a Conv3D with random kernels.
    """

    if rng is None:
        rng = default_rng()

    _filter_4d_shape = (filter_shape[0], filter_shape[1], filter_shape[2], filter_shape[3] * filter_shape[4])

    W = sharedX(rng.uniform(-irange, irange, (_filter_4d_shape)))

    return Conv3DC01TB(
        filters=W,
        input_axes=input_axes,
        output_axes=output_axes,
        signal_shape=signal_shape,
        filter_shape=filter_shape,
        kernel_stride=kernel_stride,
        pad=pad,
        message=message,
        partial_sum=partial_sum,
    )
Пример #4
0
def make_random_conv3D(irange,
                       input_axes,
                       output_axes,
                       signal_shape,
                       filter_shape,
                       kernel_stride=(1, 1),
                       pad=0,
                       message="",
                       rng=None,
                       partial_sum=None):
    """ Creates a Conv3D with random kernels.
    """

    if rng is None:
        rng = default_rng()

    _filter_4d_shape = (filter_shape[0], filter_shape[1], filter_shape[2],
                        filter_shape[3] * filter_shape[4])

    W = sharedX(rng.uniform(-irange, irange, (_filter_4d_shape)))

    return Conv3DC01TB(filters=W,
                       input_axes=input_axes,
                       output_axes=output_axes,
                       signal_shape=signal_shape,
                       filter_shape=filter_shape,
                       kernel_stride=kernel_stride,
                       pad=pad,
                       message=message,
                       partial_sum=partial_sum)
Пример #5
0
def make_random_local(
    irange,
    input_channels,
    input_axes,
    input_groups,
    image_shape,
    output_channels,
    output_axes,
    kernel_shape,
    subsample=(1, 1),
    pad=0,
    message="",
    rng=None,
    partial_sum=None,
):
    """ Creates a Local with random weights.
    """

    if rng is None:
        rng = default_rng()

    def num_pos(img, stride, kwidth):
        img = img + 2 * pad
        return (img - kwidth) // stride + 1

    num_row_pos = num_pos(image_shape[0], subsample[0], kernel_shape[0])
    num_col_pos = num_pos(image_shape[1], subsample[1], kernel_shape[1])

    assert input_channels % input_groups == 0
    colors_per_group = input_channels // input_groups
    assert output_channels % input_groups == 0
    filters_per_group = output_channels // input_groups

    W = sharedX(
        rng.uniform(
            -irange,
            irange,
            (
                num_row_pos,
                num_col_pos,
                colors_per_group,
                kernel_shape[0],
                kernel_shape[1],
                input_groups,
                filters_per_group,
            ),
        )
    )

    return Local(
        filters=W,
        image_shape=image_shape,
        input_groups=input_groups,
        input_axes=input_axes,
        output_axes=output_axes,
        subsample=subsample,
        pad=pad,
        message=message,
        partial_sum=partial_sum,
    )
Пример #6
0
def make_random_conv2D(
    irange,
    input_channels,
    input_axes,
    output_axes,
    output_channels,
    kernel_shape,
    subsample=(1, 1),
    border_mode="valid",
    message="",
    rng=None,
):
    """ Creates a Conv2D with random kernels.
        Should be functionally equivalent to
        pylearn2.linear.conv2d.make_random_conv2D
    """

    if rng is None:
        rng = default_rng()

    W = sharedX(rng.uniform(-irange, irange, (input_channels, kernel_shape[0], kernel_shape[1], output_channels)))

    return Conv2D(
        filters=W,
        input_axes=input_axes,
        output_axes=output_axes,
        subsample=subsample,
        border_mode=border_mode,
        message=message,
    )
Пример #7
0
def make_random_local(irange,
                      input_channels,
                      input_axes,
                      input_groups,
                      image_shape,
                      output_channels,
                      output_axes,
                      kernel_shape,
                      kernel_stride=(1, 1),
                      pad=0,
                      message="",
                      rng=None,
                      partial_sum=None):
    """
    .. todo::

        WRITEME properly

    Creates a Local with random weights.
    """

    if rng is None:
        rng = default_rng()

    def num_pos(img, stride, kwidth):
        img = img + 2 * pad
        return (img - kwidth) // stride + 1

    num_row_pos = num_pos(image_shape[0], kernel_stride[0], kernel_shape[0])
    num_col_pos = num_pos(image_shape[1], kernel_stride[1], kernel_shape[1])

    assert input_channels % input_groups == 0
    colors_per_group = input_channels // input_groups
    assert output_channels % input_groups == 0
    filters_per_group = output_channels // input_groups

    W = sharedX(
        rng.uniform(
            -irange, irange,
            (num_row_pos, num_col_pos, colors_per_group, kernel_shape[0],
             kernel_shape[1], input_groups, filters_per_group)))

    return Local(filters=W,
                 image_shape=image_shape,
                 input_groups=input_groups,
                 input_axes=input_axes,
                 output_axes=output_axes,
                 kernel_stride=kernel_stride,
                 pad=pad,
                 message=message,
                 partial_sum=partial_sum)