Keras

Higher-level layer abstractions built on TF Encrypted.

class tf_encrypted.keras.Sequential(layers=None, name=None)[source]

Model defined by a stack of layers in sequence.

TODO

add(layer)[source]

Adds a layer instance on top of the layer stack.

Parameters

layer – layer instance.

Raises
  • TypeError – If layer is not a layer instance.

  • ValueError – In case the layer argument does not know its input shape.

  • ValueError – In case the layer argument has multiple output tensors, or is already connected somewhere else (forbidden in Sequential models).

call(inputs, training=None, mask=None)[source]

This is where the layer’s logic lives. :param inputs: Input tensor, or list/tuple of input tensors.

Returns

A tensor or list/tuple of tensors.

compile(optimizer, loss)[source]

Configures the model for training.

Parameters
  • optimizer – Optimizer instance

  • loss – Objective function

fit(x, y, epochs=1, steps_per_epoch=1)[source]

Trains the model for a given number of epochs (iterations on a dataset).

Parameters
  • x – Private tensor of training data

  • y – Private tensor of target (label) data

  • epochs – Integer. Number of epochs to train the model.

  • steps_per_epoch – Integer. Total number of steps (batches of samples) before declaring one epoch finished and starting the next epoch.

fit_batch(x, y)[source]

Trains the model on a single batch.

Parameters
  • x – Private tensor of training data

  • y – Private tensor of target (label) data

classmethod from_config(config)[source]

Instantiates a TFE Keras model from its config.

Parameters

config – Configuration dictionary matching the output of model.get_weights().

Returns

A TFE Keras Sequential instance.

property layers

Historically, sequential.layers only returns layers that were added via add, and omits the auto-generated InputLayer that comes at the bottom of the stack.

set_weights(weights, sess=None)[source]

Sets the weights of the model.

Parameters
  • weights – A list of Numpy arrays with shapes and types matching the output of model.get_weights()

  • sess – tfe.Session instance.