Layer

class dragon.vm.tensorlayer.layers.Layer(
  name=None,
  act=None,
  *args,
  **kwargs
)[source]

The base layer abstraction of a neural network.

It should be subclassed when implementing new types of layers:

class MyLayer(tl.layers.Layer):
    def __init__(name=None, act=None):
        super(MyLayer, self).__init__(name=name, act=act)

__init__

Layer.__init__(
  name=None,
  act=None,
  *args,
  **kwargs
)[source]

Create a new Layer.

Parameters:
  • name (str, optional.) – The optional layer name.
  • act (str or function, optional) – The optional activation.

Properties

all_weights

Layer.all_weights

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

Returns:
Sequence[dragon.Tensor] – The weights sequence.

name

Layer.name

Return the layer name.

Returns:
str – The layer name.

nontrainable_weights

Layer.nontrainable_weights

Return the non-trainable weights.

Returns:
Sequence[dragon.Tensor] – The weights sequence.

trainable_weights

Layer.trainable_weights

Return the trainable weights.

Returns:
Sequence[dragon.Tensor] – The weights sequence.

training

Layer.training

Return the training mode.

Returns:
boolTrue for training otherwise evaluation.

Methods

add_weight

Module.add_weight(
  name=None,
  shape=None,
  init='glorot_uniform',
  trainable=True
)[source]

Add a new weight.

Parameters:
  • name (str, optional) – The weight name.
  • shape (Sequence[int], optional) – The weight shape.
  • init (Union[callable, str], optional) – The initializer for weight.
  • trainable (bool, optional, default=True) – True to compute the gradients if necessary.
Returns:

dragon.Tensor – The weight tensor.

build

Layer.build(input_shapes)[source]

Method to define the weights.

Parameters:
  • input_shapes (Sequence[Sequence[int]]) – The shape of inputs.

forward

Layer.forward(inputs)[source]

Method to define the forward operations.

Parameters:
Returns:

Sequence[dragon.Tensor] – The outputs.

load_weights

Module.load_weights(
  filepath,
  format=None,
  skip=False,
  verbose=False
)[source]

Load model weights from a binary file.

Parameters:
  • filepath (str) – The path of weights file.
  • format ({'hdf5', 'npz', 'pkl', 'npz_dict'}, optional) – The optional saving format.
  • skip (bool, optional, default=False) – True to skip the modules which is not found.
  • verbose (bool, optional, default=False) – True to print the matched weights.

save_weights

Module.save_weights(
  filepath,
  format=None
)[source]

Save weights into a binary file.

Parameters:
  • filepath (str) – The path of weights file.
  • format ({'hdf5', 'npz', 'pkl', 'npz_dict'}, optional) – The optional saving format.