neupy.layers.pooling module
- class neupy.layers.pooling.MaxPooling[source]
Maximum pooling layer.
Parameters: - size : tuple with 2 integers
Factor by which to downscale (vertical, horizontal). (2, 2) will halve the image in each dimension.
- stride : tuple or int.
Stride size, which is the number of shifts over rows/cols to get the next pool region. If stride is None, it is considered equal to size (no overlap on pooling regions).
- padding : {valid, same}
(pad_h, pad_w), pad zeros to extend beyond four borders of the images, pad_h is the size of the top and bottom margins, and pad_w is the size of the left and right margins.
- name : str or None
Layer’s name. Can be used as a reference to specific layer. Name Can be specified as:
- String: Specified name will be used as a direct reference to the layer. For example, name=”fc”
- Format string: Name pattern could be defined as a format string and specified field will be replaced with an index. For example, name=”fc{}” will be replaced with fc1, fc2 and so on. A bit more complex formatting methods are acceptable, for example, name=”fc-{:<03d}” will be converted to fc-001, fc-002, fc-003 and so on.
- None: When value specified as None than name will be generated from the class name.
Defaults to None.
Examples
2D pooling
>>> from neupy.layers import * >>> network = join( ... Input((10, 10, 3)), ... MaxPooling((2, 2)), ... ) >>> network (?, 10, 10, 3) -> [... 2 layers ...] -> (?, 5, 5, 3)
1D pooling
>>> from neupy.layers import * >>> network = join( ... Input((30, 10)), ... Reshape((30, 1, 10)), ... MaxPooling((2, 1)), ... Reshape((-1, 10)) ... ) >>> network (?, 30, 10) -> [... 4 layers ...] -> (?, 15, 10)
Attributes: - variables : dict
Variable names and their values. Dictionary can be empty in case if variables hasn’t been created yet.
Methods
variable(value, name, shape=None, trainable=True) Initializes variable with specified values. get_output_shape(input_shape) Computes expected output shape from the layer based on the specified input shape. output(*inputs, **kwargs) Propagates input through the layer. The kwargs variable might contain additional information that propagates through the network. - options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'padding': Option(class_name='BasePooling', value=ChoiceProperty(name="padding")), 'size': Option(class_name='BasePooling', value=TypedListProperty(name="size")), 'stride': Option(class_name='BasePooling', value=Spatial2DProperty(name="stride"))}[source]
- pooling_type = 'MAX'[source]
- class neupy.layers.pooling.AveragePooling[source]
Average pooling layer.
Parameters: - size : tuple with 2 integers
Factor by which to downscale (vertical, horizontal). (2, 2) will halve the image in each dimension.
- stride : tuple or int.
Stride size, which is the number of shifts over rows/cols to get the next pool region. If stride is None, it is considered equal to size (no overlap on pooling regions).
- padding : {valid, same}
(pad_h, pad_w), pad zeros to extend beyond four borders of the images, pad_h is the size of the top and bottom margins, and pad_w is the size of the left and right margins.
- name : str or None
Layer’s name. Can be used as a reference to specific layer. Name Can be specified as:
- String: Specified name will be used as a direct reference to the layer. For example, name=”fc”
- Format string: Name pattern could be defined as a format string and specified field will be replaced with an index. For example, name=”fc{}” will be replaced with fc1, fc2 and so on. A bit more complex formatting methods are acceptable, for example, name=”fc-{:<03d}” will be converted to fc-001, fc-002, fc-003 and so on.
- None: When value specified as None than name will be generated from the class name.
Defaults to None.
Examples
2D pooling
>>> from neupy.layers import * >>> network = join( ... Input((10, 10, 3)), ... AveragePooling((2, 2)), ... ) >>> network (?, 10, 10, 3) -> [... 2 layers ...] -> (?, 5, 5, 3)
1D pooling
>>> from neupy.layers import * >>> network = join( ... Input((30, 10)), ... Reshape((30, 1, 10)), ... AveragePooling((2, 1)), ... Reshape((-1, 10)) ... ) >>> network (?, 30, 10) -> [... 4 layers ...] -> (?, 15, 10)
Attributes: - variables : dict
Variable names and their values. Dictionary can be empty in case if variables hasn’t been created yet.
Methods
variable(value, name, shape=None, trainable=True) Initializes variable with specified values. get_output_shape(input_shape) Computes expected output shape from the layer based on the specified input shape. output(*inputs, **kwargs) Propagates input through the layer. The kwargs variable might contain additional information that propagates through the network. - options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'padding': Option(class_name='BasePooling', value=ChoiceProperty(name="padding")), 'size': Option(class_name='BasePooling', value=TypedListProperty(name="size")), 'stride': Option(class_name='BasePooling', value=Spatial2DProperty(name="stride"))}[source]
- pooling_type = 'AVG'[source]
- class neupy.layers.pooling.Upscale[source]
Upscales input over two axis (height and width).
Parameters: - scale : int or tuple with two int
Scaling factor for the input value. In the tuple first parameter identifies scale of the height and the second one of the width.
- name : str or None
Layer’s name. Can be used as a reference to specific layer. Name Can be specified as:
- String: Specified name will be used as a direct reference to the layer. For example, name=”fc”
- Format string: Name pattern could be defined as a format string and specified field will be replaced with an index. For example, name=”fc{}” will be replaced with fc1, fc2 and so on. A bit more complex formatting methods are acceptable, for example, name=”fc-{:<03d}” will be converted to fc-001, fc-002, fc-003 and so on.
- None: When value specified as None than name will be generated from the class name.
Defaults to None.
Examples
>>> from neupy.layers import * >>> network = Input((10, 10, 3)) >> Upscale((2, 2)) (?, 10, 10, 3) -> [... 2 layers ...] -> (?, 20, 20, 3)
Attributes: - variables : dict
Variable names and their values. Dictionary can be empty in case if variables hasn’t been created yet.
Methods
variable(value, name, shape=None, trainable=True) Initializes variable with specified values. get_output_shape(input_shape) Computes expected output shape from the layer based on the specified input shape. output(*inputs, **kwargs) Propagates input through the layer. The kwargs variable might contain additional information that propagates through the network. - fail_if_shape_invalid(input_shape)[source]
- get_output_shape(input_shape)[source]
- options = {'name': Option(class_name='BaseLayer', value=Property(name="name")), 'scale': Option(class_name='Upscale', value=TypedListProperty(name="scale"))}[source]
- output(input_value, **kwargs)[source]
- scale = None[source]
- class neupy.layers.pooling.GlobalPooling[source]
Global pooling layer.
Parameters: - function : {avg, max, sum} or callable
Common functions has been predefined for the user. These options are available:
- avg - For average global pooling. The same as tf.reduce_mean.
- max - For max global pooling. The same as tf.reduce_max.
- sum - For sum global pooling. The same as tf.reduce_sum.
Parameter also excepts custom functions that have following format.
def agg_func(x, axis=None): pass
Defaults to avg.
- name : str or None
Layer’s name. Can be used as a reference to specific layer. Name Can be specified as:
- String: Specified name will be used as a direct reference to the layer. For example, name=”fc”
- Format string: Name pattern could be defined as a format string and specified field will be replaced with an index. For example, name=”fc{}” will be replaced with fc1, fc2 and so on. A bit more complex formatting methods are acceptable, for example, name=”fc-{:<03d}” will be converted to fc-001, fc-002, fc-003 and so on.
- None: When value specified as None than name will be generated from the class name.
Defaults to None.
Examples
>>> from neupy.layers import * >>> network = Input((4, 4, 16)) >> GlobalPooling('avg') (?, 4, 4, 16) -> [... 2 layers ...] -> (?, 16)
Attributes: - variables : dict
Variable names and their values. Dictionary can be empty in case if variables hasn’t been created yet.
Methods
variable(value, name, shape=None, trainable=True) Initializes variable with specified values. get_output_shape(input_shape) Computes expected output shape from the layer based on the specified input shape. output(*inputs, **kwargs) Propagates input through the layer. The kwargs variable might contain additional information that propagates through the network. - function = None[source]
- get_output_shape(input_shape)[source]
- options = {'function': Option(class_name='GlobalPooling', value=FunctionWithOptionsProperty(name="function")), 'name': Option(class_name='BaseLayer', value=Property(name="name"))}[source]
- output(input_value, **kwargs)[source]