stateless_call

FullyConnected.stateless_call(trainable_variables, non_trainable_variables, *args, return_losses=False, **kwargs)

Call the layer without any side effects.

Parameters:
  • trainable_variables – List of trainable variables of the model.

  • non_trainable_variables – List of non-trainable variables of the model.

  • *args – Positional arguments to be passed to call().

  • return_losses – If True, stateless_call() will return the list of losses created during call() as part of its return values.

  • **kwargs – Keyword arguments to be passed to call().

Returns:

A tuple. By default, returns (outputs, non_trainable_variables).

If return_losses = True, then returns (outputs, non_trainable_variables, losses).

Note: non_trainable_variables include not only non-trainable weights such as BatchNormalization statistics, but also RNG seed state (if there are any random operations part of the layer, such as dropout), and Metric state (if there are any metrics attached to the layer). These are all elements of state of the layer.

Example:

```python model = … data = … trainable_variables = model.trainable_variables non_trainable_variables = model.non_trainable_variables # Call the model with zero side effects outputs, non_trainable_variables = model.stateless_call(

trainable_variables, non_trainable_variables, data,

) # Attach the updated state to the model # (until you do this, the model is still in its pre-call state). for ref_var, value in zip(

model.non_trainable_variables, non_trainable_variables

):

ref_var.assign(value)

```