zoo.pipeline.api.keras.layers package

Submodules

zoo.pipeline.api.keras.layers.advanced_activations module

class zoo.pipeline.api.keras.layers.advanced_activations.ELU(alpha=1.0, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Exponential Linear Unit. It follows: f(x) = alpha * (exp(x) - 1.) for x < 0, f(x) = x for x >= 0.

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 alpha: Float, scale for the negative factor. Default is 1.0. 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.
>>> elu = ELU(1.2, input_shape=(4, 5))
creating: createZooKerasELU
class zoo.pipeline.api.keras.layers.advanced_activations.LeakyReLU(alpha=0.01, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Leaky version of a Rectified Linear Unit. It allows a small gradient when the unit is not active: f(x) = alpha * x for x < 0, f(x) = x for x >= 0.

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 alpha: Float >= 0. Negative slope coefficient. Default is 0.3. 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.
>>> leakyrelu = LeakyReLU(0.02, input_shape=(4, 5))
creating: createZooKerasLeakyReLU
class zoo.pipeline.api.keras.layers.advanced_activations.SReLU(t_left_init='zero', a_left_init='glorot_uniform', t_right_init='glorot_uniform', a_right_init='one', shared_axes=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

S-shaped Rectified Linear Unit. It follows: f(x) = t^r + a^r(x - t^r) for x >= t^r f(x) = x for t^r > x > t^l, f(x) = t^l + a^l(x - t^l) for x <= t^l

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 t_left_init: String representation of the initialization method for the left part intercept.

Default is ‘zero’.
a_left_init: String representation of the initialization method for the left part slope.
Default is ‘glorot_uniform’.
t_right_init: String representation of the nitialization method for the right part intercept.
Default is ‘glorot_uniform’.
a_right_init: String representation of the initialization method for the right part slope.
Default is ‘one’.
shared_axes: Int tuple. The axes along which to share learnable parameters for the
activation function. Default is None. For example, if the incoming feature maps are from a 2D convolution with output shape (batch, height, width, channels), and you wish to share parameters across space so that each filter only has one set of parameters, set ‘shared_axes=(1,2)’.

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.
>>> srelu = SReLU(input_shape=(4, 5))
creating: createZooKerasSReLU
class zoo.pipeline.api.keras.layers.advanced_activations.ThresholdedReLU(theta=1.0, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Thresholded Rectified Linear Unit. It follows: f(x) = x for x > theta, f(x) = 0 otherwise.

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 theta: Float >= 0. Threshold location of activation. Default is 1.0. 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.
>>> thresholdedrelu = ThresholdedReLU(input_shape=(10, 12))
creating: createZooKerasThresholdedReLU

zoo.pipeline.api.keras.layers.convolutional module

zoo.pipeline.api.keras.layers.convolutional.AtrousConv1D

alias of zoo.pipeline.api.keras.layers.convolutional.AtrousConvolution1D

zoo.pipeline.api.keras.layers.convolutional.AtrousConv2D

alias of zoo.pipeline.api.keras.layers.convolutional.AtrousConvolution2D

class zoo.pipeline.api.keras.layers.convolutional.AtrousConvolution1D(nb_filter, filter_length, init='glorot_uniform', activation=None, border_mode='valid', subsample_length=1, atrous_rate=1, W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies an atrous convolution operator for filtering neighborhoods of 1D inputs. A.k.a dilated convolution or convolution with holes. Border mode currently supported for this layer is ‘valid’. Bias will be included in this layer. You can also use AtrousConv1D as an alias of this layer. 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 nb_filter: Number of convolution filters to use. filter_length: The extension (spatial or temporal) of each filter. init: 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.

border_mode: Only ‘valid’ is supported for now. subsample_length: Factor by which to subsample output. Int. Default is 1. atrous_rate: Factor for kernel dilation. Also called filter_dilation elsewhere.

Int. Default is 1.
W_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: Only ‘True’ is supported for now. 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.
>>> atrousconv1d = AtrousConvolution1D(8, 3, input_shape=(3, 12))
creating: createZooKerasAtrousConvolution1D
class zoo.pipeline.api.keras.layers.convolutional.AtrousConvolution2D(nb_filter, nb_row, nb_col, init='glorot_uniform', activation=None, border_mode='valid', subsample=(1, 1), atrous_rate=(1, 1), dim_ordering='th', W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies an atrous Convolution operator for filtering windows of 2D inputs. A.k.a dilated convolution or convolution with holes. Data format currently supported for this layer is dim_ordering=’th’ (Channel First). Border mode currently supported for this layer is ‘valid’. Bias will be included in this layer. You can also use AtrousConv2D as an alias of this layer. 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). e.g. input_shape=(3, 128, 128) for 128x128 RGB pictures.

# Arguments nb_filter: Number of convolution filters to use. nb_row: Number of rows in the convolution kernel. nb_col: Number of cols in the convolution kernel. init: 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.

border_mode: Only ‘valid’ is supported for now. subsample: Int tuple of length 2 corresponding to the step of the convolution in the

height and width dimension. Also called strides elsewhere. Default is (1, 1).
atrous_rate: Int tuple of length 2. Factor for kernel dilation.
Also called filter_dilation elsewhere. Default is (1, 1).

dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. W_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: Only ‘True’ is supported for now. 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.
>>> atrousconv2d = AtrousConvolution2D(12, 4, 3, input_shape=(3, 64, 64))
creating: createZooKerasAtrousConvolution2D
zoo.pipeline.api.keras.layers.convolutional.Conv1D

alias of zoo.pipeline.api.keras.layers.convolutional.Convolution1D

zoo.pipeline.api.keras.layers.convolutional.Conv2D

alias of zoo.pipeline.api.keras.layers.convolutional.Convolution2D

zoo.pipeline.api.keras.layers.convolutional.Conv3D

alias of zoo.pipeline.api.keras.layers.convolutional.Convolution3D

class zoo.pipeline.api.keras.layers.convolutional.Convolution1D(nb_filter, filter_length, init='glorot_uniform', limits=None, activation=None, border_mode='valid', subsample_length=1, W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies convolution operator for filtering neighborhoods of 1D inputs. You can also use Conv1D as an alias of this layer. 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 nb_filter: Number of convolution filters to use. filter_length: The extension (spatial or temporal) of each filter. init: String representation of the initialization method for the weights of the layer.

Default is ‘glorot_uniform’.

limits: Optional. Limit value for initialization method. activation: String representation of the activation function to use

(such as ‘relu’ or ‘sigmoid’). Default is None.

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. subsample_length: Factor by which to subsample output. Int. Default is 1. W_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: 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.
>>> conv1d = Convolution1D(12, 4, input_shape=(3, 16))
creating: createZooKerasConvolution1D
class zoo.pipeline.api.keras.layers.convolutional.Convolution2D(nb_filter, nb_row, nb_col, init='glorot_uniform', activation=None, border_mode='valid', subsample=(1, 1), dim_ordering='th', W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, pads=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies a 2D convolution over an input image composed of several input planes. You can also use Conv2D as an alias of this layer. 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). e.g. input_shape=(3, 128, 128) for 128x128 RGB pictures.

# Arguments nb_filter: Number of convolution filters to use. nb_row: Number of rows in the convolution kernel. nb_col: Number of cols in the convolution kernel. init: 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.

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. subsample: Int tuple of length 2 corresponding to the step of the convolution in the

height and width dimension. Also called strides elsewhere. Default is (1, 1).
dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).
Default is ‘th’.
W_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: 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.
>>> conv2d = Convolution2D(32, 3, 3, input_shape=(3, 128, 128), name="convolution2d_1")
creating: createZooKerasConvolution2D
class zoo.pipeline.api.keras.layers.convolutional.Convolution3D(nb_filter, kernel_dim1, kernel_dim2, kernel_dim3, init='glorot_uniform', activation=None, border_mode='valid', subsample=(1, 1, 1), dim_ordering='th', W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies convolution operator for filtering windows of three-dimensional inputs. You can also use Conv3D as an alias of this layer. Data format currently supported for this layer is dim_ordering=’th’ (Channel First). The input of this layer should be 5D.

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 nb_filter: Number of convolution filters to use. kernel_dim1: Length of the first dimension in the convolution kernel. kernel_dim2: Length of the second dimension in the convolution kernel. kernel_dim3: Length of the third dimension in the convolution kernel. init: 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.

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. subsample: Int tuple of length 3. Factor by which to subsample output.

Also called strides elsewhere. Default is (1, 1, 1).

dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. W_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: 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.
>>> conv3d = Convolution3D(32, 3, 4, 5, input_shape=(3, 64, 64, 64))
creating: createZooKerasConvolution3D
class zoo.pipeline.api.keras.layers.convolutional.Cropping1D(cropping=(1, 1), input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Cropping 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: createZooKerasCropping1D
class zoo.pipeline.api.keras.layers.convolutional.Cropping2D(cropping=((0, 0), (0, 0)), dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Cropping layer for 2D input (e.g. picture). 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 cropping: Int tuple of tuple of length 2. How many units should be trimmed off

at the beginning and end of the 2 cropping dimensions (i.e. height and width). Default is ((0, 0), (0, 0)).

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.
>>> cropping2d = Cropping2D(cropping=((1, 2), (0, 1)), input_shape=(12, 12, 12))
creating: createZooKerasCropping2D
class zoo.pipeline.api.keras.layers.convolutional.Cropping3D(cropping=((1, 1), (1, 1), (1, 1)), dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Cropping layer for 3D data (e.g. spatial or spatio-temporal). The input of this layer should be 5D.

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 tuple of length 3. How many units should be trimmed off

at the beginning and end of the 3 cropping dimensions (i.e. kernel_dim1, kernel_dim2 and kernel_dim3). Default is ((1, 1), (1, 1), (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.
>>> cropping3d = Cropping3D(cropping=((0, 2), (1, 1), (3, 1)), input_shape=(4, 12, 12, 16))
creating: createZooKerasCropping3D
zoo.pipeline.api.keras.layers.convolutional.Deconv2D

alias of zoo.pipeline.api.keras.layers.convolutional.Deconvolution2D

class zoo.pipeline.api.keras.layers.convolutional.Deconvolution2D(nb_filter, nb_row, nb_col, output_shape, init='glorot_uniform', activation=None, border_mode='valid', subsample=(1, 1), dim_ordering='th', W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Transposed convolution operator for filtering windows of 2D inputs. The need for transposed convolutions generally arises from the desire to use a transformation going in the opposite direction of a normal convolution, i.e., from something that has the shape of the output of some convolution to something that has the shape of its input while maintaining a connectivity pattern that is compatible with said convolution. Data format currently supported for this layer is dim_ordering=’th’ (Channel First). Border mode currently supported for this layer is ‘valid’. You can also use Deconv2D as an alias of this layer. 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). e.g. input_shape=(3, 128, 128) for 128x128 RGB pictures.

# Arguments nb_filter: Number of transposed convolution filters to use. nb_row: Number of rows in the convolution kernel. nb_col: Number of cols in the convolution kernel. output_shape: Output shape of the transposed convolution operation. Tuple of int. init: 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.

border_mode: Only ‘valid’ is supported for now. subsample: Int tuple of length 2 corresponding to the step of the convolution in the

height and width dimension. Also called strides elsewhere. Default is (1, 1).

dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. W_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: 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.
>>> deconv2d = Deconvolution2D(3, 3, 3, output_shape=(None, 3, 14, 14), input_shape=(3, 12, 12))
creating: createZooKerasDeconvolution2D
zoo.pipeline.api.keras.layers.convolutional.SeparableConv2D

alias of zoo.pipeline.api.keras.layers.convolutional.SeparableConvolution2D

class zoo.pipeline.api.keras.layers.convolutional.SeparableConvolution2D(nb_filter, nb_row, nb_col, init='glorot_uniform', activation=None, border_mode='valid', subsample=(1, 1), depth_multiplier=1, dim_ordering='th', depthwise_regularizer=None, pointwise_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies separable convolution operator for 2D inputs. Separable convolutions consist in first performing a depthwise spatial convolution (which acts on each input channel separately) followed by a pointwise convolution which mixes together the resulting output channels. The depth_multiplier argument controls how many output channels are generated per input channel in the depthwise step. You can also use SeparableConv2D as an alias of this layer. 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). e.g. input_shape=(3, 128, 128) for 128x128 RGB pictures.

# Arguments nb_filter: Number of convolution filters to use. nb_row: Number of rows in the convolution kernel. nb_col: Number of cols in the convolution kernel. init: 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.

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. subsample: Int tuple of length 2 corresponding to the step of the convolution in the

height and width dimension. Also called strides elsewhere. Default is (1, 1).
depth_multiplier: How many output channel to use per input channel for the depthwise
convolution step. Int. Default is 1.
dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).
Default is ‘th’.
depthwise_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),
applied to the depthwise weights matrices. Default is None.
pointwise_regularizer: An instance of [[Regularizer]], applied to the pointwise weights
matrices. Default is None.

b_regularizer: An instance of [[Regularizer]], applied to the bias. Default is None. 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.
>>> separableconv2d = SeparableConvolution2D(12, 3, 4, input_shape=(3, 32, 32))
creating: createZooKerasSeparableConvolution2D
class zoo.pipeline.api.keras.layers.convolutional.UpSampling1D(length=2, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

UpSampling layer for 1D inputs. Repeats each temporal step ‘length’ times along the time axis. 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 length: Int. UpSampling factor. Default is 2. 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.
>>> upsampling1d = UpSampling1D(length=3, input_shape=(3, 12))
creating: createZooKerasUpSampling1D
class zoo.pipeline.api.keras.layers.convolutional.UpSampling2D(size=(2, 2), dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

UpSampling layer for 2D inputs. Repeats the rows and columns of the data by size[0] and size[1] respectively. 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 size: Int tuple of length 2. UpSampling factors for rows and columns. Default is (2, 2). dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

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.
>>> upsampling2d = UpSampling2D(size=(1, 3), input_shape=(3, 16, 16))
creating: createZooKerasUpSampling2D
class zoo.pipeline.api.keras.layers.convolutional.UpSampling3D(size=(2, 2, 2), dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

UpSampling layer for 2D inputs. Repeats the 1st, 2nd and 3rd dimensions of the data by size[0], size[1] and size[2] respectively. Data format currently supported for this layer is dim_ordering=’th’ (Channel First). The input of this layer should be 5D.

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 size: Int tuple of length 3. UpSampling factors for dim1, dim2 and dim3. Default is (2, 2, 2). dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. 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.
>>> upsampling3d = UpSampling3D(size=(1, 2, 3), input_shape=(3, 16, 16, 16))
creating: createZooKerasUpSampling3D
class zoo.pipeline.api.keras.layers.convolutional.ZeroPadding1D(padding=1, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Zero-padding 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 padding: Int or int tuple of length 2.

If int, how many zeros to add both at the beginning and at the end of the padding dimension. If tuple of length 2, how many zeros to add in the order ‘(left_pad, right_pad)’. Default is 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.
>>> zeropadding1d = ZeroPadding1D(padding=2, input_shape=(3, 6))
creating: createZooKerasZeroPadding1D
class zoo.pipeline.api.keras.layers.convolutional.ZeroPadding2D(padding=(1, 1), dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Zero-padding layer for 2D input (e.g. picture). 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 padding: Int tuple of length 2 or length 4.

If tuple of length 2, how many zeros to add both at the beginning and at the end of rows and cols. If tuple of length 4, how many zeros to add in the order ‘(top_pad, bottom_pad, left_pad, right_pad)’. Default is (1, 1).
dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).
Default is ‘th’.

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.
>>> zeropadding2d = ZeroPadding2D(padding=(2, 1), input_shape=(2, 8, 8))
creating: createZooKerasZeroPadding2D
class zoo.pipeline.api.keras.layers.convolutional.ZeroPadding3D(padding=(1, 1, 1), dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Zero-padding layer for 3D data (spatial or spatio-temporal). The input of this layer should be 5D.

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 padding: Int tuple of length 3. How many zeros to add at the beginning and

at the end of the 3 padding dimensions. Symmetric padding will be applied to each dimension. Default is (1, 1, 1).
dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).
Default is ‘th’.

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.
>>> zeropadding3d = ZeroPadding3D(padding=(2, 1, 2), input_shape=(2, 8, 8, 10))
creating: createZooKerasZeroPadding3D

zoo.pipeline.api.keras.layers.convolutional_recurrent module

class zoo.pipeline.api.keras.layers.convolutional_recurrent.ConvLSTM2D(nb_filter, nb_row, nb_col, activation='tanh', inner_activation='hard_sigmoid', dim_ordering='th', border_mode='valid', subsample=(1, 1), W_regularizer=None, U_regularizer=None, b_regularizer=None, return_sequences=False, go_backwards=False, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Convolutional LSTM. The convolution kernel for this layer is a square kernel with equal strides ‘subsample’. The input of this layer should be 5D, i.e. (samples, time, channels, rows, cols) and dim_ordering=’th’ (Channel First) is expected.

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 nb_filter: Number of convolution filters to use. nb_row: Number of rows in the convolution kernel. nb_col: Number of cols in the convolution kernel.

Should be equal to nb_row as for a square kernel.
activation: String representation of the activation function to use
(such as ‘relu’ or ‘sigmoid’). Default is ‘tanh’.
inner_activation: String representation of the activation function for inner cells.
Default is ‘hard_sigmoid’.

dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. subsample: Tuple of length 2. Factor by which to subsample output.

Also called strides elsewhere. Only support subsample[0] equal to subsample[1] for now. Default is (1, 1).

border_mode: One of “same” or “valid”. Also called padding elsewhere. Default is “valid”. W_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),

applied to the input weights matrices. Default is None.
U_regularizer: An instance of [[Regularizer]], applied the recurrent weights matrices.
Default is None.

b_regularizer: An instance of [[Regularizer]], applied to the bias. Default is None. return_sequences: Whether to return the full sequence or only return the last output

in the output sequence. Default is False.

go_backwards: Whether the input sequence will be processed backwards. Default is False. 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.
>>> convlstm2d = ConvLSTM2D(24, 3, 3, input_shape=(4, 32, 32, 32))
creating: createZooKerasConvLSTM2D
class zoo.pipeline.api.keras.layers.convolutional_recurrent.ConvLSTM3D(nb_filter, nb_kernel, dim_ordering='th', border_mode='valid', subsample=(1, 1, 1), W_regularizer=None, U_regularizer=None, b_regularizer=None, return_sequences=False, go_backwards=False, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Convolutional LSTM for 3D input. The convolution kernel for this layer is a cubic kernel with equal strides for all dimensions. The input of this layer should be 6D, i.e. (samples, time, channels, dim1, dim2, dim3), and ‘CHANNEL_FIRST’ (dimOrdering=’th’) is expected.

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 nb_filter: Number of convolution filters to use. nb_kernel: Length of the first, second and third dimensions in the convolution kernel.

Cubic kernel.

dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. border_mode: Only ‘same’ is supported for now. subsample: Tuple of length 3. Factor by which to subsample output.

Also called strides elsewhere. Default is (1, 1, 1). Only support subsample[0] equal to subsample[1] equal to subsample[2] for now.

border_mode: One of “same” or “valid”. Also called padding elsewhere. Default is “valid”. W_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),

applied to the input weights matrices. Default is None.
U_regularizer: An instance of [[Regularizer]], applied the recurrent weights matrices.
Default is None.

b_regularizer: An instance of [[Regularizer]], applied to the bias. Default is None. return_sequences: Whether to return the full sequence or only return the last output

in the output sequence. Default is False.

go_backwards: Whether the input sequence will be processed backwards. Default is False. 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.
>>> convlstm3d = ConvLSTM3D(10, 4, input_shape=(8, 4, 10, 32, 32))
creating: createZooKerasConvLSTM3D

zoo.pipeline.api.keras.layers.core module

class zoo.pipeline.api.keras.layers.core.Activation(activation, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Simple 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: createZooKerasActivation
class zoo.pipeline.api.keras.layers.core.Dense(output_dim, init='glorot_uniform', limits=None, activation=None, W_regularizer=None, b_regularizer=None, bias=True, input_dim=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

A 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 output_dim: The size of output dimension. init: 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.
W_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: 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, input_dim=8, name="dense1")
creating: createZooKerasDense
class zoo.pipeline.api.keras.layers.core.Dropout(p, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies Dropout to the input by randomly setting a fraction ‘p’ 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 p: 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: createZooKerasDropout
class zoo.pipeline.api.keras.layers.core.ExpandDim(dim, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Expand_dim is an improved layer to suuport 1D input. For example, if we get an 1D input with shape(3), we will return the shape(1, 3) after we use expand_dim(0, input). # Arguments dim: The specified axis to expand dimension on. input_shape: A shape tuple, not including batch.

>>> expandDim = ExpandDim(dim=0, input_shape=(3, 2))
creating: createZooKerasExpandDim
class zoo.pipeline.api.keras.layers.core.Flatten(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Flattens 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: createZooKerasFlatten
class zoo.pipeline.api.keras.layers.core.GetShape(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

GetShape gets the value of input_shape. For example, if input_shape = (2, 3, 4), then output will be (2, 3, 4).

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. >>> getShape = GetShape(input_shape=(3, 4, 5)) creating: createZooKerasGetShape

class zoo.pipeline.api.keras.layers.core.Highway(activation=None, W_regularizer=None, b_regularizer=None, bias=True, input_dim=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Densely connected highway network. Highway layers are a natural extension of LSTMs to feedforward networks. The input of this layer should be 2D, i.e. (batch, input dim).

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: String representation of the activation function to use

(such as ‘relu’ or ‘sigmoid’). Default is None.
W_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: Whether to include a bias (i.e. make the layer affine rather than linear).

Default is True.
input_dim: Dimensionality of the input. Alternatively, you can 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.
>>> highway = Highway(activation='relu', input_shape=(8, ))
creating: createZooKerasHighway
class zoo.pipeline.api.keras.layers.core.Masking(mask_value=0.0, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Use a mask value to skip timesteps for a sequence. Masks a sequence by using a mask value to skip timesteps.

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 mask_value: Float, mask value. For each timestep in the input (the second dimension),

if all values in the input at that timestep are equal to ‘mask_value’, then the timestep will masked (skipped) in all downstream layers.

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.
>>> masking = Masking(0.3, input_shape=(6, 8))
creating: createZooKerasMasking
class zoo.pipeline.api.keras.layers.core.Max(dim, num_input_dims=-2147483648, return_value=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies a max operation over dimension dim

# Arguments dim: max along this dimension num_input_dims: Optional. If in a batch model, set to the inputDims. return_value: Optional. Config whether return value or indices input_shape: A shape tuple, not including batch.

>>> max = Max(dim=1, input_shape=(3, 5))
creating: createZooKerasMax
class zoo.pipeline.api.keras.layers.core.MaxoutDense(output_dim, nb_feature=4, W_regularizer=None, b_regularizer=None, bias=True, input_dim=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

A dense maxout layer that takes the element-wise maximum of linear layers. This allows the layer to learn a convex, piecewise linear activation function over the inputs. The input of this layer should be 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 output_dim: The size of output dimension. nb_feature: Number of Dense layers to use internally. Int. Default is 4. W_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: Whether to include a bias (i.e. make the layer affine rather than linear).

Default is True.
input_dim: Dimensionality of the input. Alternatively, you can 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.
>>> maxoutdense = MaxoutDense(6, input_shape=(10, ))
creating: createZooKerasMaxoutDense
class zoo.pipeline.api.keras.layers.core.Permute(dims, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Permutes the dimensions of the input according to a given pattern. Useful for connecting RNNs and convnets together.

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 dims: Tuple of int. Permutation pattern, does not include the batch dimension.

Indexing starts at 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.
>>> permute = Permute((2, 1, 3), input_shape=(3, 4, 5))
creating: createZooKerasPermute
class zoo.pipeline.api.keras.layers.core.RepeatVector(n, input_dim=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Repeats the input n times. The input of this layer should be 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 n: Repetition factor. Int. input_dim: Dimensionality of the input. Alternatively, you can 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.
>>> repeatvector = RepeatVector(5, input_shape=(3, ))
creating: createZooKerasRepeatVector
class zoo.pipeline.api.keras.layers.core.Reshape(target_shape, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Reshapes an output to a certain shape. Supports shape inference by allowing one -1 in the target shape. For example, if input_shape = (2, 3, 4), target_shape = (3, -1), then output_shape will be (3, 8).

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 target_shape: A shape tuple. The target shape that you desire to have.

Batch dimension should be excluded.

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.
>>> reshape = Reshape((2, 10), input_shape=(5, 4))
creating: createZooKerasReshape
class zoo.pipeline.api.keras.layers.core.SparseDense(output_dim, init='glorot_uniform', activation=None, W_regularizer=None, b_regularizer=None, backward_start=-1, backward_length=-1, init_weight=None, init_bias=None, init_grad_weight=None, init_grad_bias=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

SparseDense is the sparse version of layer Dense. SparseDense has two different from Dense: firstly, SparseDense’s input Tensor is a SparseTensor. Secondly, SparseDense doesn’t backward gradient to next layer in the backpropagation by default, as the gradInput of SparseDense is useless and very big in most cases.

But, considering model like Wide&Deep, we provide backwardStart and backwardLength to backward part of the gradient to next 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 inputShape (a Single Shape, does not include the batch dimension).

# Arguments output_dim: The size of output dimension. init: 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.
W_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: Whether to include a bias (i.e. make the layer affine rather than linear).

Default is True.

backward_start: backward start index, counting from 1. backward_length: backward length. 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.
>>> sparseDense = SparseDense(10, input_shape=(10, 4), name="sparseDense")
creating: createZooKerasSparseDense
class zoo.pipeline.api.keras.layers.core.SpatialDropout1D(p=0.5, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Spatial 1D version of Dropout. This version performs the same function as Dropout, however it drops entire 1D feature maps instead of individual elements. If adjacent frames within feature maps are strongly correlated (as is normally the case in early convolution layers) then regular dropout will not regularize the activations and will otherwise just result in an effective learning rate decrease. In this case, SpatialDropout1D will help promote independence between feature maps and should be used instead. 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 p: 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.
>>> spatialdropout1d = SpatialDropout1D(0.4, input_shape=(10, 12))
creating: createZooKerasSpatialDropout1D
class zoo.pipeline.api.keras.layers.core.SpatialDropout2D(p=0.5, dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Spatial 2D version of Dropout. This version performs the same function as Dropout, however it drops entire 2D feature maps instead of individual elements. If adjacent pixels within feature maps are strongly correlated (as is normally the case in early convolution layers) then regular dropout will not regularize the activations and will otherwise just result in an effective learning rate decrease. In this case, SpatialDropout2D will help promote independence between feature maps and should be used instead. 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 p: Fraction of the input units to drop. Float between 0 and 1. dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

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.
>>> spatialdropout2d = SpatialDropout2D(0.25, input_shape=(5, 12, 12))
creating: createZooKerasSpatialDropout2D
class zoo.pipeline.api.keras.layers.core.SpatialDropout3D(p=0.5, dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Spatial 3D version of Dropout. This version performs the same function as Dropout, however it drops entire 3D feature maps instead of individual elements. If adjacent voxels within feature maps are strongly correlated (as is normally the case in early convolution layers) then regular dropout will not regularize the activations and will otherwise just result in an effective learning rate decrease. In this case, SpatialDropout3D will help promote independence between feature maps and should be used instead. The input of this layer should be 5D.

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 p: Fraction of the input units to drop. Float between 0 and 1. dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

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.
>>> spatialdropout3d = SpatialDropout3D(0.6, input_shape=(4, 12, 12, 16))
creating: createZooKerasSpatialDropout3D

zoo.pipeline.api.keras.layers.embeddings module

class zoo.pipeline.api.keras.layers.embeddings.Embedding(input_dim, output_dim, init='uniform', weights=None, trainable=True, input_length=None, W_regularizer=None, input_shape=None, mask_zero=False, padding_value=0, zero_based_id=True, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Turn positive integers (indexes) into dense vectors of fixed size. The input of this layer should be 2D.

This layer can only be used as the first layer in a model, you need to provide the argument input_length (an integer) or input_shape (a shape tuple, does not include the batch dimension).

# Arguments input_dim: Size of the vocabulary. Int > 0. output_dim: Dimension of the dense embedding. Int > 0. init: String representation of the initialization method for the weights of the layer.

Default is ‘uniform’.
W_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),
applied to the embedding matrix. Default is None.
weights: Initial weights set to this layer, which should be a numpy array of
size (inputDim, outputDim). Default is None and in this case weights are initialized by the initialization method specified by ‘init’. Otherwise, ‘weights’ will override ‘init’ to take effect.

trainable: Whether this layer is trainable or not. Default is True. input_length: Positive int. The sequence length of each input. mask_zero: if maskZero is set to true, the input whose value equals paddingValue the output will be masked to zero vector. padding_value: padding value, default 0 zero_based_id: default True and input should be 0 based. Otherwise need to be 1 base name: String to set the name of the layer.

If not specified, its name will by default to be a generated string.
>>> embedding = Embedding(1000, 32, input_length=10, name="embedding1")
creating: createZooKerasEmbedding
>>> import numpy as np
>>> embedding = Embedding(10, 200, weights=np.random.random([10, 200]), input_length=10)
creating: createZooKerasEmbedding
class zoo.pipeline.api.keras.layers.embeddings.SparseEmbedding(input_dim, output_dim, combiner='sum', max_norm=-1.0, init='uniform', W_regularizer=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

SparseEmbedding is the sparse version of layer Embedding.

The input of SparseEmbedding should be a 2D SparseTensor or two 2D sparseTensors. If the input is a SparseTensor, the values are positive integer ids, values in each row of this SparseTensor will be turned into a dense vector. If the input is two SparseTensors, the first tensor should be the integer ids, just like the SparseTensor input. And the second tensor is the corresponding weights of the integer ids.

This layer can only be used as the first layer in a model, you need to provide the argument inputShape (a Single Shape, does not include the batch dimension).

# Arguments input_dim: Size of the vocabulary. Int > 0. output_dim: Dimension of the dense embedding. Int >= 0. init: String representation of the initialization method for the weights of the layer.

Default is ‘uniform’.
combiner: A string specifying the reduce type.
Currently “mean”, “sum”, “sqrtn” is supported.
max_norm: If provided, each embedding is normalized to have l2 norm equal to
maxNorm before combining.
W_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),
applied to the embedding matrix. Default is None.

input_shape: A Single Shape, does not include the batch dimension. name: String to set the name of the layer.

If not specified, its name will by default to be a generated string.
>>> sparse_embedding = SparseEmbedding(input_dim=10, output_dim=4, input_shape=(10, ))
creating: createZooKerasSparseEmbedding
class zoo.pipeline.api.keras.layers.embeddings.WordEmbedding(embedding_file, word_index=None, trainable=False, input_length=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Embedding layer that directly loads pre-trained word vectors as weights. Turn non-negative integers (indices) into dense vectors of fixed size. Currently only GloVe embedding is supported. The input of this layer should be 2D.

This layer can only be used as the first layer in a model, you need to provide the argument input_length (an integer) or input_shape (a shape tuple, does not include the batch dimension).

# Arguments embedding_file: The path to the embedding file.

Currently the following GloVe files are supported: “glove.6B.50d.txt”, “glove.6B.100d.txt”, “glove.6B.200d.txt” “glove.6B.300d.txt”, “glove.42B.300d.txt”, “glove.840B.300d.txt”. You can download them from: https://nlp.stanford.edu/projects/glove/.
word_index: Dictionary of word (string) and its corresponding index (int).
The index is supposed to start from 1 with 0 reserved for unknown words. During the prediction, if you have words that are not in the word_index for the training, you can map them to index 0. Default is None. In this case, all the words in the embedding_file will be taken into account and you can call WordEmbedding.get_word_index(embedding_file) to retrieve the dictionary.
trainable: To configure whether the weights of this layer will be updated or not.
Only False is supported for now.

input_length: Positive int. The sequence length of each input. name: String to set the name of the layer.

If not specified, its name will by default to be a generated string.
static get_word_index(embedding_file, bigdl_type='float')[source]

Get the full wordIndex map from the given embedding_file.

# Arguments embedding_file: The path to the embedding file.

Currently only the following GloVe files are supported: “glove.6B.50d.txt”, “glove.6B.100d.txt”, “glove.6B.200d.txt” “glove.6B.300d.txt”, “glove.42B.300d.txt”, “glove.840B.300d.txt”. You can download them from: https://nlp.stanford.edu/projects/glove/.

# Return Dictionary of word (string) and its corresponding index (int) obtained from the given embedding file.

zoo.pipeline.api.keras.layers.embeddings.prepare_embedding(embedding_file, word_index=None, randomize_unknown=False, normalize=False)[source]

Prepare embedding weights from embedding_file given word_index.

# Arguments embedding_file and word_index: See WordEmbedding. randomize_unknown: Boolean. Whether to randomly initialize words that don’t exist in

embedding_file. Default is False and in this case corresponding entries to unknown words will be zero vectors.

normalize: Boolean. Whether to normalize word vectors. Default is False.

# Return Pretrained embedding weights as a numpy array.

zoo.pipeline.api.keras.layers.local module

class zoo.pipeline.api.keras.layers.local.LocallyConnected1D(nb_filter, filter_length, activation=None, border_mode='valid', subsample_length=1, W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Locally-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. Border mode 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 nb_filter: Dimensionality of the output. filter_length: The extension (spatial or temporal) of each filter. activation: String representation of the activation function to use

(such as ‘relu’ or ‘sigmoid’). Default is None.

border_mode: Only ‘valid’ is supported for now. subsample_length: Factor by which to subsample output. Int. Default is 1. W_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: 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: createZooKerasLocallyConnected1D
class zoo.pipeline.api.keras.layers.local.LocallyConnected2D(nb_filter, nb_row, nb_col, activation=None, border_mode='valid', subsample=(1, 1), dim_ordering='th', W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Locally-connected layer for 2D inputs that works similarly to the SpatialConvolution layer, except that weights are unshared, that is, a different set of filters is applied at each different patch of the input. 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 nb_filter: Number of convolution filters to use. nb_row: Number of rows in the convolution kernel. nb_col: Number of cols in the convolution kernel. activation: String representation of the activation function to use

(such as ‘relu’ or ‘sigmoid’). Default is None.

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. subsample: Int tuple of length 2 corresponding to the step of the convolution in the

height and width dimension. Also called strides elsewhere. Default is (1, 1).
dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).
Default is ‘th’.
W_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: 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.
>>> locallyconnected2d = LocallyConnected2D(12, 3, 4, input_shape=(3, 128, 128))
creating: createZooKerasLocallyConnected2D

zoo.pipeline.api.keras.layers.noise module

class zoo.pipeline.api.keras.layers.noise.GaussianDropout(p, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Apply multiplicative 1-centered Gaussian noise. As it is a regularization layer, it is only active at training time.

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 p: Drop probability. Float between 0 and 1.

The multiplicative noise will have standard deviation ‘sqrt(p/(1-p))’.

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.
>>> gaussiandropout = GaussianDropout(0.45, input_shape=(4, 8))
creating: createZooKerasGaussianDropout
class zoo.pipeline.api.keras.layers.noise.GaussianNoise(sigma, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Apply additive zero-centered Gaussian noise. This is useful to mitigate overfitting (you could see it as a form of random data augmentation). Gaussian Noise is a natural choice as corruption process for real valued inputs. As it is a regularization layer, it is only active at training time.

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 sigma: Float, standard deviation of the noise distribution. 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.
>>> gaussiannoise = GaussianNoise(0.45, input_shape=(3, 4, 5), name="gaussiannoise1")
creating: createZooKerasGaussianNoise

zoo.pipeline.api.keras.layers.normalization module

class zoo.pipeline.api.keras.layers.normalization.BatchNormalization(epsilon=0.001, mode=0, axis=1, momentum=0.99, beta_init='zero', gamma_init='one', dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Batch normalization layer. Normalize the activations of the previous layer at each batch, i.e. applies a transformation that maintains the mean activation close to 0 and the activation standard deviation close to 1. It is a feature-wise normalization, each feature map in the input will be normalized separately. The input of this layer should be 4D or 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 epsilon: Small float > 0. Fuzz parameter. Default is 0.001. momentum: Float. Momentum in the computation of the exponential average of the mean and

standard deviation of the data, for feature-wise normalization. Default is 0.99.

beta_init: Name of the initialization function for shift parameter. Default is ‘zero’. gamma_init: Name of the initialization function for scale parameter. Default is ‘one’. dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’. For ‘th’, axis along which to normalize is 1. For ‘tf’, axis is 3.

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.
>>> batchnormalization = BatchNormalization(input_shape=(3, 12, 12), name="bn1")
creating: createZooKerasBatchNormalization
get_running_mean()[source]

Get the running meaning of the BatchNormalization layer.

get_running_std()[source]

Get the running variance of the BatchNormalization layer.

set_running_mean(running_mean)[source]

Set the running mean of the BatchNormalization layer. :param running_mean: a Numpy array.

set_running_std(running_std)[source]

Set the running variance of the BatchNormalization layer. :param running_std: a Numpy array.

zoo.pipeline.api.keras.layers.pooling module

class zoo.pipeline.api.keras.layers.pooling.AveragePooling1D(pool_length=2, stride=None, border_mode='valid', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies 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 pool_length: Size of the region to which max pooling is applied. strides: Factor by which to downscale. 2 will halve the input.

Default is None, and in this case it will be equal to pool_length..

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. 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.
>>> averagepooling1d = AveragePooling1D(input_shape=(3, 24))
creating: createZooKerasAveragePooling1D
class zoo.pipeline.api.keras.layers.pooling.AveragePooling2D(pool_size=(2, 2), strides=None, border_mode='valid', dim_ordering='th', input_shape=None, pads=None, count_include_pad=False, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies 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 pool_size: Int tuple of length 2 corresponding to the downscale vertically and horizontally.

Default is (2, 2), which will halve the image in each dimension.
strides: Int tuple of length 2. Stride values.
Default is None, and in this case it will be equal to pool_size.

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

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.
>>> averagepooling2d = AveragePooling2D((1, 2), input_shape=(2, 28, 32))
creating: createZooKerasAveragePooling2D
class zoo.pipeline.api.keras.layers.pooling.AveragePooling3D(pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies average pooling operation for 3D data (spatial or spatio-temporal). Data format currently supported for this layer is dim_ordering=’th’ (Channel First). Border mode currently supported for this layer is ‘valid’. The input of this layer should be 5D.

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 pool_size: Int tuple of length 3. Factors by which to downscale (dim1, dim2, dim3).

Default is (2, 2, 2), which will halve the image in each dimension.
strides: Int tuple of length 3. Stride values.
Default is None, and in this case it will be equal to pool_size.

border_mode: Only ‘valid’ is supported for now. dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. 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.
>>> averagepooling3d = AveragePooling3D((1, 1, 2), input_shape=(3, 28, 32, 36))
creating: createZooKerasAveragePooling3D
class zoo.pipeline.api.keras.layers.pooling.GlobalAveragePooling1D(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies 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: createZooKerasGlobalAveragePooling1D
class zoo.pipeline.api.keras.layers.pooling.GlobalAveragePooling2D(dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies 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 dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

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: createZooKerasGlobalAveragePooling2D
class zoo.pipeline.api.keras.layers.pooling.GlobalAveragePooling3D(dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies global average pooling operation for 3D data. Data format currently supported for this layer is dim_ordering=’th’ (Channel First). Border mode currently supported for this layer is ‘valid’. The input of this layer should be 5D.

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 dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. 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.
>>> globalaveragepooling3d = GlobalAveragePooling3D(input_shape=(4, 16, 16, 20))
creating: createZooKerasGlobalAveragePooling3D
class zoo.pipeline.api.keras.layers.pooling.GlobalMaxPooling1D(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies 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: createZooKerasGlobalMaxPooling1D
class zoo.pipeline.api.keras.layers.pooling.GlobalMaxPooling2D(dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies global max 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 dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

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.
>>> globalmaxpooling2d = GlobalMaxPooling2D(input_shape=(4, 32, 32))
creating: createZooKerasGlobalMaxPooling2D
class zoo.pipeline.api.keras.layers.pooling.GlobalMaxPooling3D(dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies global max pooling operation for 3D data. Data format currently supported for this layer is dim_ordering=’th’ (Channel First). Border mode currently supported for this layer is ‘valid’. The input of this layer should be 5D.

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 dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. 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.
>>> globalmaxpooling3d = GlobalMaxPooling3D(input_shape=(4, 32, 32, 32))
creating: createZooKerasGlobalMaxPooling3D
class zoo.pipeline.api.keras.layers.pooling.MaxPooling1D(pool_length=2, stride=None, border_mode='valid', input_shape=None, pad=0, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies 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 pool_length: Size of the region to which max pooling is applied. Integer. Default is 2. strides: Factor by which to downscale. 2 will halve the input.

Default is None, and in this case it will be equal to pool_length..

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. 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.
>>> maxpooling1d = MaxPooling1D(3, input_shape=(3, 24))
creating: createZooKerasMaxPooling1D
class zoo.pipeline.api.keras.layers.pooling.MaxPooling2D(pool_size=(2, 2), strides=None, border_mode='valid', dim_ordering='th', input_shape=None, pads=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies max 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 pool_size: Int tuple of length 2 corresponding to the downscale vertically and horizontally.

Default is (2, 2), which will halve the image in each dimension.
strides: Int tuple of length 2. Stride values.
Default is None, and in this case it will be equal to pool_size.

border_mode: Either ‘valid’ or ‘same’. Default is ‘valid’. dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

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.
>>> maxpooling2d = MaxPooling2D((2, 2), input_shape=(3, 32, 32), name="maxpooling2d_1")
creating: createZooKerasMaxPooling2D
class zoo.pipeline.api.keras.layers.pooling.MaxPooling3D(pool_size=(2, 2, 2), strides=None, border_mode='valid', dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies max pooling operation for 3D data (spatial or spatio-temporal). Data format currently supported for this layer is dim_ordering=’th’ (Channel First). Border mode currently supported for this layer is ‘valid’. The input of this layer should be 5D.

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 pool_size: Int tuple of length 3. Factors by which to downscale (dim1, dim2, dim3).

Default is (2, 2, 2), which will halve the image in each dimension.
strides: Int tuple of length 3. Stride values.
Default is None, and in this case it will be equal to pool_size.

border_mode: Only ‘valid’ is supported for now. dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. 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.
>>> maxpooling3d = MaxPooling3D((2, 1, 3), input_shape=(3, 32, 32, 32))
creating: createZooKerasMaxPooling3D

zoo.pipeline.api.keras.layers.recurrent module

class zoo.pipeline.api.keras.layers.recurrent.GRU(output_dim, activation='tanh', inner_activation='hard_sigmoid', return_sequences=False, go_backwards=False, W_regularizer=None, U_regularizer=None, b_regularizer=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Gated Recurrent Unit architecture. The input of this layer should be 3D, i.e. (batch, time steps, input dim).

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 output_dim: Hidden unit size. Dimension of internal projections and final output. activation: String representation of the activation function to use

(such as ‘relu’ or ‘sigmoid’). Default is ‘tanh’.
inner_activation: String representation of the activation function for inner cells.
Default is ‘hard_sigmoid’.
return_sequences: Whether to return the full sequence or only return the last output
in the output sequence. Default is False.

go_backwards: Whether the input sequence will be processed backwards. Default is False. W_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),

applied to the input weights matrices. Default is None.
U_regularizer: An instance of [[Regularizer]], applied the recurrent weights matrices.
Default is None.

b_regularizer: An instance of [[Regularizer]], applied to the bias. Default is None. 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.
>>> gru = GRU(24, input_shape=(32, 32))
creating: createZooKerasGRU
class zoo.pipeline.api.keras.layers.recurrent.LSTM(output_dim, activation='tanh', inner_activation='hard_sigmoid', return_sequences=False, go_backwards=False, W_regularizer=None, U_regularizer=None, b_regularizer=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Long Short Term Memory unit architecture. The input of this layer should be 3D, i.e. (batch, time steps, input dim).

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 output_dim: Hidden unit size. Dimension of internal projections and final output. activation: String representation of the activation function to use

(such as ‘relu’ or ‘sigmoid’). Default is ‘tanh’.
inner_activation: String representation of the activation function for inner cells.
Default is ‘hard_sigmoid’.
return_sequences: Whether to return the full sequence or only return the last output
in the output sequence. Default is False.

go_backwards: Whether the input sequence will be processed backwards. Default is False. W_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),

applied to the input weights matrices. Default is None.
U_regularizer: An instance of [[Regularizer]], applied the recurrent weights matrices.
Default is None.

b_regularizer: An instance of [[Regularizer]], applied to the bias. Default is None. 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.
>>> lstm = LSTM(32, input_shape=(8, 16), name="lstm1")
creating: createZooKerasLSTM
class zoo.pipeline.api.keras.layers.recurrent.SimpleRNN(output_dim, activation='tanh', return_sequences=False, go_backwards=False, W_regularizer=None, U_regularizer=None, b_regularizer=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

A fully-connected recurrent neural network cell. The output is to be fed back to input. The input of this layer should be 3D, i.e. (batch, time steps, input dim).

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 output_dim: Hidden unit size. Dimension of internal projections and final output. activation: String representation of the activation function to use

(such as ‘relu’ or ‘sigmoid’). Default is ‘tanh’.
return_sequences: Whether to return the full sequence or only return the last output
in the output sequence. Default is False.

go_backwards: Whether the input sequence will be processed backwards. Default is False. W_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),

applied to the input weights matrices. Default is None.
U_regularizer: An instance of [[Regularizer]], applied the recurrent weights matrices.
Default is None.

b_regularizer: An instance of [[Regularizer]], applied to the bias. Default is None. 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.
>>> simplernn = SimpleRNN(16, input_shape=(3, 32))
creating: createZooKerasSimpleRNN

zoo.pipeline.api.keras.layers.self_attention module

class zoo.pipeline.api.keras.layers.self_attention.BERT(n_block, n_head, intermediate_size, hidden_drop, attn_drop, initializer_range, output_all_block, embedding_layer, input_shape, bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.layers.self_attention.TransformerLayer

A self attention layer. Input is a list which consists of 4 ndarrays. 1. Token id ndarray: shape [batch, seqLen] with the word token indices in the vocabulary 2. Token type id ndarray: shape [batch, seqLen] with the token types in [0, 1].

0 means sentence A and 1 means a sentence B (see BERT paper for more details).
  1. Position id ndarray: shape [batch, seqLen] with positions in the sentence.
  2. Attention_mask ndarray: shape [batch, seqLen] with indices in [0, 1]. It’s a mask to be used if the input sequence length is smaller than seqLen in the current batch.

Output is a list which contains: 1. The states of BERT layer. 2. The pooled output which processes the hidden state of the last layer with regard to the first token of the sequence. This would be useful for segment-level tasks.

# Arguments n_block: block number n_head: head number intermediate_size: The size of the “intermediate” (i.e., feed-forward) hidden_drop: The dropout probability for all fully connected layers attn_drop: drop probability of attention initializer_ranger: weight initialization range output_all_block: whether output all blocks’ output embedding_layer: embedding layer input_shape: input shape

build_input(input_shape)[source]
gelu(x)[source]
classmethod init(vocab=40990, hidden_size=768, n_block=12, n_head=12, seq_len=512, intermediate_size=3072, hidden_drop=0.1, attn_drop=0.1, initializer_range=0.02, output_all_block=True, bigdl_type='float')[source]

vocab: vocabulary size of training data, default is 40990 hidden_size: size of the encoder layers, default is 768 n_block: block number, default is 12 n_head: head number, default is 12 seq_len: max sequence length of training data, default is 77 intermediate_size: The size of the “intermediate” (i.e., feed-forward) hidden_drop: drop probability of full connected layers, default is 0.1 attn_drop: drop probability of attention, default is 0.1 initializer_ranger: weight initialization range, default is 0.02 output_all_block: whether output all blocks’ output, default is True

static init_from_existing_model(path, weight_path=None, input_seq_len=-1.0, hidden_drop=-1.0, attn_drop=-1.0, output_all_block=True, bigdl_type='float')[source]

Load an existing BERT model (with weights).

# Arguments path: The path for the pre-defined model.

Local file system, HDFS and Amazon S3 are supported. HDFS path should be like ‘hdfs://[host]:[port]/xxx’. Amazon S3 path should be like ‘s3a://bucket/xxx’.

weight_path: The path for pre-trained weights if any. Default is None.

projection_layer(output_size)[source]
class zoo.pipeline.api.keras.layers.self_attention.TransformerLayer(n_block, hidden_drop, attn_drop, n_head, initializer_range, bidirectional, output_all_block, embedding_layer, input_shape, intermediate_size=0, bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

A self attention layer

Input is a list which consists of 2 ndarrays. 1. Token id ndarray: shape [batch, seqLen] with the word token indices in the vocabulary 2. Position id ndarray: shape [batch, seqLen] with positions in the sentence. Output is a list which contains: 1. The states of Transformer layer. 2. The pooled output which processes the hidden state of the last layer with regard to the first token of the sequence. This would be useful for segment-level tasks.

# Arguments nBlock: block number hidden_drop: drop probability off projection attn_drop: drop probability of attention n_head: head number initializer_range: weight initialization range bidirectional: whether unidirectional or bidirectional output_all_block: whether output all blocks’ output embedding_layer: embedding layer input_shape: input shape

attn(q, k, v, scale=False, attention_mask=None)[source]
block(x, size, attention_mask=None, eplision=1e-05)[source]
build_input(input_shape)[source]
gelu(x)[source]
classmethod init(vocab=40990, seq_len=77, n_block=12, hidden_drop=0.1, attn_drop=0.1, n_head=12, hidden_size=768, embedding_drop=0.1, initializer_range=0.02, bidirectional=False, output_all_block=False)[source]

vocab: vocabulary size of training data, default is 40990 seq_len: max sequence length of training data, default is 77 n_block: block number, default is 12 hidden_drop: drop probability of projection, default is 0.1 attn_drop: drop probability of attention, default is 0.1 n_head: head number, default is 12 hidden_size: is also embedding size embedding_drop: drop probability of embedding layer, default is 0.1 initializer_range: weight initialization range, default is 0.02 bidirectional: whether unidirectional or bidirectional, default is unidirectional output_all_block: whether output all blocks’ output

merge_heads(x)[source]
mlp(x, hidden_size)[source]
multi_head_self_attention(x, size, attention_mask=None)[source]
pooler(x, hidden_size)[source]
projection_layer(output_size)[source]
split_heads(x, n_head, k=False)[source]
zoo.pipeline.api.keras.layers.self_attention.layer_norm(x, w, b, e=1e-05)[source]

zoo.pipeline.api.keras.layers.torch module

class zoo.pipeline.api.keras.layers.torch.AddConstant(constant, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Add a (non-learnable) scalar constant to the input.

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 constant: The scalar constant to be added. 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.
>>> addconstant = AddConstant(1, input_shape=(1, 4, 5))
creating: createZooKerasAddConstant
class zoo.pipeline.api.keras.layers.torch.BinaryThreshold(value=1e-06, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Threshold the input. If an input element is smaller than the threshold value, it will be replaced by 0; otherwise, it will be replaced by 1.

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 value: The threshold value to compare with. Default is 1e-6. 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.
>>> binarythreshold = BinaryThreshold(input_shape=(2, 3, 4, 5))
creating: createZooKerasBinaryThreshold
class zoo.pipeline.api.keras.layers.torch.CAdd(size, b_regularizer=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

This layer has a bias with given size. The bias will be added element-wise to the input. If the element number of the bias matches the input, a simple element-wise addition will be done. Or the bias will be expanded to the same size of the input. The expand means repeat on unmatched singleton dimension (if some unmatched dimension isn’t a singleton dimension, an error will be raised).

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 size: The size of the bias. b_regularizer: An instance of [[Regularizer]], applied to the bias. Default is null. 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.
>>> cadd = CAdd((2, 1), input_shape=(3, ))
creating: createZooKerasCAdd
class zoo.pipeline.api.keras.layers.torch.CMul(size, W_regularizer=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

This layer has a weight with given size. The weight will be multiplied element-wise to the input. If the element number of the weight matches the input, a simple element-wise multiplication will be done. Or the bias will be expanded to the same size of the input. The expand means repeat on unmatched singleton dimension (if some unmatched dimension isn’t singleton dimension, an error will be raised).

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 size: The size of the bias. W_regularizer: An instance of [[Regularizer]], (eg. L1 or L2 regularization),

applied to the input weights matrices. Default is null.

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.
>>> cmul = CMul((2, 1), input_shape=(3, ))
creating: createZooKerasCMul
class zoo.pipeline.api.keras.layers.torch.Exp(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies element-wise exp to the input.

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.
>>> exp = Exp(input_shape=(2, 3, 4))
creating: createZooKerasExp
class zoo.pipeline.api.keras.layers.torch.GaussianSampler(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Takes {mean, log_variance} as input and samples from the Gaussian distribution

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.

>>> gaussianSampler = GaussianSampler(input_shape=[(3,),(3,)])
creating: createZooKerasGaussianSampler
class zoo.pipeline.api.keras.layers.torch.HardShrink(value=0.5, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies the hard shrinkage function element-wise to the input.

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 value: The threshold value. Default is 0.5. 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.
>>> hardshrink = HardShrink(input_shape=(2, 4, 8))
creating: createZooKerasHardShrink
class zoo.pipeline.api.keras.layers.torch.HardTanh(min_value=-1, max_value=1, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies the hard tanh function element-wise to the input.

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 min_value: The minimum threshold value. Default is -1. max_value: The maximum threshold value. Default is 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.
>>> hardtanh = HardTanh(input_shape=(3, 4))
creating: createZooKerasHardTanh
class zoo.pipeline.api.keras.layers.torch.Identity(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Identity just return the input to output. It’s useful in same parallel container to get an origin input.

# 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.
>>> identity = Identity(input_shape=(3, ))
creating: createZooKerasIdentity
class zoo.pipeline.api.keras.layers.torch.LRN2D(alpha=0.0001, k=1.0, beta=0.75, n=5, dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Local Response Normalization between different feature maps.

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 alpha: Float. The scaling parameter. Default is 0.0001. k: Float. A constant. beta: Float. The exponent. Default is 0.75. n: The number of channels to sum over. dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

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.
>>> lrn2d = LRN2D(1e-3, 1.2, 0.4, 4, dim_ordering="tf", input_shape=(4, 5, 6))
creating: createZooKerasLRN2D
class zoo.pipeline.api.keras.layers.torch.Log(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies a log transformation to the input.

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.
>>> log = Log(input_shape=(4, 8, 8))
creating: createZooKerasLog
class zoo.pipeline.api.keras.layers.torch.Mul(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Multiply a single scalar factor to the input.

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.
>>> mul = Mul(input_shape=(3, 4, 5))
creating: createZooKerasMul
class zoo.pipeline.api.keras.layers.torch.MulConstant(constant, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Multiply the input by a (non-learnable) scalar constant.

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 constant: The scalar constant to be multiplied. 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.
>>> mulconstant = MulConstant(2.2, input_shape=(3, 4))
creating: createZooKerasMulConstant
class zoo.pipeline.api.keras.layers.torch.Narrow(dim, offset, length=1, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Narrow the input with the number of dimensions not being reduced. The batch dimension needs to be unchanged. For example, if input is: [[1 2 3], [4 5 6]] Narrow(1, 1, 2) will give output [[2 3], [5 6]] Narrow(1, 2, -1) will give output [[3], [6]]

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 dim: The dimension to narrow. 0-based index. Cannot narrow the batch dimension.

-1 means the last dimension of the input.

offset: Non-negative integer. The start index on the given dimension. 0-based index. length: The length to narrow. Default is 1.

Can use a negative length such as -1 in the case where input size is unknown.

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.
>>> narrow = Narrow(1, 3, input_shape=(5, 6, 7), name="narrow1")
creating: createZooKerasNarrow
class zoo.pipeline.api.keras.layers.torch.Negative(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Computes the negative value of each element of the input.

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.
>>> negative = Negative(input_shape=(4, 5, 8))
creating: createZooKerasNegative
class zoo.pipeline.api.keras.layers.torch.PReLU(n_output_plane=0, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies parametric ReLU, where parameter varies the slope of the negative part.

Notice: Please don’t use weight decay on this.

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 n_output_plane: Input map number. Default is 0,

which means using PReLU in shared version and has only one parameter.

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.
>>> prelu = PReLU(input_shape=(3, 4, 8, 8))
creating: createZooKerasPReLU
class zoo.pipeline.api.keras.layers.torch.Power(power, scale=1, shift=0, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies an element-wise power operation with scale and shift to the input.

f(x) = (shift + scale * x)^power^

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 power: The exponent. scale: The scale parameter. Default is 1. shift: The shift parameter. Default is 0. 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.
>>> power = Power(3, input_shape=(3, ))
creating: createZooKerasPower
class zoo.pipeline.api.keras.layers.torch.RReLU(lower=0.125, upper=0.3333333333333333, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies the randomized leaky rectified linear unit element-wise to the input.

In the training mode, negative inputs are multiplied by a factor drawn from a uniform random distribution U(l, u). In the evaluation mode, a RReLU behaves like a LeakyReLU with a constant mean factor a = (l + u) / 2. If l == u, a RReLU essentially becomes a LeakyReLU. Regardless of operating in in-place mode a RReLU will internally allocate an input-sized noise tensor to store random factors for negative inputs. For reference see [Empirical Evaluation of Rectified Activations in Convolutional Network](http://arxiv.org/abs/1505.00853).

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 lower: Lower boundary of the uniform random distribution. Default is 1.0/8. upper: Upper boundary of the uniform random distribution. Default is 1.0/3. 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.
>>> rrelu = RReLU(input_shape=(3, 4))
creating: createZooKerasRReLU
class zoo.pipeline.api.keras.layers.torch.ResizeBilinear(output_height, output_width, align_corner=False, dim_ordering='th', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Resize the input image with bilinear interpolation. The input image must be a float tensor with NHWC or NCHW layout

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 output_height: output height output_width: output width align_corner: align corner or not dim_ordering: Format of input data. Either ‘th’ (Channel First) or ‘tf’ (Channel Last).

Default is ‘th’.

input_shape: A shape tuple, not including batch.

>>> resizeBilinear = ResizeBilinear(10, 20, input_shape=(2, 3, 5, 7))
creating: createZooKerasResizeBilinear
class zoo.pipeline.api.keras.layers.torch.Scale(size, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Scale is the combination of CMul and CAdd.

Computes the element-wise product of the input and weight, with the shape of the weight “expand” to match the shape of the input. Similarly, perform an expanded bias and perform an element-wise add.

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 size: Size of the weight and bias. 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.
>>> scale = Scale((2, 1), input_shape=(3, ))
creating: createZooKerasScale
class zoo.pipeline.api.keras.layers.torch.Select(dim, index, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Select an index of the input in the given dim and return the subset part. The batch dimension needs to be unchanged. The returned tensor has one less dimension: the dimension dim is removed. As a result, it is not possible to select() on a 1D tensor. For example, if input is: [[1 2 3], [4 5 6]] Select(1, 1) will give output [2 5] Select(1, -1) will give output [3 6]

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 dim: The dimension to select. 0-based index. Cannot select the batch dimension.

-1 means the last dimension of the input.
index: The index of the dimension to be selected. 0-based index.
-1 means the last dimension of the input.

input_shape: A shape tuple, not including batch. name: String to set the name of the wrapper.

If not specified, its name will by default to be a generated string.
>>> select = Select(0, -1, input_shape=(3, 4), name="select1")
creating: createZooKerasSelect
class zoo.pipeline.api.keras.layers.torch.SelectTable(index, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Creates a module that takes a list of JTensors as input and outputs the element at index index

# Arguments index: the index to be selected. 0-based index input_shape: a list of shape tuples, not including batch.

>>> selectTable = SelectTable(0, input_shape=[[2, 3], [5, 7]])
creating: createZooKerasSelectTable
zoo.pipeline.api.keras.layers.torch.ShareConv2D

alias of zoo.pipeline.api.keras.layers.torch.ShareConvolution2D

class zoo.pipeline.api.keras.layers.torch.ShareConvolution2D(nb_filter, nb_row, nb_col, init='glorot_uniform', activation=None, subsample=(1, 1), pad_h=0, pad_w=0, propagate_back=True, dim_ordering='th', W_regularizer=None, b_regularizer=None, bias=True, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies a 2D convolution over an input image composed of several input planes. You can also use ShareConv2D as an alias of this layer. Data format currently supported for this layer is dim_ordering=’th’ (Channel First). 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). e.g. input_shape=(3, 128, 128) for 128x128 RGB pictures.

# Arguments nb_filter: Number of convolution filters to use. nb_row: Number of rows in the convolution kernel. nb_col: Number of cols in the convolution kernel. init: 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.
subsample: Int tuple of length 2 corresponding to the step of the convolution in the
height and width dimension. Also called strides elsewhere. Default is (1, 1).

pad_h: The additional zeros added to the height dimension. Default is 0. pad_w: The additional zeros added to the width dimension. Default is 0. propagate_back: Whether to propagate gradient back. Default is True. dim_ordering: Format of input data. Only ‘th’ (Channel First) is supported for now. W_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: 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.
>>> shareconv2d = ShareConvolution2D(32, 3, 4, activation="tanh", input_shape=(3, 128, 128))
creating: createZooKerasShareConvolution2D
class zoo.pipeline.api.keras.layers.torch.SoftShrink(value=0.5, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies the soft shrinkage function element-wise to the input.

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 value: The threshold value. Default is 0.5. 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.
>>> softshrink = SoftShrink(input_shape=(4, 4, 8, 8))
creating: createZooKerasSoftShrink
class zoo.pipeline.api.keras.layers.torch.Sqrt(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies an element-wise square root operation to the input.

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.
>>> sqrt = Sqrt(input_shape=(3, ))
creating: createZooKerasSqrt
class zoo.pipeline.api.keras.layers.torch.Square(input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Applies an element-wise square operation to the input.

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.
>>> square = Square(input_shape=(5, ))
creating: createZooKerasSquare
class zoo.pipeline.api.keras.layers.torch.Squeeze(dim=None, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Delete the singleton dimension(s). The batch dimension needs to be unchanged. For example, if input has size (2, 1, 3, 4, 1): Squeeze(1) will give output size (2, 3, 4, 1) Squeeze() will give output size (2, 3, 4)

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 dim: The dimension(s) to squeeze. Can be either int or tuple of int.

0-based index. Cannot squeeze the batch dimension. The selected dimensions must be singleton, i.e. having size 1. Default is None, and in this case all the non-batch singleton dimensions will be deleted.

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.
>>> squeeze1 = Squeeze(1, input_shape=(1, 4, 5))
creating: createZooKerasSqueeze
>>> squeeze2 = Squeeze(input_shape=(1, 8, 1, 4))
creating: createZooKerasSqueeze
>>> squeeze3 = Squeeze((1, 2), input_shape=(1, 1, 1, 32))
creating: createZooKerasSqueeze
class zoo.pipeline.api.keras.layers.torch.Threshold(th=1e-06, v=0.0, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Threshold input Tensor. If values in the Tensor smaller than or equal to th, then replace it with v. 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 th: The threshold value to compare with. Default is 1e-6. v: the value to replace with. 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.
>>> threshold = Threshold(input_shape=(2, 3, 4, 5))
creating: createZooKerasThreshold
class zoo.pipeline.api.keras.layers.torch.WithinChannelLRN2D(size=5, alpha=1.0, beta=0.75, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

The local response normalization layer performs a kind of “lateral inhibition” by normalizing over local input regions. The local regions extend spatially, in separate channels (i.e., they have shape 1 x size x 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 size: The side length of the square region to sum over. Default is 5. alpha: The scaling parameter. Default is 1.0. beta: The exponent. Default is 0.75. 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.
>>> withinchannellrn2d = WithinChannelLRN2D(input_shape=(2, 3, 8, 8))
creating: createZooKerasWithinChannelLRN2D

zoo.pipeline.api.keras.layers.wrappers module

class zoo.pipeline.api.keras.layers.wrappers.Bidirectional(layer, merge_mode='concat', input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Bidirectional wrapper for RNNs. Bidirectional currently requires RNNs to return the full sequence, i.e. return_sequences = True.

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). Example of creating a bidirectional LSTM: Bidirectiona(LSTM(12, return_sequences=True), merge_mode=”sum”, input_shape=(32, 32))

# Arguments layer: An instance of a recurrent layer. merge_mode: Mode by which outputs of the forward and backward RNNs will be combined.

Must be one of: ‘sum’, ‘mul’, ‘concat’, ‘ave’. Default is ‘concat’.

input_shape: A shape tuple, not including batch. name: String to set the name of the wrapper.

If not specified, its name will by default to be a generated string.
>>> from zoo.pipeline.api.keras.layers import LSTM
>>> bidiretional = Bidirectional(LSTM(10, return_sequences=True), input_shape=(12, 16))
creating: createZooKerasLSTM
creating: createZooKerasBidirectional
class zoo.pipeline.api.keras.layers.wrappers.KerasLayerWrapper(torch_layer, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

Wrap a torch style layer to keras style layer. This layer can be built multiple times. This layer will return a keras compatible layer

# Arguments torch_layer: a torch style layer. input_shape: A shape tuple, not including batch. i.e If the input data is (2, 3, 4) and 2 is the batch size, you should input: (3, 4) here. >>> from zoo.pipeline.api.keras.layers import KerasLayerWrapper >>> from bigdl.nn.layer import Linear >>> linear = Linear(100, 10, with_bias=True) creating: createLinear >>> kerasLayer = KerasLayerWrapper(linear, input_shape=(100, )) creating: createZooKerasKerasLayerWrapper

class zoo.pipeline.api.keras.layers.wrappers.TimeDistributed(layer, input_shape=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer

TimeDistributed wrapper. Apply a layer to every temporal slice of an input. The input should be at least 3D. The dimension of index one will be considered as the temporal dimension.

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). name: String to specify the name of the wrapper. Default is None.

# Arguments layer: A layer instance. input_shape: A shape tuple, not including batch. name: String to set the name of the wrapper.

If not specified, its name will by default to be a generated string.
>>> from zoo.pipeline.api.keras.layers import Dense
>>> timedistributed = TimeDistributed(Dense(8), input_shape=(10, 12))
creating: createZooKerasDense
creating: createZooKerasTimeDistributed

Module contents