The main differences between a TF-Agents Network and a Keras Layer include:
networks keep track of their underlying layers, explicitly represent RNN-like
state in inputs and outputs, and simplify variable creation and clone
operations.
When calling a network net, typically one passes data through it via:
outputs, next_state = net(observation, network_state=...)
outputs, next_state = net(observation, step_type=..., network_state=...)
outputs, next_state = net(observation) # net.call must fill an empty state
outputs, next_state = net(observation, step_type=...)
outputs, next_state = net(
observation, step_type=..., network_state=..., learning=...)
etc.
To force construction of a network's variables:
net.create_variables()
net.create_variables(input_tensor_spec=...) # To provide an input spec
net.create_variables(training=True) # Provide extra kwargs
net.create_variables(input_tensor_spec, training=True)
To create a copy of the network:
cloned_net = net.copy()
cloned_net.variables # Raises ValueError: cloned net does not share weights.
cloned_net.create_variables(...)
cloned_net.variables # Now new variables have been created.
Args
input_tensor_spec
A nest of tf.TypeSpec representing the input
observations. Optional. If not provided, create_variables() will
fail unless a spec is provided.
state_spec
A nest of tensor_spec.TensorSpec representing the state
needed by the network. Default is (), which means no state.
name
(Optional.) A string representing the name of the network.
Attributes
input_tensor_spec
Returns the spec of the input to the network of type InputSpec.
layers
Get the list of all (nested) sub-layers used in this Network.
(Optional). Override or provide an input tensor spec
when creating variables.
**kwargs
Other arguments to network.call(), e.g. training=True.
Returns
Output specs - a nested spec calculated from the outputs (excluding any
batch dimensions). If any of the output elements is a tfp Distribution,
the associated spec entry returned is a DistributionSpec.
Raises
ValueError
If no input_tensor_spec is provided, and the network did
not provide one during construction.
Total length of printed lines (e.g. set this to adapt the
display to different terminal window sizes).
positions
Relative or absolute positions of log elements in each line.
If not provided, defaults to [.33, .55, .67, 1.].
print_fn
Print function to use. Defaults to print. It will be called
on each line of the summary. You can set it to a custom function in
order to capture the string summary.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[]]