Layers

This module contains classes definitions for different types of layers.

lenet.layers.conv_2d_layer(input, neurons=20, filter_size=(5, 5), stride=(1, 1, 1, 1), padding='VALID', name='conv', activation='relu', visualize=False)[source][source]

Creates a convolution layer

Parameters:
  • input – (NHWC) Where is the input of the layer coming from
  • neurons – Number of neurons in the layer.
  • name – name scope of the layer
  • filter_size – A tuple of filter size (5,5) is default.
  • stride – A tuple of x and y axis strides. (1,1,1,1) is default.
  • name – A name for the scope of tensorflow
  • visualize – If True, will add to summary. Only for first layer at the moment.
  • activation – Activation for the outputs.
  • padding – Padding to be used in convolution. “VALID” is default.
Returns:

The output node and A list of parameters that are learnable

Return type:

tuple

lenet.layers.dot_product_layer(input, params=None, neurons=1200, name='fc', activation='relu')[source][source]

Creates a fully connected layer

Parameters:
  • input – Where is the input of the layer coming from
  • neurons – Number of neurons in the layer.
  • params – List of tensors, if supplied will use those params.
  • name – name scope of the layer
  • activation – What kind of activation to use.
Returns:

The output node and A list of parameters that are learnable

Return type:

tuple

lenet.layers.dropout_layer(input, prob, name='dropout')[source][source]

This layer drops out nodes with the probability of 0.5 During training time, run a probability of 0.5. During test time run a probability of 1.0. To do this, ensure that the prob is a tf.placeholder. You can supply this probability with feed_dict in trainer.

Parameters:
  • input – a 2D node.
  • prob – Probability feeder.
  • name – name scope of the layer.
Returns:

An output node

Return type:

tensorflow tensor

lenet.layers.flatten_layer(input, name='flatten')[source][source]

This layer returns the flattened output :param input: a 4D node. :param name: name scope of the layer.

Returns:a 2D node.
Return type:tensorflow tensor
lenet.layers.local_response_normalization_layer(input, name='lrn')[source][source]

This layer returns the flattened output

Parameters:
  • input – a 4D node.
  • name – name scope of the layer.
Returns:

a 2D node.

Return type:

tensorflow tensor

lenet.layers.max_pool_2d_layer(input, pool_size=(1, 2, 2, 1), stride=(1, 2, 2, 1), padding='VALID', name='pool')[source][source]

Creates a max pooling layer

Parameters:
  • input – (NHWC) Where is the input of the layer coming from
  • name – name scope of the layer
  • pool_size – A tuple of filter size (5,5) is default.
  • stride – A tuple of x and y axis strides. (1,1,1,1) is default.
  • name – A name for the scope of tensorflow
  • padding – Padding to be used in convolution. “VALID” is default.
Returns:

The output node

Return type:

tensorflow tensor

lenet.layers.softmax_layer(input, name='softmax')[source][source]

Creates the softmax normalization

Parameters:
  • input – Where is the input of the layer coming from
  • name – Name scope of the layer
Returns:

(softmax, prediction), A softmax output node and prediction output node

Return type:

tuple

lenet.layers.unflatten_layer(input, channels=1, name='unflatten')[source][source]

This layer returns the unflattened output :param input: a 2D node. :param chanels: How many channels are there in the image. (Default = 1) :param name: name scope of the layer.

Returns:a 4D node in (NHWC) format that is square in shape.
Return type:tensorflow tensor