Model

class dragon.vm.tensorlayer.models.Model(name=None)[source]

Compose a group of layers with training features.

__init__

Model.__init__(name=None)[source]

Create a Model instance.

Parameters:
  • name (str, optional) – The optional model name.

Properties

all_layers

Model.all_layers

Return all the layers in this model.

Returns:
Sequence[dragon.vm.tensorlayer.layers.Layer] – The layer sequence.

all_weights

Model.all_weights

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

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

name

Model.name

Return the model name.

Returns:
str – The model name.

nontrainable_weights

Module.nontrainable_weights

Return the non-trainable weights.

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

trainable_weights

Module.trainable_weights

Return the trainable weights.

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

training

Module.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.

eval

Model.eval()[source]

Set the model in evaluation mode.

forward

Module.forward(
  *inputs,
  **kwargs
)[source]

Method to define the forward operations.

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.

train

Model.train()[source]

Set the model in training mode.