Completed
Pull Request — master (#946)
by Vincent
02:06
created

_push_allocation_config()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 4
rs 10
1
from theano import tensor
0 ignored issues
show
Unused Code introduced by
Unused tensor imported from theano
Loading history...
2
from theano.tensor.nnet import conv2d
3
from theano.tensor.nnet.abstract_conv import (AbstractConv2d_gradInputs,
4
                                              get_conv_output_shape)
5
from theano.tensor.signal.pool import pool_2d, Pool
6
7
from blocks.bricks import Initializable, Feedforward, Sequence
8
from blocks.bricks.base import application, Brick, lazy
9
from blocks.roles import add_role, FILTER, BIAS
10
from blocks.utils import shared_floatx_nans
11
12
13
class Convolutional(Initializable):
14
    """Performs a 2D convolution.
15
16
    Parameters
17
    ----------
18
    filter_size : tuple
19
        The height and width of the filter (also called *kernels*).
20
    num_filters : int
21
        Number of filters per channel.
22
    num_channels : int
23
        Number of input channels in the image. For the first layer this is
24
        normally 1 for grayscale images and 3 for color (RGB) images. For
25
        subsequent layers this is equal to the number of filters output by
26
        the previous convolutional layer. The filters are pooled over the
27
        channels.
28
    batch_size : int, optional
29
        Number of examples per batch. If given, this will be passed to
30
        Theano convolution operator, possibly resulting in faster
31
        execution.
32
    image_size : tuple, optional
33
        The height and width of the input (image or feature map). If given,
34
        this will be passed to the Theano convolution operator, resulting
35
        in possibly faster execution times.
36
    step : tuple, optional
37
        The step (or stride) with which to slide the filters over the
38
        image. Defaults to (1, 1).
39
    border_mode : {'valid', 'full'}, optional
40
        The border mode to use, see :func:`scipy.signal.convolve2d` for
41
        details. Defaults to 'valid'.
42
    tied_biases : bool
43
        If ``True``, it indicates that the biases of every filter in this
44
        layer should be shared amongst all applications of that filter.
45
        Setting this to ``False`` will untie the biases, yielding a
46
        separate bias for every location at which the filter is applied.
47
        Defaults to ``False``.
48
49
    """
50
    # Make it possible to override the implementation of conv2d that gets
51
    # used, i.e. to use theano.sandbox.cuda.dnn.dnn_conv directly in order
52
    # to leverage features not yet available in Theano's standard conv2d.
53
    # The function you override with here should accept at least the
54
    # input and the kernels as positionals, and the keyword arguments
55
    # image_shape, subsample, border_mode, and filter_shape. If some of
56
    # these are unsupported they should still be accepted and ignored,
57
    # e.g. with a wrapper function that swallows **kwargs.
58
    conv2d_impl = staticmethod(conv2d)
59
60
    # Used to override the output shape computation for a given value of
61
    # conv2d_impl. Should accept 4 positional arguments: the shape of an
62
    # image minibatch (with 4 elements: batch size, number of channels,
63
    # height, and width), the shape of the filter bank (number of filters,
64
    # number of output channels, filter height, filter width), the border
65
    # mode, and the step (vertical and horizontal strides). It is expected
66
    # to return a 4-tuple of (batch size, number of channels, output
67
    # height, output width). The first element of this tuple is not used
68
    # for anything by this brick.
69
    get_output_shape = staticmethod(get_conv_output_shape)
70
71
    @lazy(allocation=['filter_size', 'num_filters', 'num_channels'])
72
    def __init__(self, filter_size, num_filters, num_channels, batch_size=None,
73
                 image_size=(None, None), step=(1, 1), border_mode='valid',
74
                 tied_biases=False, **kwargs):
75
        super(Convolutional, self).__init__(**kwargs)
76
77
        self.filter_size = filter_size
78
        self.num_filters = num_filters
79
        self.batch_size = batch_size
80
        self.num_channels = num_channels
81
        self.image_size = image_size
82
        self.step = step
83
        self.border_mode = border_mode
84
        self.tied_biases = tied_biases
85
86
    def _allocate(self):
87
        W = shared_floatx_nans((self.num_filters, self.num_channels) +
88
                               self.filter_size, name='W')
89
        add_role(W, FILTER)
90
        self.parameters.append(W)
91
        self.add_auxiliary_variable(W.norm(2), name='W_norm')
92
        if self.use_bias:
93
            if self.tied_biases:
94
                b = shared_floatx_nans((self.num_filters,), name='b')
95
            else:
96
                # this error is raised here instead of during initializiation
97
                # because ConvolutionalSequence may specify the image size
98
                if self.image_size == (None, None) and not self.tied_biases:
99
                    raise ValueError('Cannot infer bias size without '
100
                                     'image_size specified. If you use '
101
                                     'variable image_size, you should use '
102
                                     'tied_biases=True.')
103
104
                b = shared_floatx_nans(self.get_dim('output'), name='b')
105
            add_role(b, BIAS)
106
107
            self.parameters.append(b)
108
            self.add_auxiliary_variable(b.norm(2), name='b_norm')
109
110
    def _initialize(self):
111
        if self.use_bias:
112
            W, b = self.parameters
0 ignored issues
show
Bug introduced by
The tuple unpacking with sequence defined at line 610 of blocks.bricks.base seems to be unbalanced; 2 value(s) for 0 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
113
            self.biases_init.initialize(b, self.rng)
114
        else:
115
            W, = self.parameters
0 ignored issues
show
Bug introduced by
The tuple unpacking with sequence defined at line 610 of blocks.bricks.base seems to be unbalanced; 1 value(s) for 0 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
116
        self.weights_init.initialize(W, self.rng)
117
118
    @application(inputs=['input_'], outputs=['output'])
119
    def apply(self, input_):
120
        """Perform the convolution.
121
122
        Parameters
123
        ----------
124
        input_ : :class:`~tensor.TensorVariable`
125
            A 4D tensor with the axes representing batch size, number of
126
            channels, image height, and image width.
127
128
        Returns
129
        -------
130
        output : :class:`~tensor.TensorVariable`
131
            A 4D tensor of filtered images (feature maps) with dimensions
132
            representing batch size, number of filters, feature map height,
133
            and feature map width.
134
135
            The height and width of the feature map depend on the border
136
            mode. For 'valid' it is ``image_size - filter_size + 1`` while
137
            for 'full' it is ``image_size + filter_size - 1``.
138
139
        """
140
        if self.use_bias:
141
            W, b = self.parameters
0 ignored issues
show
Bug introduced by
The tuple unpacking with sequence defined at line 610 of blocks.bricks.base seems to be unbalanced; 2 value(s) for 0 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
142
        else:
143
            W, = self.parameters
0 ignored issues
show
Bug introduced by
The tuple unpacking with sequence defined at line 610 of blocks.bricks.base seems to be unbalanced; 1 value(s) for 0 label(s)

This happens when the amount of values does not equal the amount of labels:

a, b = ("a", "b", "c")  # only 2 labels for 3 values
Loading history...
144
145
        if self.image_size == (None, None):
146
            image_shape = None
147
        else:
148
            image_shape = (self.batch_size, self.num_channels)
149
            image_shape += self.image_size
150
151
        output = self.conv2d_impl(
152
            input_, W,
153
            image_shape=image_shape,
154
            subsample=self.step,
155
            border_mode=self.border_mode,
156
            filter_shape=((self.num_filters, self.num_channels) +
157
                          self.filter_size))
158
        if self.use_bias:
159
            if self.tied_biases:
160
                output += b.dimshuffle('x', 0, 'x', 'x')
161
            else:
162
                output += b.dimshuffle('x', 0, 1, 2)
163
        return output
164
165
    def get_dim(self, name):
166
        if name == 'input_':
167
            return (self.num_channels,) + self.image_size
168
        if name == 'output':
169
            image_shape = (None, self.num_channels) + self.image_size
170
            kernel_shape = ((self.num_filters, self.num_channels) +
171
                            self.filter_size)
172
            out_shape = self.get_output_shape(image_shape, kernel_shape,
173
                                              self.border_mode, self.step)
174
            assert len(out_shape) == 4
175
            return out_shape[1:]
176
        return super(Convolutional, self).get_dim(name)
177
178
    @property
179
    def num_output_channels(self):
180
        return self.num_filters
181
182
183
class ConvolutionalTranspose(Convolutional):
184
    """Performs the transpose of a 2D convolution.
185
186
    Parameters
187
    ----------
188
    image_size : tuple, optional
189
        Required for tied biases. Defaults to ``None``.
190
    original_image_size : tuple
191
        The height and width of the output (image or feature map).
192
193
    See Also
194
    --------
195
    :class:`Convolutional` : For the documentation of other parameters.
196
197
    """
198
    @lazy(allocation=['filter_size', 'num_filters', 'num_channels',
199
                      'original_image_size'])
200
    def __init__(self, filter_size, num_filters, num_channels,
201
                 original_image_size, **kwargs):
202
        super(ConvolutionalTranspose, self).__init__(
203
            filter_size, num_filters, num_channels, **kwargs)
204
        self.original_image_size = original_image_size
205
206
    def conv2d_impl(self, input_, W, image_shape, subsample, border_mode,
0 ignored issues
show
Unused Code introduced by
The argument image_shape seems to be unused.
Loading history...
207
                    filter_shape):
208
        # The AbstractConv2d_gradInputs op takes a kernel that was used for the
209
        # **convolution**. We therefore have to invert num_channels and
210
        # num_filters for W.
211
        W = W.transpose(1, 0, 2, 3)
212
        imshp = (None,) + self.get_dim('output')
213
        kshp = (filter_shape[1], filter_shape[0]) + filter_shape[2:]
214
        return AbstractConv2d_gradInputs(
215
            imshp=imshp, kshp=kshp, border_mode=border_mode,
216
            subsample=subsample)(W, input_, self.get_dim('output')[1:])
217
218
    def get_dim(self, name):
219
        if name == 'output':
220
            return (self.num_filters,) + self.original_image_size
221
        return super(ConvolutionalTranspose, self).get_dim(name)
222
223
224
class Pooling(Initializable, Feedforward):
225
    """Base Brick for pooling operations.
226
227
    This should generally not be instantiated directly; see
228
    :class:`MaxPooling`.
229
230
    """
231
    @lazy(allocation=['mode', 'pooling_size'])
232
    def __init__(self, mode, pooling_size, step, input_dim, ignore_border,
233
                 padding, **kwargs):
234
        super(Pooling, self).__init__(**kwargs)
235
        self.pooling_size = pooling_size
236
        self.mode = mode
237
        self.step = step
238
        self.input_dim = input_dim if input_dim is not None else (None,) * 3
239
        self.ignore_border = ignore_border
240
        self.padding = padding
241
242
    @property
243
    def image_size(self):
244
        return self.input_dim[-2:]
245
246
    @image_size.setter
247
    def image_size(self, value):
248
        self.input_dim = self.input_dim[:-2] + value
249
250
    @property
251
    def num_channels(self):
252
        return self.input_dim[0]
253
254
    @num_channels.setter
255
    def num_channels(self, value):
256
        self.input_dim = (value,) + self.input_dim[1:]
257
258
    @application(inputs=['input_'], outputs=['output'])
259
    def apply(self, input_):
260
        """Apply the pooling (subsampling) transformation.
261
262
        Parameters
263
        ----------
264
        input_ : :class:`~tensor.TensorVariable`
265
            An tensor with dimension greater or equal to 2. The last two
266
            dimensions will be downsampled. For example, with images this
267
            means that the last two dimensions should represent the height
268
            and width of your image.
269
270
        Returns
271
        -------
272
        output : :class:`~tensor.TensorVariable`
273
            A tensor with the same number of dimensions as `input_`, but
274
            with the last two dimensions downsampled.
275
276
        """
277
        output = pool_2d(input_, self.pooling_size, st=self.step,
278
                         mode=self.mode, padding=self.padding,
279
                         ignore_border=self.ignore_border)
280
        return output
281
282
    def get_dim(self, name):
283
        if name == 'input_':
284
            return self.input_dim
285
        if name == 'output':
286
            return tuple(Pool.out_shape(
287
                self.input_dim, self.pooling_size, st=self.step,
288
                ignore_border=self.ignore_border, padding=self.padding))
289
290
    @property
291
    def num_output_channels(self):
292
        return self.input_dim[0]
293
294
295
class MaxPooling(Pooling):
296
    """Max pooling layer.
297
298
    Parameters
299
    ----------
300
    pooling_size : tuple
301
        The height and width of the pooling region i.e. this is the factor
302
        by which your input's last two dimensions will be downscaled.
303
    step : tuple, optional
304
        The vertical and horizontal shift (stride) between pooling regions.
305
        By default this is equal to `pooling_size`. Setting this to a lower
306
        number results in overlapping pooling regions.
307
    input_dim : tuple, optional
308
        A tuple of integers representing the shape of the input. The last
309
        two dimensions will be used to calculate the output dimension.
310
    padding : tuple, optional
311
        A tuple of integers representing the vertical and horizontal
312
        zero-padding to be applied to each of the top and bottom
313
        (vertical) and left and right (horizontal) edges. For example,
314
        an argument of (4, 3) will apply 4 pixels of padding to the
315
        top edge, 4 pixels of padding to the bottom edge, and 3 pixels
316
        each for the left and right edge. By default, no padding is
317
        performed.
318
    ignore_border : bool, optional
319
        Whether or not to do partial downsampling based on borders where
320
        the extent of the pooling region reaches beyond the edge of the
321
        image. If `True`, a (5, 5) image with (2, 2) pooling regions
322
        and (2, 2) step will be downsampled to shape (2, 2), otherwise
323
        it will be downsampled to (3, 3). `True` by default.
324
325
    Notes
326
    -----
327
    .. warning::
328
        As of this writing, setting `ignore_border` to `False` with a step
329
        not equal to the pooling size will force Theano to perform pooling
330
        computations on CPU rather than GPU, even if you have specified
331
        a GPU as your computation device. Additionally, Theano will only
332
        use [cuDNN]_ (if available) for pooling computations with
333
        `ignure_border` set to `True`. You can ensure that the entire
334
        input is captured by at least one pool by using the `padding`
335
        argument to add zero padding prior to pooling being performed.
336
337
    .. [cuDNN]: `NVIDIA cuDNN <https://developer.nvidia.com/cudnn>`_.
338
339
    """
340
    @lazy(allocation=['pooling_size'])
341
    def __init__(self, pooling_size, step=None, input_dim=None,
342
                 ignore_border=True, padding=(0, 0),
343
                 **kwargs):
344
        super(MaxPooling, self).__init__('max', pooling_size,
345
                                         step=step, input_dim=input_dim,
346
                                         ignore_border=ignore_border,
347
                                         padding=padding, **kwargs)
348
349
    def __setstate__(self, state):
350
        self.__dict__.update(state)
351
        # Fix objects created before pull request #899.
352
        self.mode = getattr(self, 'mode', 'max')
353
        self.padding = getattr(self, 'padding', (0, 0))
354
        self.ignore_border = getattr(self, 'ignore_border', False)
355
356
357
class AveragePooling(Pooling):
358
    """Average pooling layer.
359
360
    Parameters
361
    ----------
362
    include_padding : bool, optional
363
        When calculating an average, include zeros that are the
364
        result of zero padding added by the `padding` argument.
365
        A value of `True` is only accepted if `ignore_border`
366
        is also `True`. `False` by default.
367
368
    Notes
369
    -----
370
    For documentation on the remainder of the arguments to this
371
    class, see :class:`MaxPooling`.
372
373
    """
374
    @lazy(allocation=['pooling_size'])
375
    def __init__(self, pooling_size, step=None, input_dim=None,
376
                 ignore_border=True, padding=(0, 0),
377
                 include_padding=False, **kwargs):
378
        mode = 'average_inc_pad' if include_padding else 'average_exc_pad'
379
        super(AveragePooling, self).__init__(mode, pooling_size,
380
                                             step=step, input_dim=input_dim,
381
                                             ignore_border=ignore_border,
382
                                             padding=padding, **kwargs)
383
384
385
class _AllocationMixin(object):
386
    def _push_allocation_config(self):
387
        for attr in ['filter_size', 'num_filters', 'border_mode',
388
                     'batch_size', 'num_channels', 'image_size',
389
                     'tied_biases', 'use_bias']:
390
            setattr(self.convolution, attr, getattr(self, attr))
391
392
    @property
393
    def num_output_channels(self):
394
        # Assumes an elementwise activation function. Would need to
395
        # change to support e.g. maxout, but that would also require
396
        # a way of querying the activation function for this kind of
397
        # information.
398
        return self.num_filters
399
400
401
class ConvolutionalActivation(_AllocationMixin, Sequence, Initializable):
402
    """A convolution followed by an activation function.
403
404
    Parameters
405
    ----------
406
    activation : :class:`.BoundApplication`
407
        The application method to apply after convolution (i.e.
408
        the nonlinear activation function)
409
410
    See Also
411
    --------
412
    :class:`Convolutional` : For the documentation of other parameters.
413
414
    """
415
    @lazy(allocation=['filter_size', 'num_filters', 'num_channels'])
416
    def __init__(self, activation, filter_size, num_filters, num_channels,
417
                 batch_size=None, image_size=None, step=(1, 1),
418
                 border_mode='valid', tied_biases=False, **kwargs):
419
        self.convolution = Convolutional()
420
421
        self.filter_size = filter_size
422
        self.num_filters = num_filters
423
        self.num_channels = num_channels
424
        self.batch_size = batch_size
425
        self.image_size = image_size
426
        self.step = step
427
        self.border_mode = border_mode
428
        self.tied_biases = tied_biases
429
430
        super(ConvolutionalActivation, self).__init__(
431
            application_methods=[self.convolution.apply, activation],
432
            **kwargs)
433
434
    def get_dim(self, name):
435
        # TODO The name of the activation output doesn't need to be `output`
436
        return self.convolution.get_dim(name)
437
438
    def _push_allocation_config(self):
439
        super(ConvolutionalActivation, self)._push_allocation_config()
440
        self.convolution.step = self.step
441
442
443
class ConvolutionalTransposeActivation(_AllocationMixin, Sequence,
444
                                       Initializable):
445
    """A transposed convolution followed by an activation function.
446
447
    Parameters
448
    ----------
449
    activation : :class:`.BoundApplication`
450
        The application method to apply after convolution (i.e.
451
        the nonlinear activation function)
452
453
    See Also
454
    --------
455
    :class:`ConvolutionalTranspose` : For the documentation of other
456
    parameters.
457
458
    """
459
    @lazy(allocation=['filter_size', 'num_filters', 'num_channels',
460
                      'original_image_size'])
461
    def __init__(self, activation, filter_size, num_filters, num_channels,
462
                 original_image_size, batch_size=None, image_size=None,
463
                 step=(1, 1), border_mode='valid', tied_biases=False,
464
                 **kwargs):
465
        self.convolution = ConvolutionalTranspose()
466
467
        self.filter_size = filter_size
468
        self.num_filters = num_filters
469
        self.num_channels = num_channels
470
        self.batch_size = batch_size
471
        self.image_size = image_size
472
        self.original_image_size = original_image_size
473
        self.step = step
474
        self.border_mode = border_mode
475
        self.tied_biases = tied_biases
476
477
        super(ConvolutionalTransposeActivation, self).__init__(
478
            application_methods=[self.convolution.apply, activation],
479
            **kwargs)
480
481
    def get_dim(self, name):
482
        # TODO The name of the activation output doesn't need to be `output`
483
        return self.convolution.get_dim(name)
484
485
    def _push_allocation_config(self):
486
        super(ConvolutionalTransposeActivation, self)._push_allocation_config()
487
        self.convolution.step = self.step
488
        self.convolution.original_image_size = self.original_image_size
489
490
491
class ConvolutionalSequence(Sequence, Initializable, Feedforward):
492
    """A sequence of convolutional (or pooling) operations.
493
494
    Parameters
495
    ----------
496
    layers : list
497
        List of convolutional bricks (i.e. :class:`Convolutional`,
498
        :class:`ConvolutionalActivation`, or :class:`Pooling` bricks).
499
    num_channels : int
500
        Number of input channels in the image. For the first layer this is
501
        normally 1 for grayscale images and 3 for color (RGB) images. For
502
        subsequent layers this is equal to the number of filters output by
503
        the previous convolutional layer.
504
    batch_size : int, optional
505
        Number of images in batch. If given, will be passed to
506
        theano's convolution operator resulting in possibly faster
507
        execution.
508
    image_size : tuple, optional
509
        Width and height of the input (image/featuremap). If given,
510
        will be passed to theano's convolution operator resulting in
511
        possibly faster execution.
512
    border_mode : 'valid', 'full' or None, optional
513
        The border mode to use, see :func:`scipy.signal.convolve2d` for
514
        details. Unlike with :class:`Convolutional`, this defaults to
515
        None, in which case no default value is pushed down to child
516
        bricks at allocation time. Child bricks will in this case
517
        need to rely on either a default border mode (usually valid)
518
        or one provided at construction and/or after construction
519
        (but before allocation).
520
521
    Notes
522
    -----
523
    The passed convolutional operators should be 'lazy' constructed, that
524
    is, without specifying the batch_size, num_channels and image_size. The
525
    main feature of :class:`ConvolutionalSequence` is that it will set the
526
    input dimensions of a layer to the output dimensions of the previous
527
    layer by the :meth:`~.Brick.push_allocation_config` method.
528
529
    The reason the `border_mode` parameter behaves the way it does is that
530
    pushing a single default `border_mode` makes it very difficult to
531
    have child bricks with different border modes. Normally, such things
532
    would be overridden after `push_allocation_config()`, but this is
533
    a particular hassle as the border mode affects the allocation
534
    parameters of every subsequent child brick in the sequence. Thus, only
535
    an explicitly specified border mode will be pushed down the hierarchy.
536
537
    """
538
    @lazy(allocation=['num_channels'])
539
    def __init__(self, layers, num_channels, batch_size=None, image_size=None,
540
                 border_mode=None, tied_biases=False, **kwargs):
541
        self.layers = layers
542
        self.image_size = image_size
543
        self.num_channels = num_channels
544
        self.batch_size = batch_size
545
        self.border_mode = border_mode
546
        self.tied_biases = tied_biases
547
548
        application_methods = [brick.apply for brick in layers]
549
        super(ConvolutionalSequence, self).__init__(
550
            application_methods=application_methods, **kwargs)
551
552
    def get_dim(self, name):
553
        if name == 'input_':
554
            return ((self.num_channels,) + self.image_size)
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after return.
Loading history...
555
        if name == 'output':
556
            return self.layers[-1].get_dim(name)
557
        return super(ConvolutionalSequence, self).get_dim(name)
558
559
    def _push_allocation_config(self):
560
        num_channels = self.num_channels
561
        image_size = self.image_size
562
        for layer in self.layers:
563
            if self.border_mode is not None:
564
                layer.border_mode = self.border_mode
565
            layer.tied_biases = self.tied_biases
566
            layer.image_size = image_size
567
            layer.num_channels = num_channels
568
            layer.batch_size = self.batch_size
569
            layer.use_bias = self.use_bias
570
571
            # Push input dimensions to children
572
            layer._push_allocation_config()
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _push_allocation_config was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
573
574
            # Retrieve output dimensions
575
            # and set it for next layer
576
            if layer.image_size is not None:
577
                output_shape = layer.get_dim('output')
578
                image_size = output_shape[1:]
579
            num_channels = layer.num_output_channels
580
581
582
class Flattener(Brick):
583
    """Flattens the input.
584
585
    It may be used to pass multidimensional objects like images or feature
586
    maps of convolutional bricks into bricks which allow only two
587
    dimensional input (batch, features) like MLP.
588
589
    """
590
    @application(inputs=['input_'], outputs=['output'])
591
    def apply(self, input_):
592
        return input_.flatten(ndim=2)
593