tf_agents.networks.encoding_network.EncodingNetwork

Feed Forward network with CNN and FNN layers.

Inherits From: Network

Used in the notebooks

Used in the tutorials

input_tensor_spec A nest of tensor_spec.TensorSpec representing the input observations.
preprocessing_layers (Optional.) A nest of tf.keras.layers.Layer representing preprocessing for the different observations. All of these layers must not be already built.
preprocessing_combiner (Optional.) A keras layer that takes a flat list of tensors and combines them. Good options include tf.keras.layers.Add and tf.keras.layers.Concatenate(axis=-1). This layer must not be already built.
conv_layer_params Optional list of convolution layers parameters, where each item is either a length-three tuple indicating (filters, kernel_size, stride) or a length-four tuple indicating (filters, kernel_size, stride, dilation_rate).
fc_layer_params Optional list of fully_connected parameters, where each item is the number of units in the layer.
dropout_layer_params Optional list of dropout layer parameters, each item is the fraction of input units to drop or a dictionary of parameters according to the keras.Dropout documentation. The additional parameter permanent, if set to True, allows to apply dropout at inference for approximated Bayesian inference. The dropout layers are interleaved with the fully connected layers; there is a dropout layer after each fully connected layer, except if the entry in the list is None. This list must have the same length of fc_layer_params, or be None.
activation_fn Activation function, e.g. tf.keras.activations.relu.
weight_decay_params Optional list of weight decay parameters for the fully connected layers.
kernel_initializer Initializer to use for the kernels of the conv and dense layers. If none is provided a default variance_scaling_initializer
batch_squash If True the outer_ranks of the observation are squashed into the batch dimension. This allow encoding networks to be used with observations with shape [BxTx...].
dtype The dtype to use by the convolution and fully connected layers.
name A string representing name of the network.
conv_type string, '1d' or '2d'. Convolution layers will be 1d or 2D respectively

ValueError If any of preprocessing_layers is already built.
ValueError If preprocessing_combiner is already built.
ValueError If the number of dropout layer parameters does not match the number of fully connected layer parameters.
ValueError If conv_layer_params tuples do not have 3 or 4 elements each.

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

Methods

copy

View source

Create a shallow copy of this network.

Args
**kwargs Args to override when recreating this network. Commonly overridden args include 'name'.

Returns
A shallow copy of this network.

create_variables

View source

Force creation of the network's variables.

Return output specs.

Args
input_tensor_spec (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.

get_initial_state

View source

Returns an initial state usable by the network.

Args
batch_size Tensor or constant: size of the batch dimension. Can be None in which case not dimensions gets added.

Returns
A nested object of type self.state_spec containing properly initialized Tensors.

get_layer

View source

Retrieves a layer based on either its name (unique) or index.

If name and index are both provided, index will take precedence. Indices are based on order of horizontal graph traversal (bottom-up).

Args
name String, name of layer.
index Integer, index of layer.

Returns
A layer instance.

Raises
ValueError In case of invalid layer name or index.

summary

View source

Prints a string summary of the network.

Args
line_length 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.

Raises
ValueError if summary() is called before the model is built.