zoo.pipeline.api.keras package

Submodules

zoo.pipeline.api.keras.base module

class zoo.pipeline.api.keras.base.InferShape(bigdl_type='float')[source]

Bases: bigdl.util.common.JavaValue

get_input_shape()[source]

Return a list of shape tuples if there are multiple inputs. Return one shape tuple otherwise.

get_output_shape()[source]

Return a list of shape tuples if there are multiple outputs. Return one shape tuple otherwise.

class zoo.pipeline.api.keras.base.ZooCallable[source]

Bases: object

class zoo.pipeline.api.keras.base.ZooKerasCreator(jvalue, bigdl_type, *args)[source]

Bases: bigdl.util.common.JavaValue

jvm_class_constructor()[source]
class zoo.pipeline.api.keras.base.ZooKerasLayer(jvalue, *args, **kwargs)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, zoo.pipeline.api.keras.base.ZooCallable, bigdl.nn.layer.Layer, zoo.pipeline.api.keras.base.InferShape

get_weights_shape()[source]
Returns:None if without weights
classmethod of(jvalue, bigdl_type='float')[source]

Create a Python Layer base on the given java value and the real type. :param jvalue: Java object create by Py4j :return: A Python Layer

set_weights(weights)[source]

Set weights for this layer

Parameters:weights – a list of numpy arrays which represent weight and bias

zoo.pipeline.api.keras.metrics module

class zoo.pipeline.api.keras.metrics.AUC(threshold_num=200, bigdl_type='float')[source]

Bases: bigdl.util.common.JavaValue

Metric for binary(0/1) classification, support single label and multiple labels.

# Arguments threshold_num: The number of thresholds. The quality of approximation

may vary depending on threshold_num.
>>> meter = AUC(20)
creating: createAUC
class zoo.pipeline.api.keras.metrics.Accuracy(zero_based_label=True, bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, bigdl.util.common.JavaValue

Measures top1 accuracy for multi-class classification or accuracy for binary classification.

# Arguments zero_based_label: Boolean. Whether target labels start from 0. Default is True.

If False, labels start from 1. Note that this only takes effect for multi-class classification. For binary classification, labels ought to be 0 or 1.
>>> acc = Accuracy()
creating: createZooKerasAccuracy
class zoo.pipeline.api.keras.metrics.BinaryAccuracy(bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, bigdl.util.common.JavaValue

Measures top1 accuracy for binary classification with zero-based index.

>>> acc = BinaryAccuracy()
creating: createZooKerasBinaryAccuracy
class zoo.pipeline.api.keras.metrics.CategoricalAccuracy(bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, bigdl.util.common.JavaValue

Measures top1 accuracy for multi-class classification when target is one-hot encoded.

>>> acc = CategoricalAccuracy()
creating: createZooKerasCategoricalAccuracy
class zoo.pipeline.api.keras.metrics.MAE(bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, bigdl.util.common.JavaValue

Metric for mean absoluate error, similar from MAE criterion

>>> mae = MAE()
creating: createZooKerasMAE
class zoo.pipeline.api.keras.metrics.SparseCategoricalAccuracy(bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, bigdl.util.common.JavaValue

Measures top1 accuracy for multi-class classification with sparse target.

>>> acc = SparseCategoricalAccuracy()
creating: createZooKerasSparseCategoricalAccuracy
class zoo.pipeline.api.keras.metrics.Top5Accuracy(zero_based_label=True, bigdl_type='float')[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, bigdl.util.common.JavaValue

Measures top5 accuracy for multi-class classification.

# Arguments zero_based_label: Boolean. Whether target labels start from 0. Default is True.

If False, labels start from 1.
>>> acc = Top5Accuracy()
creating: createZooKerasTop5Accuracy

zoo.pipeline.api.keras.models module

class zoo.pipeline.api.keras.models.Model(input, output, jvalue=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.engine.topology.KerasNet

Container for a graph model.

# Arguments input: An input node or a list of input nodes. output: An output node or a list of output nodes. name: String to specify the name of the graph model. Default is None.

freeze_up_to(names)[source]
static from_jvalue(jvalue, bigdl_type='float')[source]

Create a Python Model base on the given java value :param jvalue: Java object create by Py4j :return: A Python Model

new_graph(outputs)[source]
save_graph_topology(log_path, backward=False)[source]

Save the current model graph to a folder, which can be displayed in TensorBoard by running the command: tensorboard –logdir log_path

# Arguments log_path: The path to save the model graph. backward: The name of the application.

unfreeze(names)[source]

unfreeze module, if names is not None, unfreeze layers that match given names :param names: an array of layer names :return:

class zoo.pipeline.api.keras.models.Sequential(jvalue=None, **kwargs)[source]

Bases: zoo.pipeline.api.keras.engine.topology.KerasNet

Container for a sequential model.

# Arguments name: String to specify the name of the sequential model. Default is None.

>>> sequential = Sequential(name="seq1")
creating: createZooKerasSequential
add(model)[source]
static from_jvalue(jvalue, bigdl_type='float')[source]

Create a Python Model base on the given java value :param jvalue: Java object create by Py4j :return: A Python Model

is_built()[source]

zoo.pipeline.api.keras.objectives module

class zoo.pipeline.api.keras.objectives.BinaryCrossEntropy(weights=None, size_average=True, bigdl_type='float')[source]

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

A loss that measures the Binary Cross Entropy between the target and the output

# Arguments size_average: Boolean. Whether losses are averaged over observations for each

mini-batch. Default is True. If False, the losses are instead summed for each mini-batch.

weights: weights over the input dimension

>>> loss = BinaryCrossEntropy()
creating: createZooKerasBinaryCrossEntropy
class zoo.pipeline.api.keras.objectives.CategoricalCrossEntropy(bigdl_type='float')[source]

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

This is same with cross entropy criterion, except the target tensor is a one-hot tensor

>>> loss = CategoricalCrossEntropy()
creating: createZooKerasCategoricalCrossEntropy
class zoo.pipeline.api.keras.objectives.CosineProximity(bigdl_type='float')[source]

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

The negative of the mean cosine proximity between predictions and targets. The cosine proximity is defined as below:

x’(i) = x(i) / sqrt(max(sum(x(i)^2), 1e-12)) y’(i) = y(i) / sqrt(max(sum(x(i)^2), 1e-12)) cosine_proximity(x, y) = mean(-1 * x’(i) * y’(i))
>>> loss = CosineProximity()
creating: createZooKerasCosineProximity
class zoo.pipeline.api.keras.objectives.Hinge(margin=1.0, size_average=True, bigdl_type='float')[source]

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

Creates a criterion that optimizes a two-class classification hinge loss (margin-based loss) between input x (a Tensor of dimension 1) and output y.

# Arguments: margin: Float. Default is 1.0. size_average: Boolean. Whether losses are averaged over observations for each

mini-batch. Default is True. If False, the losses are instead summed for each mini-batch.
>>> loss = Hinge()
creating: createZooKerasHinge
class zoo.pipeline.api.keras.objectives.KullbackLeiblerDivergence(bigdl_type='float')[source]

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

Loss calculated as:y_true = K.clip(y_true, K.epsilon(), 1) y_pred = K.clip(y_pred, K.epsilon(), 1) and output K.sum(y_true * K.log(y_true / y_pred), axis=-1)

>>> loss = KullbackLeiblerDivergence()
creating: createZooKerasKullbackLeiblerDivergence
class zoo.pipeline.api.keras.objectives.LossFunction(jvalue, bigdl_type, *args)[source]

Bases: zoo.pipeline.api.keras.base.ZooKerasCreator, bigdl.nn.criterion.Criterion

The base class for Keras-style API objectives in Analytics Zoo.

classmethod of(jloss, bigdl_type='float')[source]

Create a Python LossFunction from a JavaObject.

# Arguments jloss: A java criterion object which created by Py4j

zoo.pipeline.api.keras.objectives.MAE

alias of zoo.pipeline.api.keras.objectives.MeanAbsoluteError

zoo.pipeline.api.keras.objectives.MAPE

alias of zoo.pipeline.api.keras.objectives.MeanAbsolutePercentageError

zoo.pipeline.api.keras.objectives.MSE

alias of zoo.pipeline.api.keras.objectives.MeanSquaredError

zoo.pipeline.api.keras.objectives.MSLE

alias of zoo.pipeline.api.keras.objectives.MeanSquaredLogarithmicError

class zoo.pipeline.api.keras.objectives.MeanAbsoluteError(size_average=True, bigdl_type='float')[source]

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

A loss that measures the mean absolute value of the element-wise difference between the input and the target.

# Arguments size_average: Boolean. Whether losses are averaged over observations for each

mini-batch. Default is True. If False, the losses are instead summed for each mini-batch.
>>> loss = MeanAbsoluteError()
creating: createZooKerasMeanAbsoluteError
class zoo.pipeline.api.keras.objectives.MeanAbsolutePercentageError(bigdl_type='float')[source]

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

It caculates diff = K.abs((y - x) / K.clip(K.abs(y), K.epsilon(), Double.MaxValue)) and return 100 * K.mean(diff) as outpout

>>> loss = MeanAbsolutePercentageError()
creating: createZooKerasMeanAbsolutePercentageError
class zoo.pipeline.api.keras.objectives.MeanSquaredError(size_average=True, bigdl_type='float')[source]

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

A loss that measures the mean squared value of the element-wise difference between the input and the target.

# Arguments size_average: Boolean. Whether losses are averaged over observations for each

mini-batch. Default is True. If False, the losses are instead summed for each mini-batch.
>>> loss = MeanSquaredError()
creating: createZooKerasMeanSquaredError
class zoo.pipeline.api.keras.objectives.MeanSquaredLogarithmicError(bigdl_type='float')[source]

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

It calculates: first_log = K.log(K.clip(y, K.epsilon(), Double.MaxValue) + 1.) second_log = K.log(K.clip(x, K.epsilon(), Double.MaxValue) + 1.) and output K.mean(K.square(first_log - second_log))

>>> loss = MeanSquaredLogarithmicError()
creating: createZooKerasMeanSquaredLogarithmicError
class zoo.pipeline.api.keras.objectives.Poisson(bigdl_type='float')[source]

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

Loss calculated as: K.mean(y_pred - y_true * K.log(y_pred + K.epsilon()), axis=-1)

>>> loss = Poisson()
creating: createZooKerasPoisson
class zoo.pipeline.api.keras.objectives.RankHinge(margin=1.0, bigdl_type='float')[source]

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

Hinge loss for pairwise ranking problems.

# Arguments: margin: Float. Default is 1.0.

>>> loss = RankHinge()
creating: createZooKerasRankHinge
class zoo.pipeline.api.keras.objectives.SparseCategoricalCrossEntropy(log_prob_as_input=False, zero_based_label=True, weights=None, size_average=True, padding_value=-1, bigdl_type='float')[source]

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

A loss often used in multi-class classification problems with SoftMax as the last layer of the neural network.

By default, same as Keras, input(y_pred) is supposed to be probabilities of each class, and target(y_true) is supposed to be the class label starting from 0.

# Arguments log_prob_as_input: Boolean. Whether to accept log-probabilities or probabilities

as input. Default is False and inputs should be probabilities.
zero_based_label: Boolean. Whether target labels start from 0. Default is True.
If False, labels start from 1.

weights: A Numpy array. Weights of each class if you have an unbalanced training set. size_average: Boolean. Whether losses are averaged over observations for each

mini-batch. Default is True. If False, the losses are instead summed for each mini-batch.
padding_value: Int. If the target is set to this value, the training process
will skip this sample. In other words, the forward process will return zero output and the backward process will also return zero grad_input. Default is -1.
>>> loss = SparseCategoricalCrossEntropy()
creating: createZooKerasSparseCategoricalCrossEntropy
>>> import numpy as np
>>> np.random.seed(1128)
>>> weights = np.random.uniform(0, 1, (2,)).astype("float32")
>>> loss = SparseCategoricalCrossEntropy(weights=weights)
creating: createZooKerasSparseCategoricalCrossEntropy
class zoo.pipeline.api.keras.objectives.SquaredHinge(margin=1.0, size_average=False, bigdl_type='float')[source]

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

Creates a criterion that optimizes a two-class classification squared hinge loss (margin-based loss) between input x (a Tensor of dimension 1) and output y.

# Arguments: margin: Float. Default is 1.0. size_average: Boolean. Whether losses are averaged over observations for each

mini-batch. Default is True. If False, the losses are instead summed for each mini-batch.
>>> loss = SquaredHinge()
creating: createZooKerasSquaredHinge
zoo.pipeline.api.keras.objectives.mae

alias of zoo.pipeline.api.keras.objectives.MeanAbsoluteError

zoo.pipeline.api.keras.objectives.mape

alias of zoo.pipeline.api.keras.objectives.MeanAbsolutePercentageError

zoo.pipeline.api.keras.objectives.mse

alias of zoo.pipeline.api.keras.objectives.MeanSquaredError

zoo.pipeline.api.keras.objectives.msle

alias of zoo.pipeline.api.keras.objectives.MeanSquaredLogarithmicError

zoo.pipeline.api.keras.optimizers module

class zoo.pipeline.api.keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0, schedule=None, weight_decay=0.0, bigdl_type='float')[source]

Bases: bigdl.optim.optimizer.OptimMethod, zoo.pipeline.api.keras.base.ZooKerasCreator

An implementation of Adam with learning rate schedule. >>> adam = Adam() creating: createZooKerasAdam creating: createDefault

class zoo.pipeline.api.keras.optimizers.AdamWeightDecay(lr=0.001, warmup_portion=-1.0, total=-1, schedule='linear', beta1=0.9, beta2=0.999, epsilon=1e-06, weight_decay=0.01, bigdl_type='float')[source]

Bases: bigdl.optim.optimizer.OptimMethod, zoo.pipeline.api.keras.base.ZooKerasCreator

Implements BERT version of Adam algorithm. >>> adam = AdamWeightDecay() creating: createZooKerasAdamWeightDecay

class zoo.pipeline.api.keras.optimizers.PolyEpochDecay(power, max_epochs, bigdl_type='float')[source]

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

A learning rate decay policy, where the effective learning rate follows a polynomial decay, to be zero by the max_epochs. Calculation: init_lr * (1 - epoch/max_iteration) ^ (power)

Parameters:
  • power – The coefficient of decay.
  • max_epochs – The maximum number of epochs when lr becomes zero.
>>> poly = PolyEpochDecay(0.5, 5)
creating: createZooKerasPolyEpochDecay

zoo.pipeline.api.keras.regularizers module

zoo.pipeline.api.keras.regularizers.l1(l1=0.01)[source]
zoo.pipeline.api.keras.regularizers.l1l2(l1=0.01, l2=0.01)[source]
zoo.pipeline.api.keras.regularizers.l2(l2=0.01)[source]

zoo.pipeline.api.keras.utils module

zoo.pipeline.api.keras.utils.to_bigdl_criterion(criterion)[source]
zoo.pipeline.api.keras.utils.to_bigdl_metric(metric, loss)[source]
zoo.pipeline.api.keras.utils.to_bigdl_metrics(metrics, loss)[source]
zoo.pipeline.api.keras.utils.to_bigdl_optim_method(optimizer)[source]

Module contents