common.encoder

Please Reference ding/ding/docs/source/api_doc/model/common/encoder.py for usage

ConvEncoder

class ding.model.common.encoder.ConvEncoder(obs_shape: ding.utils.type_helper.SequenceType, hidden_size_list: ding.utils.type_helper.SequenceType = [32, 64, 64, 128], activation: Optional[torch.nn.modules.module.Module] = ReLU(), norm_type: Optional[str] = None)[source]
Overview:

The Convolution Encoder used in models. Used to encoder raw 2-dim observation.

Interfaces:

__init__, forward

__init__(obs_shape: ding.utils.type_helper.SequenceType, hidden_size_list: ding.utils.type_helper.SequenceType = [32, 64, 64, 128], activation: Optional[torch.nn.modules.module.Module] = ReLU(), norm_type: Optional[str] = None) None[source]
Overview:

Init the Convolution Encoder according to arguments.

Arguments:
  • obs_shape (SequenceType): Sequence of in_channel, some output size

  • hidden_size_list (SequenceType): The collection of hidden_size

  • activation (nn.Module):

    The type of activation to use in the conv layers and ResBlock, if None then default set to nn.ReLU()

  • norm_type (str):

    The type of normalization to use, see ding.torch_utils.ResBlock for more details

_get_flatten_size() int[source]
Overview:

Get the encoding size after self.main to get the number of in-features to feed to nn.Linear.

Arguments:
  • x (torch.Tensor): Encoded Tensor after self.main

Returns:
  • outputs (torch.Tensor): Size int, also number of in-feature

forward(x: torch.Tensor) torch.Tensor[source]
Overview:

Return embedding tensor of the env observation

Arguments:
  • x (torch.Tensor): Env raw observation

Returns:
  • outputs (torch.Tensor): Embedding tensor

FCEncoder

class ding.model.common.encoder.FCEncoder(obs_shape: int, hidden_size_list: ding.utils.type_helper.SequenceType, res_block: bool = False, activation: Optional[torch.nn.modules.module.Module] = ReLU(), norm_type: Optional[str] = None)[source]
Overview:

The FCEncoder used in models. Used to encoder raw 1-dim observation.

Interfaces:

__init__, forward

__init__(obs_shape: int, hidden_size_list: ding.utils.type_helper.SequenceType, res_block: bool = False, activation: Optional[torch.nn.modules.module.Module] = ReLU(), norm_type: Optional[str] = None) None[source]
Overview:

Init the FC Encoder according to arguments.

Arguments:
  • obs_shape (int): Observation shape

  • hidden_size_list (SequenceType): The collection of hidden_size

  • res_block (bool): Whether use res_block.

  • activation (nn.Module):

    The type of activation to use in the ResFCBlock, if None then default set to nn.ReLU()

  • norm_type (str):

    The type of normalization to use, see ding.torch_utils.ResFCBlock for more details

forward(x: torch.Tensor) torch.Tensor[source]
Overview:

Return embedding tensor of the env observation

Arguments:
  • x (torch.Tensor): Env raw observation

Returns:
  • outputs (torch.Tensor): Embedding tensor

StructEncoder

class ding.model.common.encoder.StructEncoder[source]
__init__() None

Initializes internal Module state, shared by both nn.Module and ScriptModule.