Keras deep learning framework and method parameters

Keras is python based Theano, CNTK as the calculation of the background depth study modeling environment, relative to other depths learning framework, such as tensorflow, theano, Caffe etc., Keras with its significant advantages, such as support CNN, RNN algorithms . Greatly accelerate the speed of development. This paper describes the relevant parameters of Keras.

The core layer

  1. Fully connected layers: the most commonly used neural network to achieve activation of the neural network neurons.
keras.layers.core.Dense(output_dim, init='glorot_uniform', activation='linear', weights=None, W_regularizer=None, b_regularizer=None, activity_regularizer=None, W_constraint=None, b_constraint=None, bias=True, input_dim=None)
  • output_dim: integer greater than 0, a dimension representing the output layer, fully connected model layer is too fat layer which can be input automatically infer dimension, thus defining a non-fully-connected first floor designation input is not required dimension.
  • init: initialization method for initializing a predetermined string method name-defined, or a heavy weight Theano initialization function. This parameter is meaningful only when the weights do not pass parameters.
  • activation: activation function, activation of a predefined function name, or element by element (element-wise) of Theano function. If not specified, the function will not use any active (i.e. using a linear activation function: a (x) = x).
  • weights: weights for numpy array of list. The list should contain a form such as (input_dim, output_dim) weight matrix and a bias vector of the form (output_dim,) of.
  • W_regularizer: applying a regular item on the weights, as WeightRegularizer object.
  • b_regularizer: applying a positive bias on the items in the vector, as WeightRegularizer object.
  • activity_regularizer: applying a regularization term in the output of ActivityRegularizer object.
  • W_constraints: constraints imposed on the entry of the weights for the Constraints object.
  • b_constraints: the bias applied to the constraint item, the object of Constraints.
  • bias: Boolean, it contains the offset vector (i.e., an input layer linear transformation or affine transformation).
  • input_dim: integer, the dimension of the input data. When Dense layer as a first layer of the network, must be specified parameter or parameters input_shape.
  1. Activation layer of
    the active layer to the output layer is a false activation function.
keras.layers.core.Activation(activation)
  • activation: the activation function to be used for activating predefined function name or a Tensorflow / Theano function.
  1. Dropout layer
    is applied as input data Dropout. Dropout will disconnect randomly each time when updating the training process parameters § certain proportion of input neurons connected, Dropout layer serves to prevent over-fitting.
keras.layer.core.Dropout(p)
  • p: 0-1 floating-point number, controlling the ratio of the need to disconnect the connection.
  1. Flatten layer
    Flatten the input layer used to compress, i.e., the plurality of one-dimensional input, the transition from conventional to full convolution layer connection layer. Flatten not affect the size of the batch.
keras.layer.core.Flatten()
  1. Reshape layer
    Reshape layer serves to convert an input to a specific shape shape
keras.layer.core.Reshape(target_shape)
  • target_shape: target shape, is an integer tuple, it does not include the number of samples dimensions (size BATCH)
  1. Convolution layer
    convolution operation can be divided into one, two, three, respectively Conv1D, Conv2D, Conv3D. Convolution is mainly applied to a one-dimensional time series data or text data, two-dimensional data is typically applied to the image data. Because of these three parameters and use basically the same, it is mainly in the two-dimensional Conv2D explained.
  • Convolution2D layer
    two-dimensional convolution of the two-dimensional input layer convolution sliding window, when the layer is used as a first layer, it should be provided input_shape parameters. E.g. input_shape = (3,128,128) on behalf of a color RGB image of 128 * 128.
keras.layers.convolutional.Convolution2D(nb_filter, nb_row, nb_col, init='glorot_uniform', activation='linear', weights=None, border_mode='valid', subsample=(1, 1), dim_ordering='th', W_regularizer=None, b_regularizer=None, activity_regularizer=None, W_constraint=None, b_constraint=None, bias=True)
  • nb_filter: The number of convolution kernel.
  • nb_row: The number of rows convolution kernel.
  • nb_col: the number of columns convolution kernel.
  • border_mode: boundary mode, as "valid" or "same"
  • subsample: length of tuple 2, the output of the input sampling factors, are more commonly called "strides".
  • dim_ordering: 'th' or 'tf'. 'Th' mode channel dimensions (e.g., three-channel color images) located at the first position (dimensions from zero count), while 'tf' mode, the channel dimension is third position. For example, 128 * 128 three-channel color images, in the 'th' mode input_shape should be written as (3,128,128), while 'tf' mode should be written as (128,128,3), note that there appears 3 in the 0 position, because the number of dimensions is not included input_shape samples in its internal implementation is actually (None, 3,128,128), and (None, 128,128,3). The default mode is designated image_dim_ordering, viewable in ~ / .keras / keras.json, if compared not set the 'tf'.
  • Deconvolution2D layer
    This layer is the transpose of the convolution operation (deconvolution). If necessary deconvolution usually occurs when the user wants to make the results of a general convolution transformation in the opposite direction. For example, having the shape of the convolution output tensor conversion layer having a shape tensor convolution of the input layer. While retaining compatibility with the convolution layer connection mode.
keras.layers.convolutional.Deconvolution2D(nb_filter, nb_row, nb_col, output_shape, init='glorot_uniform', activation='linear', weights=None, border_mode='valid', subsample=(1, 1), dim_ordering='tf', W_regularizer=None, b_regularizer=None, activity_regularizer=None, W_constraint=None, b_constraint=None, bias=True)
  • output_shape: Shape output deconvolution, a tuple of integers, the form (nb_samples, nb_filter, nb_output_rows, nb_output_cols ), calculated output_shape formula is: o = s (i - 1 ) + a + k - 2p, where a is the value range is 0 ~ s-1, where:
       I: the input size (rows or cols)
       K: the size of the convolution kernel (nb_filter)
       s: step (subsample)
       a: the difference specified by the user for different s the possible output size parameter
  1. Cell layer
    and the layer as a convolution, maximum and average statistic pool statistics there are three types of cell, respectively MaxPooling1D, MaxPooling2D, MaxPooling3D and AveragePooling1D, AveragePooling2D, AveragePooling3D, and the use of essentially the same parameters, it is mainly for MaxPooling2D instructions.
  • MaxPooling2D layer
    is applied to the maximum value of the signal spatial pooling.
keras.layers.convolutional.MaxPooling2D(pool_size=(2, 2), strides=None, border_mode='valid', dim_ordering='th')
  • pool_size: Long integer of tuple 2, representing downsampling factor in two directions (vertical, horizontal), taken as (2,2) image in two dimensions will both become half of the original length.
  • strides: length of integer tuple 2, or None, step value.
  1. BatchNormalization layer
    This layer activation value of one renormalization before each batch will, even obtaining average output data approaches zero, the standard deviation close to one.
keras.layers.convolutional.MaxPooling2D(pool_size=(2, 2), strides=None, border_mode='valid', dim_ordering='th')
  • epsilon: 0 is greater than a small float for preventing division by zero.

  • mode: integer specifying standardized pattern, 0 or 1:

    0: characterized by standardized, various features of an input will be normalized independently. Standardization axis specified by the parameter axis. Note that, if the input is of the form (samples, channels, rows, cols) tensor 4D image, should be provided for the standardization of the shaft 1, i.e., along the channel axis normalization. Input format is 'tf' empathy.

    1: normalized to sample, the default input mode to 2D.

  • axis: integer specifying when mode = 0 when normalized axis. For example, the form is input (samples, channels, rows, cols) tensor of the 4D image, the shaft should be normalized to set 1, meant to be standardized for each feature in FIG.

  • momentum: When normalized by feature, the momentum when the index calculated mean and standard deviation of the data.

  • weights: Initialization weight of list contains two numpy array, which shape is [(input_shape,), (input_shape)].

  • beta_init: beta initialization method, the predetermined character string is the name-defined initialization method, or for re-initialization function Theano weight. This parameter is only relevant if the parameter is not passed weights.

  • gamma_init: gamma initialization method for initializing a predetermined string method name-defined, or a heavy weight Theano initialization function. This parameter is only relevant if the parameter is not passed weights.

  1. Cyclical layer
    recurrent neural network RNN, LSTM GRU and inherit this layer, the parameters of the parent class is also used in the corresponding subclass SimpleRNN, LSTM and GRU.
Recurrent(return_sequences=False)
  • return_sequences: Returns the control type of the last output sequence returns output "False", "True" is returned entire sequence. When we want to build a multilayer neural network (such as deep LSTM), if it is the last layer, you need to set this parameter to True.
  1. Buried layer
    of the layer model can only be used in a first layer, reference indexes are all mapped to the sparse dense low-dimensional matrix. When we treated as text data, we number after each word, we want to word number word vector becomes embedded layer can be used.
Embedding(input_dim, output_dim, input_length)
  • input_dim: an integer greater than or equal to 0, i.e., the length of the dictionary number of the input data.
  • output_dim: output dimension as the dimension of the term vectors.
  • input_length: when the length of the input sequence that is a fixed length, and then to add the Flatten layer after layer, and then combined with Dense layer, this parameter must be specified otherwise Dense layer can not be automatically inferred dimension output.

This layer may be a bit difficult to understand, for example, when we have a text which has 100 words, we have a series of operations, so that the text becomes a (100,32) matrix, each row represents a word, each element represents a word, we want the word word vector becomes 64 dimensions:
Embedding (100, 64, input_length = 32)
Shape of the output matrix becomes (100, 32, 64): where each word has changed word into a 64-dimensional vector.

Guess you like

Origin blog.csdn.net/weixin_43265998/article/details/89134335