zoo.pipeline.api.keras2.layers package¶
Submodules¶
zoo.pipeline.api.keras2.layers.advanced_activations module¶
zoo.pipeline.api.keras2.layers.convolutional module¶
-
class
zoo.pipeline.api.keras2.layers.convolutional.Conv1D(filters, kernel_size, strides=1, padding='valid', activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zero', kernel_regularizer=None, bias_regularizer=None, input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2Layer1D convolution layer (e.g. temporal convolution).
This layer creates a convolution kernel that is convolved with the layer input over a single spatial (or temporal) dimension to produce a tensor of outputs. If use_bias is True, a bias vector is created and added to the outputs. Finally, if activation is not None, it is applied to the outputs as well.
When using this layer as the first layer in a model, provide an input_shape argument (tuple of integers or None, e.g. (10, 128) for sequences of 10 vectors of 128-dimensional vectors, or (None, 128) for variable-length sequences of 128-dimensional vectors.
- # Arguments
- filters: Integer, the dimensionality of the output space
- (i.e. the number of output filters in the convolution).
- kernel_size: An integer or tuple/list of a single integer,
- specifying the length of the 1D convolution window.
- strides: An integer or tuple/list of a single integer,
- specifying the stride length of the convolution. Specifying any stride value != 1 is incompatible with specifying any dilation_rate value != 1.
- padding: One of “valid” or “same” (case-insensitive).
- “valid” means “no padding”. “same” results in padding the input such that the output has the same length as the original input. (see [activations](../activations.md)). If you don’t specify anything, no activation is applied (ie. “linear” activation: a(x) = x).
use_bias: Boolean, whether the layer uses a bias vector. kernel_initializer: Initializer for the kernel weights matrix bias_initializer: Initializer for the bias vector kernel_regularizer: Regularizer function applied to
the kernel weights matrixbias_regularizer: Regularizer function applied to the bias vector
- # Input shape
- 3D tensor with shape: (batch_size, steps, input_dim)
- # Output shape
- 3D tensor with shape: (batch_size, new_steps, filters) steps value might have changed due to padding or strides.
>>> conv1d = Conv1D(12, 4, input_shape=(3, 16)) creating: createZooKeras2Conv1D
-
class
zoo.pipeline.api.keras2.layers.convolutional.Conv2D(filters, kernel_size, strides=(1, 1), padding='valid', data_format='channels_first', activation=None, use_bias=True, kernel_initializer='glorot_uniform', bias_initializer='zero', kernel_regularizer=None, bias_regularizer=None, input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2Layer2D convolution layer (e.g. spatial convolution over images).
This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs. If use_bias is True, a bias vector is created and added to the outputs. Finally, if activation is not None, it is applied to the outputs as well.
When using this layer as the first layer in a model, provide the keyword argument input_shape (tuple of integers, does not include the sample axis), e.g. input_shape=(128, 128, 3) for 128x128 RGB pictures in data_format=”channels_last”.
- # Arguments
- filters: Integer, the dimensionality of the output space
- (i.e. the number of output filters in the convolution).
- kernel_size: An integer or tuple/list of 2 integers, specifying the
- width and height of the 2D convolution window. Can be a single integer to specify the same value for all spatial dimensions.
- strides: An integer or tuple/list of 2 integers,
- specifying the strides of the convolution along the width and height. Can be a single integer to specify the same value for all spatial dimensions. Specifying any stride value != 1 is incompatible with specifying any dilation_rate value != 1.
- padding: one of “valid” or “same” (case-insensitive).
- Note that “same” is slightly inconsistent across backends with strides != 1.
- data_format: A string,
- one of channels_last (default) or channels_first. The ordering of the dimensions in the inputs. channels_last corresponds to inputs with shape (batch, height, width, channels) while channels_first corresponds to inputs with shape (batch, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be “channels_last”.
- activation: Activation function to use.
- If you don’t specify anything, no activation is applied (ie. “linear” activation: a(x) = x).
use_bias: Boolean, whether the layer uses a bias vector. kernel_initializer: Initializer for the kernel weights matrix bias_initializer: Initializer for the bias vector kernel_regularizer: Regularizer function applied to
the kernel weights matrixbias_regularizer: Regularizer function applied to the bias vector
- # Input shape
- 4D tensor with shape: (samples, channels, rows, cols) if data_format=’channels_first’ or 4D tensor with shape: (samples, rows, cols, channels) if data_format=’channels_last’.
- # Output shape
- 4D tensor with shape: (samples, filters, new_rows, new_cols) if data_format=’channels_first’ or 4D tensor with shape: (samples, new_rows, new_cols, filters) if data_format=’channels_last’. rows and cols values might have changed due to padding.
>>> conv2d = Conv2D(12, kernel_size=(2, 5), input_shape=(3, 16, 16)) creating: createZooKeras2Conv2D
-
class
zoo.pipeline.api.keras2.layers.convolutional.Cropping1D(cropping=(1, 1), input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerCropping layer for 1D input (e.g. temporal sequence). The input of this layer should be 3D.
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
# Arguments cropping: Int tuple of length 2. How many units should be trimmed off at the beginning and
end of the cropping dimension. Default is (1, 1).input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> cropping1d = Cropping1D(cropping=(1, 2), input_shape=(8, 8)) creating: createZooKeras2Cropping1D
zoo.pipeline.api.keras2.layers.convolutional_recurrent module¶
zoo.pipeline.api.keras2.layers.core module¶
-
class
zoo.pipeline.api.keras2.layers.core.Activation(activation, input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerSimple activation function to be applied to the output. Available activations: ‘tanh’, ‘relu’, ‘sigmoid’, ‘softmax’, ‘softplus’, ‘softsign’,
‘hard_sigmoid’, ‘linear’, ‘relu6’, ‘tanh_shrink’, ‘softmin’, ‘log_sigmoid’ and ‘log_softmax’.When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
# Arguments activation: Name of the activation function as string. input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> activation = Activation("relu", input_shape=(3, 4)) creating: createZooKeras2Activation
-
class
zoo.pipeline.api.keras2.layers.core.Dense(units, kernel_initializer='glorot_uniform', bias_initializer='zero', activation=None, kernel_regularizer=None, bias_regularizer=None, use_bias=True, input_dim=None, input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerA densely-connected NN layer. The most common input is 2D.
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
# Arguments units: The size of output dimension. kernel_initializer: String representation of the initialization method for the weights of the layer.
Default is ‘glorot_uniform’.- activation: String representation of the activation function to use
- (such as ‘relu’ or ‘sigmoid’). Default is None.
- kernel_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),
- applied to the input weights matrices. Default is None.
b_regularizer: An instance of [[Regularizer]], applied to the bias. Default is None. bias_regularizer: Whether to include a bias (i.e. make the layer affine rather than linear).
Default is True.- input_dim: Dimensionality of the input for 2D input. For nD input, you can alternatively
- specify ‘input_shape’ when using this layer as the first layer.
input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> dense = Dense(10, kernel_initializer="glorot_uniform", input_dim=8, name="dense1") creating: createZooKeras2Dense
-
class
zoo.pipeline.api.keras2.layers.core.Dropout(rate, input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerApplies Dropout to the input by randomly setting a fraction ‘rate’ of input units to 0 at each update during training time in order to prevent overfitting.
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
# Arguments rate: Fraction of the input units to drop. Float between 0 and 1. input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> dropout = Dropout(0.25, input_shape=(2, 3)) creating: createZooKeras2Dropout
-
class
zoo.pipeline.api.keras2.layers.core.Flatten(input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerFlattens the input without affecting the batch size.
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
# Arguments input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> flatten = Flatten(input_shape=(3, 10, 2)) creating: createZooKeras2Flatten
zoo.pipeline.api.keras2.layers.embeddings module¶
zoo.pipeline.api.keras2.layers.local module¶
-
class
zoo.pipeline.api.keras2.layers.local.LocallyConnected1D(filters, kernel_size, strides=1, padding='valid', activation=None, kernel_regularizer=None, bias_regularizer=None, use_bias=True, input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerLocally-connected layer for 1D inputs which works similarly to the TemporalConvolution layer, except that weights are unshared, that is, a different set of filters is applied at each different patch of the input.. Padding currently supported for this layer is ‘valid’. The input of this layer should be 3D.
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
# Arguments filters: Dimensionality of the output. kernel_size: The extension (spatial or temporal) of each filter. strides: Factor by which to subsample output. Int. Default is 1. padding: Only ‘valid’ is supported for now. activation: String representation of the activation function to use
(such as ‘relu’ or ‘sigmoid’). Default is None.- kernel_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),
- applied to the input weights matrices. Default is None.
bias_regularizer: An instance of [[Regularizer]], applied to the bias. Default is None. use_bias: Whether to include a bias (i.e. make the layer affine rather than linear).
Default is True.input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> locallyconnected1d = LocallyConnected1D(6, 3, input_shape=(8, 12)) creating: createZooKeras2LocallyConnected1D
zoo.pipeline.api.keras2.layers.merge module¶
-
class
zoo.pipeline.api.keras2.layers.merge.Average(input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerLayer that computes the average (element-wise) a list of inputs.
It takes as input a list of tensors, all of the same shape, and returns a single tensor (also of the same shape). >>> from zoo.pipeline.api.keras.layers import Input >>> ave = Average()([Input(shape=(4, 5)), Input(shape=(4, 5)), Input(shape=(4, 5))]) creating: createZooKeras2Average creating: createZooKerasInput creating: createZooKerasInput creating: createZooKerasInput
-
class
zoo.pipeline.api.keras2.layers.merge.Maximum(input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerLayer that computes the maximum (element-wise) a list of inputs.
It takes as input a list of tensors, all of the same shape, and returns a single tensor (also of the same shape). >>> from zoo.pipeline.api.keras.layers import Input >>> max = Maximum()([Input(shape=(4, 5)), Input(shape=(4, 5))]) creating: createZooKeras2Maximum creating: createZooKerasInput creating: createZooKerasInput
-
class
zoo.pipeline.api.keras2.layers.merge.Minimum(input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerLayer that computes the minimum (element-wise) a list of inputs.
It takes as input a list of tensors, all of the same shape, and returns a single tensor (also of the same shape). >>> from zoo.pipeline.api.keras.layers import Input >>> max = Minimum()([Input(shape=(4, 5)), Input(shape=(4, 5))]) creating: createZooKeras2Minimum creating: createZooKerasInput creating: createZooKerasInput
-
zoo.pipeline.api.keras2.layers.merge.average(inputs, **kwargs)[source]¶ Functional interface to the Average layer.
- # Arguments
- inputs: A list of input tensors (at least 2). **kwargs: Standard layer keyword arguments.
- # Returns
- A tensor, the element-wise minimum of the inputs.
>>> from zoo.pipeline.api.keras.layers import Input >>> ave = average([Input(shape=(4, 5)), Input(shape=(4, 5)), Input(shape=(4, 5))]) creating: createZooKerasInput creating: createZooKerasInput creating: createZooKerasInput creating: createZooKeras2Average
-
zoo.pipeline.api.keras2.layers.merge.maximum(inputs, **kwargs)[source]¶ Functional interface to the Maximum layer.
- # Arguments
- inputs: A list of input tensors (at least 2). **kwargs: Standard layer keyword arguments.
- # Returns
- A tensor, the element-wise maximum of the inputs.
>>> from zoo.pipeline.api.keras.layers import Input >>> max = maximum([Input(shape=(4, 5)), Input(shape=(4, 5))]) creating: createZooKerasInput creating: createZooKerasInput creating: createZooKeras2Maximum
-
zoo.pipeline.api.keras2.layers.merge.minimum(inputs, **kwargs)[source]¶ Functional interface to the Minimum layer.
- # Arguments
- inputs: A list of input tensors (at least 2). **kwargs: Standard layer keyword arguments.
- # Returns
- A tensor, the element-wise minimum of the inputs.
>>> from zoo.pipeline.api.keras.layers import Input >>> min = minimum([Input(shape=(4, 5)), Input(shape=(4, 5))]) creating: createZooKerasInput creating: createZooKerasInput creating: createZooKeras2Minimum
zoo.pipeline.api.keras2.layers.noise module¶
zoo.pipeline.api.keras2.layers.normalization module¶
zoo.pipeline.api.keras2.layers.pooling module¶
-
class
zoo.pipeline.api.keras2.layers.pooling.AveragePooling1D(pool_size=2, strides=None, padding='valid', input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerAverage pooling operation for temporal data.
- # Arguments
pool_size: Integer, size of the average pooling windows. strides: Integer, or None. Factor by which to downscale.
E.g. 2 will halve the input. If None, it will be set to -1, which will be default to pool_size.padding: One of “valid” or “same” (case-insensitive).
- # Input shape
- 3D tensor with shape: (batch_size, steps, features).
- # Output shape
- 3D tensor with shape: (batch_size, downsampled_steps, features).
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
>>> averagepooling1d = AveragePooling1D(input_shape=(3, 24)) creating: createZooKeras2AveragePooling1D
-
class
zoo.pipeline.api.keras2.layers.pooling.GlobalAveragePooling1D(input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerApplies global average pooling operation for temporal data. The input of this layer should be 3D.
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
# Arguments input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> globalaveragepooling1d = GlobalAveragePooling1D(input_shape=(12, 12)) creating: createZooKeras2GlobalAveragePooling1D
-
class
zoo.pipeline.api.keras2.layers.pooling.GlobalAveragePooling2D(data_format='channels_first', input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerApplies global average pooling operation for spatial data. The input of this layer should be 4D.
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
# Arguments data_format: Format of input data. Either channels_first or channels_last.
input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> globalaveragepooling2d = GlobalAveragePooling2D(input_shape=(4, 32, 32)) creating: createZooKeras2GlobalAveragePooling2D
-
class
zoo.pipeline.api.keras2.layers.pooling.GlobalMaxPooling1D(input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerApplies global max pooling operation for temporal data. The input of this layer should be 3D.
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension) .
# Arguments input_shape: A shape tuple, not including batch. name: String to set the name of the layer.
If not specified, its name will by default to be a generated string.>>> globalmaxpooling1d = GlobalMaxPooling1D(input_shape=(4, 8)) creating: createZooKeras2GlobalMaxPooling1D
-
class
zoo.pipeline.api.keras2.layers.pooling.MaxPooling1D(pool_size=2, strides=None, padding='valid', input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras2.base.ZooKeras2LayerMax pooling operation for temporal data.
- # Arguments
pool_size: Integer, size of the max pooling windows. strides: Integer, or None. Factor by which to downscale.
E.g. 2 will halve the input. If None, it will be set to -1, which will be default to pool_size.padding: One of “valid” or “same” (case-insensitive).
- # Input shape
- 3D tensor with shape: (batch_size, steps, features).
- # Output shape
- 3D tensor with shape: (batch_size, downsampled_steps, features).
When you use this layer as the first layer of a model, you need to provide the argument input_shape (a shape tuple, does not include the batch dimension).
>>> maxpooling1d = MaxPooling1D(3, input_shape=(3, 24)) creating: createZooKeras2MaxPooling1D