zoo.pipeline.api.keras.engine package¶
Submodules¶
zoo.pipeline.api.keras.engine.topology module¶
-
class
zoo.pipeline.api.keras.engine.topology.Input(shape=None, name=None, bigdl_type='float')[source]¶ Bases:
zoo.pipeline.api.autograd.VariableUsed to instantiate an input node.
# Arguments 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.>>> input = Input(name="input1", shape=(3, 5)) creating: createZooKerasInput
-
class
zoo.pipeline.api.keras.engine.topology.InputLayer(input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras.base.ZooKerasLayerUsed as an entry point into a model.
# 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.>>> inputlayer = InputLayer(input_shape=(3, 5), name="input1") creating: createZooKerasInputLayer
-
class
zoo.pipeline.api.keras.engine.topology.KerasNet(jvalue, *args, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras.base.ZooKerasLayer-
clear_gradient_clipping()[source]¶ Clear gradient clipping parameters. In this case, gradient clipping will not be applied. In order to take effect, it needs to be called before fit.
-
compile(optimizer, loss, metrics=None)[source]¶ Configure the learning process. It MUST be called before fit or evaluate.
# Arguments optimizer: Optimization method to be used. One can alternatively pass in the corresponding
string representation, such as ‘sgd’.- loss: Criterion to be used. One can alternatively pass in the corresponding string
- representation, such as ‘mse’.
- metrics: List of validation methods to be used. Default is None if no validation is needed.
- For convenience, string representations are supported: ‘accuracy’ (or ‘acc’), ‘top5accuracy’ (or ‘top5acc’), ‘mae’, ‘auc’, ‘treennaccuracy’ and ‘loss’. For example, you can either use [Accuracy()] or [‘accuracy’].
-
evaluate(x, y=None, batch_size=32)[source]¶ Evaluate a model on a given dataset in distributed mode.
# Arguments x: Evaluation data. A Numpy array or RDD of Sample or ImageSet or TextSet. y: Labels. A Numpy array.
Default is None if x is already Sample RDD or ImageSet or TextSet.batch_size: Number of samples per batch. Default is 32.
-
fit(x, y=None, batch_size=32, nb_epoch=10, validation_split=0, validation_data=None, distributed=True)[source]¶ Train a model for a fixed number of epochs on a DataSet.
# Arguments x: Input data. A Numpy array or RDD of Sample, ImageSet or TextSet. y: Labels. A Numpy array. Default is None if x is already Sample RDD or ImageSet or TextSet. batch_size: Number of samples per gradient update. Default is 32. nb_epoch: Number of epochs to train. validation_data: Tuple (x_val, y_val) where x_val and y_val are both Numpy arrays.
Can also be RDD of Sample or ImageSet or TextSet. Default is None if no validation is involved.- distributed: Boolean. Whether to train the model in distributed mode or local mode.
- Default is True. In local mode, x and y must both be Numpy arrays.
-
forward(input)[source]¶ NB: It’s for debug only, please use optimizer.optimize() in production. Takes an input object, and computes the corresponding output of the module :param input: ndarray or list of ndarray :param input: ndarray or list of ndarray or JTensor or list of JTensor. :return: ndarray or list of ndarray
-
get_train_summary(tag=None)[source]¶ Get the scalar from model train summary Return 2-D array like object which could be converted by nd.array() # Arguments tag: The string variable represents the scalar wanted
-
get_validation_summary(tag=None)[source]¶ Get the scalar from model validation summary Return 2-D array like object which could be converted by np.array()
Note: The metric and tag may not be consistent Please look up following form to pass tag parameter Left side is your metric during compile Right side is the tag you should pass ‘Accuracy’ | ‘Top1Accuracy’ ‘BinaryAccuracy’ | ‘Top1Accuracy’ ‘CategoricalAccuracy’ | ‘Top1Accuracy’ ‘SparseCategoricalAccuracy’ | ‘Top1Accuracy’ ‘AUC’ | ‘AucScore’ ‘HitRatio’ | ‘HitRate@k’ (k is Top-k) ‘Loss’ | ‘Loss’ ‘MAE’ | ‘MAE’ ‘NDCG’ | ‘NDCG’ ‘TFValidationMethod’ | ‘${name + ” ” + valMethod.toString()}’ ‘Top5Accuracy’ | ‘Top5Accuracy’ ‘TreeNNAccuracy’ | ‘TreeNNAccuracy()’ ‘MeanAveragePrecision’ | ‘MAP@k’ (k is Top-k) (BigDL) ‘MeanAveragePrecision’ | ‘PascalMeanAveragePrecision’ (Zoo) ‘StatelessMetric’ | ‘${name}’ # Arguments tag: The string variable represents the scalar wanted
-
layers¶
-
predict(x, batch_per_thread=4, distributed=True)[source]¶ Use a model to do prediction.
# Arguments x: Prediction data. A Numpy array or RDD of Sample or ImageSet. batch_per_thread:
The default value is 4. When distributed is True,the total batch size is batch_per_thread * rdd.getNumPartitions. When distributed is False the total batch size is batch_per_thread * numOfCores.- distributed: Boolean. Whether to do prediction in distributed mode or local mode.
- Default is True. In local mode, x must be a Numpy array.
-
predict_classes(x, batch_per_thread=4, zero_based_label=True)[source]¶ Use a model to predict for classes. By default, label predictions start from 0.
# Arguments x: Prediction data. A Numpy array or RDD of Sample. batch_per_partition:
The default value is 4. When distributed is True, the total batch size is batch_per_thread * rdd.getNumPartitions. When distributed is False the total batch size is batch_per_thread * numOfCores.- zero_based_label: Boolean. Whether result labels start from 0.
- Default is True. If False, result labels start from 1.
-
saveModel(modelPath, weightPath=None, over_write=False)[source]¶ Save this module to path with protobuf format. :param modelPath: The path to save module, local file system,
HDFS and Amazon S3 is supported. HDFS path should be like “hdfs://[host]:[port]/xxx” Amazon S3 path should be like “s3a://bucket/xxx”Parameters: - weightPath – The Path for the parameters
- over_write – override the existing model on modelPath or not.
-
set_checkpoint(path, over_write=True)[source]¶ Configure checkpoint settings to write snapshots every epoch during the training process. In order to take effect, it needs to be called before fit.
# Arguments path: The path to save snapshots. Make sure this path exists beforehand. over_write: Whether to overwrite existing snapshots in the given path. Default is True.
-
set_constant_gradient_clipping(min, max)[source]¶ Set constant gradient clipping during the training process. In order to take effect, it needs to be called before fit.
# Arguments min: The minimum value to clip by. Float. max: The maximum value to clip by. Float.
-
set_evaluate_status()[source]¶ Set the model to be in evaluate status, i.e. remove the effect of Dropout, etc.
-
set_gradient_clipping_by_l2_norm(clip_norm)[source]¶ Clip gradient to a maximum L2-Norm during the training process. In order to take effect, it needs to be called before fit.
# Arguments clip_norm: Gradient L2-Norm threshold. Float.
-
set_tensorboard(log_dir, app_name)[source]¶ Set summary information during the training process for visualization purposes. Saved summary can be viewed via TensorBoard. In order to take effect, it needs to be called before fit.
Training summary will be saved to ‘log_dir/app_name/train’ and validation summary (if any) will be saved to ‘log_dir/app_name/validation’.
# Arguments log_dir: The base directory path to store training and validation logs. app_name: The name of the application.
-
summary(line_length=120, positions=[0.33, 0.55, 0.67, 1.0])[source]¶ Print out the summary information of an Analytics Zoo Keras Model.
In addition, total number of parameters of this model, separated into trainable and non-trainable counts, will be printed out after the table.
# Arguments line_length The total length of one row. Default is 120. positions: The maximum absolute length proportion(%) of each field.
List of Float of length 4. Usually you don’t need to adjust this parameter. Default is [.33, .55, .67, 1.], meaning that the first field will occupy up to 33% of line_length, the second field will occupy up to (55-33)% of line_length, the third field will occupy up to (67-55)% of line_length, the fourth field will occupy the remaining line (100-67)%. If the field has a larger length, the remaining part will be trimmed. If the field has a smaller length, the remaining part will be white spaces.
-
-
class
zoo.pipeline.api.keras.engine.topology.Merge(layers=None, mode='sum', concat_axis=-1, input_shape=None, **kwargs)[source]¶ Bases:
zoo.pipeline.api.keras.base.ZooKerasLayerUsed to merge a list of inputs into a single output, following some merge mode. Merge must have at least two input layers.
When using this layer as the first layer in a model, you need to provide the argument input_shape for input layers (a list of shape tuples, does not include the batch dimension).
# Arguments layers: A list of layer instances. Must be more than one layer. mode: Merge mode. String, must be one of: ‘sum’, ‘mul’, ‘concat’, ‘ave’, ‘cos’,
‘dot’, ‘max’, ‘sub’, ‘div’, ‘min’. Default is ‘sum’.- concat_axis: Int, axis to use when concatenating layers.
- Only specify this when merge mode is ‘concat’. Default is -1, meaning the last axis of the input.
input_shape: A list of shape tuples, each 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.>>> l1 = InputLayer(input_shape=(3, 5)) creating: createZooKerasInputLayer >>> l2 = InputLayer(input_shape=(3, 5)) creating: createZooKerasInputLayer >>> merge = Merge(layers=[l1, l2], mode='sum', name="merge1") creating: createZooKerasMerge
-
zoo.pipeline.api.keras.engine.topology.merge(inputs, mode='sum', concat_axis=-1, name=None)[source]¶ Functional merge. Only use this method if you are defining a graph model. Used to merge a list of input nodes into a single output node (NOT layers!), following some merge mode.
# Arguments inputs: A list of node instances. Must be more than one node. mode: Merge mode. String, must be one of: ‘sum’, ‘mul’, ‘concat’, ‘ave’, ‘cos’,
‘dot’, ‘max’, ‘sub’, ‘div’, ‘min’. Default is ‘sum’.- concat_axis: Int, axis to use when concatenating nodes.
- Only specify this when merge mode is ‘concat’. Default is -1, meaning the last axis of the input.
- name: String to set the name of the functional merge.
- If not specified, its name will by default to be a generated string.