zoo.pipeline.api package

Subpackages

Submodules

zoo.pipeline.api.autograd module

class zoo.pipeline.api.autograd.Constant(data, name=None, bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, zoo.pipeline.api.autograd.VariableOperator

A constant Variable without weights. :param data: value of the Variable. :param name: Optional. Name of the Variable

class zoo.pipeline.api.autograd.CustomLoss(loss_func, y_pred_shape, y_true_shape=None)[source]

Bases: zoo.pipeline.api.keras.objectives.LossFunction

backward(y_true, y_pred)[source]

NB: It’s for debug only, please use optimizer.optimize() in production. Performs a back-propagation step through the criterion, with respect to the given input.

Parameters:
  • input – ndarray or list of ndarray
  • target – ndarray or list of ndarray
Returns:

ndarray

forward(y_true, y_pred)[source]

NB: It’s for debug only, please use optimizer.optimize() in production. Takes an input object, and computes the corresponding loss of the criterion, compared with target

Parameters:
  • input – ndarray or list of ndarray
  • target – ndarray or list of ndarray
Returns:

value of loss

class zoo.pipeline.api.autograd.Lambda(function, input_shape=None, bigdl_type='float')[source]

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

Used for evaluating an arbitrary expressions on an input.

# Examples

```python
# add a x -> x + 2 layer model.add(Lambda(lambda x: x + 2))

``` # Arguments

function: The function to be evaluated.
Takes input tensor as first argument.
# Input shape
Arbitrary. Use the keyword argument input_shape (tuple of integers, does not include the samples axis) when using this layer as the first layer in a model.
create(input_shapes)[source]
class zoo.pipeline.api.autograd.LambdaLayer(input_vars, out_var, input_shape=None, **kwargs)[source]

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

class zoo.pipeline.api.autograd.Parameter(shape, init_method=None, init_weight=None, trainable=True, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasLayer, zoo.pipeline.api.autograd.VariableOperator

A trainable Variable. The default init_method is RandomUniform(-0.05, 0.05). You can also specify the init_weight by passing a ndarray. :param shape: Shape of this Parameter :param init_method: A method used to initialize the Parameter.

The default value is RandomUniform(-0.05, 0.05)
Parameters:init_weight – A ndarray as the init value.

:param trainable It’s true by default, meaning the value would be updated by gradient.

get_weight()[source]
Returns:the ndarray for the current weight
set_weight(value)[source]
Parameters:value – value is a ndarray
Returns:
shape
class zoo.pipeline.api.autograd.Variable(input_shape, node=None, jvalue=None, name=None)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, zoo.pipeline.api.autograd.VariableOperator

classmethod from_node(node)[source]
node
set_name(name)[source]
class zoo.pipeline.api.autograd.VariableOperator[source]

Bases: object

add(var)[source]
static from_jvalue(jvalue)[source]
get_input_shape()[source]
get_output_shape()[source]
index_select(dim, index)[source]
Select an index of the input in the given dim and return the subset part. The batch dimension needs to be unchanged. The selected dim would be remove after this operation. 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]
Parameters:
  • 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.
Returns:

shape
slice(dim, start_index, length)[source]

Same as narrow in Torch. Slice 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 slice(1, 1, 2) will give output 2 3 5 6 slice(1, 2, -1) will give output 3 6 :param dim The dimension to narrow. 0-based index. Cannot narrow the batch dimension.

-1 means the last dimension of the input.
:param startIndex Non-negative integer.
The start index on the given dimension. 0-based index.

:param length The length to be sliced. Default is 1.

squeeze(dim=None)[source]

Delete the singleton dimension(s). The dim can be zero, and if so you would change the batch dim. For example, if input has size (2, 1, 3, 4, 1): Squeeze(dim = 1) will give output size (2, 3, 4, 1) Squeeze(dims = null) will give output size (2, 3, 4)

sub(var)[source]
zoo.pipeline.api.autograd.abs(x)[source]

Element-wise absolute value. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.batch_dot(x, y, axes=1, normalize=False)[source]

Operator that computes a dot product between samples in two tensors.

E.g. if applied to two tensors a and b of shape (batch_size, n), the output will be a tensor of shape (batch_size, 1) where each entry i will be the dot product between a[i] and b[i].

Parameters:
  • x – Shape should only be [batch, xx]
  • y – Shape should only be [batch, xx]
  • axes – Integer or tuple of integers, axis or axes along which to take the dot product.
  • normalize – Whether to L2-normalize samples along the dot product axis before taking the dot product. If set to True, then the output of the dot product is the cosine proximity between the two samples.
Returns:

A variable.

zoo.pipeline.api.autograd.clip(x, min, max)[source]

Element-wise value clipping. :param x: A variable. :param min: Python float or integer. :param max: Python float or integer. :return: A variable.

zoo.pipeline.api.autograd.contiguous(x)[source]

Turn the output and grad to be contiguous for the input Variable :param x: A variable.

zoo.pipeline.api.autograd.epsilon()[source]

Define the value of epsilon. :return: A value of type Double.

zoo.pipeline.api.autograd.erf(x)[source]

Computes the error function(Gauss error function) of each element. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.exp(x)[source]

Element-wise exponential. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.expand_dims(x, axis)[source]
Adds a 1-sized dimension at index “axis”.
param x:a Variable to be expanded
param axis:axis Position where to add a new axis.

The axis is 0 based and if you set the axis to 0, you would change the batch dim.

zoo.pipeline.api.autograd.l2_normalize(x, axis)[source]

Normalizes a tensor wrt the L2 norm alongside the specified axis. :param x: A variable. Shape should only be [batch, xx] :param axis: axis along which to perform normalization. :return: A variable.

zoo.pipeline.api.autograd.log(x)[source]

Element-wise log. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.maximum(x, y)[source]

Element-wise maximum of two variables. :param x: A variable. :param y: A variable. :return: A variable.

zoo.pipeline.api.autograd.mean(x, axis=0, keepDims=False)[source]

Mean of a variable, alongside the specified axis. :param x: A variable. :param axis: A list of integer. Axes to compute the mean. :param keepDims: A boolean, whether to keep the dimensions or not.

If keepDims is False, the rank of the variable is reduced by 1 for each entry in axis. If keepDims is True, the reduced dimensions are retained with length 1.
Returns:A variable with the mean of elements of x.
zoo.pipeline.api.autograd.mm(x, y, axes=None)[source]

Module to perform matrix multiplication on two mini-batch inputs, producing a mini-batch. :param x: A variable. :param y: A variable. :param axes: Axes along which to perform multiplication. :return: A variable.

zoo.pipeline.api.autograd.neg(x)[source]

Computes numerical negative value element-wise. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.pow(x, a)[source]

Element-wise exponentiation. :param x: A variable. :param a: Python integer. :return: A variable.

zoo.pipeline.api.autograd.softplus(x)[source]

Softplus of a variable. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.softsign(x)[source]

Softsign of a variable. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.sqrt(x)[source]

Element-wise square root. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.square(x)[source]

Element-wise square. :param x: A variable. :return: A variable.

zoo.pipeline.api.autograd.stack(inputs, axis=1)[source]

Stacks a list of rank R tensors into a rank R+1 tensor. You should start from 1 as dim 0 is for batch. :param inputs: List of variables (tensors). :param axis: axis along which to perform stacking. :return:

zoo.pipeline.api.autograd.sum(x, axis=0, keepDims=False)[source]

Sum of the values in a a variable, alongside the specified axis. :param x: A variable. :param axis: An integer. Axes to compute the sum over. :param keepDims: A boolean, whether to keep the dimensions or not.

If keepDims is False, the rank of the variable is reduced by 1 for each entry in axis. If keepDims is True, the reduced dimensions are retained with length 1.
Returns:A variable with sum of x.

zoo.pipeline.api.utils module

zoo.pipeline.api.utils.remove_batch(shape)[source]
zoo.pipeline.api.utils.toMultiShape(shape)[source]

Module contents