Adds a new variable to the layer, or gets an existing one; returns it. Arguments: name: variable name. shape: variable shape. dtype: The type of the variable. Defaults to `self.dtype` or `float32`. initializer: initializer instance (callable). regularizer: regulari
(self,
name,
shape,
dtype=None,
initializer=None,
regularizer=None,
trainable=None,
constraint=None,
use_resource=None,
synchronization=vs.VariableSynchronization.AUTO,
aggregation=vs.VariableAggregation.NONE,
partitioner=None,
**kwargs)
| 315 | self._scope = captured_scope |
| 316 | |
| 317 | def add_weight(self, |
| 318 | name, |
| 319 | shape, |
| 320 | dtype=None, |
| 321 | initializer=None, |
| 322 | regularizer=None, |
| 323 | trainable=None, |
| 324 | constraint=None, |
| 325 | use_resource=None, |
| 326 | synchronization=vs.VariableSynchronization.AUTO, |
| 327 | aggregation=vs.VariableAggregation.NONE, |
| 328 | partitioner=None, |
| 329 | **kwargs): |
| 330 | """Adds a new variable to the layer, or gets an existing one; returns it. |
| 331 | |
| 332 | Arguments: |
| 333 | name: variable name. |
| 334 | shape: variable shape. |
| 335 | dtype: The type of the variable. Defaults to `self.dtype` or `float32`. |
| 336 | initializer: initializer instance (callable). |
| 337 | regularizer: regularizer instance (callable). |
| 338 | trainable: whether the variable should be part of the layer's |
| 339 | "trainable_variables" (e.g. variables, biases) |
| 340 | or "non_trainable_variables" (e.g. BatchNorm mean, stddev). |
| 341 | Note, if the current variable scope is marked as non-trainable |
| 342 | then this parameter is ignored and any added variables are also |
| 343 | marked as non-trainable. `trainable` defaults to `True` unless |
| 344 | `synchronization` is set to `ON_READ`. |
| 345 | constraint: constraint instance (callable). |
| 346 | use_resource: Whether to use `ResourceVariable`. |
| 347 | synchronization: Indicates when a distributed a variable will be |
| 348 | aggregated. Accepted values are constants defined in the class |
| 349 | `tf.VariableSynchronization`. By default the synchronization is set to |
| 350 | `AUTO` and the current `DistributionStrategy` chooses |
| 351 | when to synchronize. If `synchronization` is set to `ON_READ`, |
| 352 | `trainable` must not be set to `True`. |
| 353 | aggregation: Indicates how a distributed variable will be aggregated. |
| 354 | Accepted values are constants defined in the class |
| 355 | `tf.VariableAggregation`. |
| 356 | partitioner: (optional) partitioner instance (callable). If |
| 357 | provided, when the requested variable is created it will be split |
| 358 | into multiple partitions according to `partitioner`. In this case, |
| 359 | an instance of `PartitionedVariable` is returned. Available |
| 360 | partitioners include `tf.compat.v1.fixed_size_partitioner` and |
| 361 | `tf.compat.v1.variable_axis_size_partitioner`. For more details, see |
| 362 | the documentation of `tf.compat.v1.get_variable` and the "Variable |
| 363 | Partitioners and Sharding" section of the API guide. |
| 364 | **kwargs: Additional keyword arguments. |
| 365 | |
| 366 | Returns: |
| 367 | The created variable. Usually either a `Variable` or `ResourceVariable` |
| 368 | instance. If `partitioner` is not `None`, a `PartitionedVariable` |
| 369 | instance is returned. |
| 370 | |
| 371 | Raises: |
| 372 | RuntimeError: If called with partitioned variable regularization and |
| 373 | eager execution is enabled. |
| 374 | ValueError: When trainable has been set to True with synchronization |