neupy.layers.Softmax

class neupy.layers.Softmax[source]

Layer with the softmax activation function. It applies linear transformation when the n_units parameter specified and softmax function after the transformation. When n_units is not specified, only softmax function will be applied to the input.

Parameters:
n_units : int or None

Number of units in the layers. It also corresponds to the number of output features that will be produced per sample after passing it through this layer. The None value means that layer will not have parameters and it will only apply activation function to the input without linear transformation output for the specified input value. Defaults to None.

weight : array-like, Tensorfow variable, scalar or Initializer

Defines layer’s weights. Default initialization methods you can find here. Defaults to HeNormal().

bias : 1D array-like, Tensorfow variable, scalar, Initializer or None

Defines layer’s bias. Default initialization methods you can find here. Defaults to Constant(0). The None value excludes bias from the calculations and do not add it into parameters list.

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

Feedforward Neural Networks (FNN)

>>> from neupy.layers import *
>>> network = Input(10) >> Relu(20) >> Softmax(10)

Convolutional Neural Networks (CNN) for Semantic Segmentation

Softmax layer can be used in order to normalize probabilities per pixel. In the example below, we have as input 32x32 image with raw prediction per each pixel for 10 different classes. Softmax normalizes raw predictions per pixel to the probability distribution.

>>> from neupy.layers import *
>>> network = Input((32, 32, 10)) >> Softmax()
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.
activation_function(input) Applies activation function to the input.
activation_function(input_value)[source]
options = {'bias': Option(class_name='Linear', value=ParameterProperty(name="bias")), 'n_units': Option(class_name='Linear', value=IntProperty(name="n_units")), 'name': Option(class_name='BaseLayer', value=Property(name="name")), 'weight': Option(class_name='Linear', value=ParameterProperty(name="weight"))}[source]