Layer

class dragon.vm.tensorflow.keras.layers.Layer(
  trainable=True,
  name=None,
  dtype=None,
  **kwargs
)[source]

The base class of layers.

Inherit this class to design a new layer:

class MyLayer(tf.keras.layers.Layer):
    def __init__():
        super(MyModule, self).__init__()

__init__

Layer.__init__(
  trainable=True,
  name=None,
  dtype=None,
  **kwargs
)[source]

Create a Layer.

Parameters:
  • trainable (bool, optional, default=True) The initial training flag.
  • name (str, optional) The layer name.
  • dtype (dragon.vm.tensorflow.dtypes.DType) The optional data type.

Properties

dtype

Layer.dtype

Return the data type.

Returns:
str The data type.

non_trainable_weights

Layer.non_trainable_weights

Return the non-trainable weights.

Returns:
Sequence[dragon.vm.tensorflow.Variable] The non-trainable weights.

trainable

Layer.trainable

Return the trainable indicator.

Returns:
bool True if trainable otherwise False.

trainable_weights

Layer.trainable_weights

Return the trainable weights.

Returns:
Sequence[dragon.vm.tensorflow.Variable] The trainable weights.

weights

Layer.weights

Return all the weights, both trainable and non-trainable.

Returns:
Sequence[dragon.vm.tensorflow.Variable] The weights.

Methods

add_weight

Layer.add_weight(
  name=None,
  shape=None,
  dtype=None,
  initializer=None,
  regularizer=None,
  trainable=True,
  use_resource=None,
  **kwargs
)[source]

Add a new variable as the weight.

Parameters:
  • name (str, optional) The optional variable name.
  • shape (Sequence[int], optional) The variable shape.
  • dtype (str, optional) The optional data type.
  • initializer (Union[callable, str], optional) The optional initializer.
  • regularizer (Union[callable, str], optional) The optional regularizer.
  • trainable (bool, optional, default=True) True to add to the trainable collection.
  • use_resource (bool, optional, default=True) True to set as a ResourceVariable.

build

Layer.build(input_shape)[source]

Create and initialize the variables.

Parameters:
  • input_shape (Sequence[Sequence[int]]) The input shape(s).

call

Layer.call(
  *args,
  **kwargs
)[source]

Define the implementation of forward.

Parameters:
Returns:

Sequence[dragon.Tensor] The output tensors.

load_weights

Layer.load_weights(
  filepath,
  verbose=False
)[source]

Load the value of weights from a binary file.

Parameters:
  • filepath (str, required) The path of weights file to load.
  • verbose (bool, optional, default=False) True to display the weights info.

save_weights

Layer.save_weights(
  filepath,
  save_format=None
)[source]

Save the value of weights into a binary file.

Parameters:
  • filepath (str, required) The path of weights file to save.
  • save_format ({'tf', 'h5', 'pkl'}, optional) The determined saving format.