Skip to content

allenact.embodiedai.models.basic_models#

[view_source]

Basic building block torch networks that can be used across a variety of tasks.

SimpleCNN#

class SimpleCNN(nn.Module)

[view_source]

A Simple N-Conv CNN followed by a fully connected layer. Takes in observations (of type gym.spaces.dict) and produces an embedding of the rgb_uuid and/or depth_uuid components.

Attributes

  • observation_space: The observation_space of the agent, should have rgb_uuid or depth_uuid as a component (otherwise it is a blind model).
  • output_size: The size of the embedding vector to produce.

SimpleCNN.__init__#

 | __init__(observation_space: SpaceDict, output_size: int, rgb_uuid: Optional[str], depth_uuid: Optional[str], layer_channels: Sequence[int] = (32, 64, 32), kernel_sizes: Sequence[Tuple[int, int]] = ((8, 8), (4, 4), (3, 3)), layers_stride: Sequence[Tuple[int, int]] = ((4, 4), (2, 2), (1, 1)), paddings: Sequence[Tuple[int, int]] = ((0, 0), (0, 0), (0, 0)), dilations: Sequence[Tuple[int, int]] = ((1, 1), (1, 1), (1, 1)), flatten: bool = True, output_relu: bool = True)

[view_source]

Initializer.

Parameters

  • observation_space : See class attributes documentation.
  • output_size : See class attributes documentation.

SimpleCNN.layer_init#

 | @staticmethod
 | layer_init(cnn) -> None

[view_source]

Initialize layer parameters using Kaiming normal.

SimpleCNN.is_blind#

 | @property
 | is_blind()

[view_source]

True if the observation space doesn't include self.rgb_uuid or self.depth_uuid.

RNNStateEncoder#

class RNNStateEncoder(nn.Module)

[view_source]

A simple RNN-based model playing a role in many baseline embodied- navigation agents.

See seq_forward for more details of how this model is used.

RNNStateEncoder.__init__#

 | __init__(input_size: int, hidden_size: int, num_layers: int = 1, rnn_type: str = "GRU", trainable_masked_hidden_state: bool = False)

[view_source]

An RNN for encoding the state in RL. Supports masking the hidden state during various timesteps in the forward lass.

Parameters

  • input_size : The input size of the RNN.
  • hidden_size : The hidden size.
  • num_layers : The number of recurrent layers.
  • rnn_type : The RNN cell type. Must be GRU or LSTM.
  • trainable_masked_hidden_state : If True the initial hidden state (used at the start of a Task) is trainable (as opposed to being a vector of zeros).

RNNStateEncoder.layer_init#

 | layer_init()

[view_source]

Initialize the RNN parameters in the model.

RNNStateEncoder.num_recurrent_layers#

 | @property
 | num_recurrent_layers() -> int

[view_source]

The number of recurrent layers in the network.

RNNStateEncoder.single_forward#

 | single_forward(x: torch.FloatTensor, hidden_states: torch.FloatTensor, masks: torch.FloatTensor) -> Tuple[
 |         torch.FloatTensor, Union[torch.FloatTensor, Tuple[torch.FloatTensor, ...]]
 |     ]

[view_source]

Forward for a single-step input.

RNNStateEncoder.seq_forward#

 | seq_forward(x: torch.FloatTensor, hidden_states: torch.FloatTensor, masks: torch.FloatTensor) -> Tuple[
 |         torch.FloatTensor, Union[torch.FloatTensor, Tuple[torch.FloatTensor, ...]]
 |     ]

[view_source]

Forward for a sequence of length T.

Parameters

  • x : (Steps, Samplers, Agents, -1) tensor.
  • hidden_states : The starting hidden states.
  • masks : A (Steps, Samplers, Agents) tensor. The masks to be applied to hidden state at every timestep, equal to 0 whenever the previous step finalized the task, 1 elsewhere.