add_weight

FullyConnected.add_weight(name=None, shape=None, dtype=None, initializer=None, regularizer=None, trainable=None, constraint=None, use_resource=None, synchronization=VariableSynchronization.AUTO, aggregation=VariableAggregationV2.NONE, **kwargs)

Adds a new variable to the layer.

Parameters:
  • name – Variable name.

  • shape – Variable shape. Defaults to scalar if unspecified.

  • dtype – The type of the variable. Defaults to self.dtype.

  • initializer – Initializer instance (callable).

  • regularizer – Regularizer instance (callable).

  • trainable – Boolean, whether the variable should be part of the layer’s “trainable_variables” (e.g. variables, biases) or “non_trainable_variables” (e.g. BatchNorm mean and variance). Note that trainable cannot be True if synchronization is set to ON_READ.

  • constraint – Constraint instance (callable).

  • use_resource

    Whether to use a ResourceVariable or not. See [this guide]( https://www.tensorflow.org/guide/migrate/tf1_vs_tf2#resourcevariables_instead_of_referencevariables)

    for more information.

  • synchronization – Indicates when a distributed a variable will be aggregated. Accepted values are constants defined in the class tf.VariableSynchronization. By default the synchronization is set to AUTO and the current DistributionStrategy chooses when to synchronize. If synchronization is set to ON_READ, trainable must not be set to True.

  • aggregation – Indicates how a distributed variable will be aggregated. Accepted values are constants defined in the class tf.VariableAggregation.

  • **kwargs – Additional keyword arguments. Accepted values are getter, collections, experimental_autocast and caching_device.

Returns:

The variable created.

Raises:

ValueError – When giving unsupported dtype and no initializer or when trainable has been set to True with synchronization set as ON_READ.