Example #1
0
    def __init__(self, hp):
        super().__init__()
        self._hp = hp
        if self._hp.low_dim:
            self.encoder = Linear(in_dim=self._hp.state_size * 2,
                                  out_dim=128,
                                  builder=self._hp.builder)
            out_size = 128
        else:
            self.encoder = ConvEncoder(self._hp)
            out_size = self.encoder.get_output_size()[0] * 5 * 5
        self.mlp = torch.nn.Sequential()

        self.mlp.add_module(
            'linear_1',
            Linear(in_dim=out_size, out_dim=128, builder=self._hp.builder))
        for i in range(10):
            self.mlp.add_module(
                f'linear_{i+2}',
                Linear(in_dim=128, out_dim=128, builder=self._hp.builder))
            self.mlp.add_module(f'relu_{i+2}', torch.nn.ReLU())
        self.mlp.add_module(
            'linear_final',
            Linear(in_dim=128,
                   out_dim=self._hp.action_size,
                   builder=self._hp.builder))
        self.mlp.add_module('tanh', torch.nn.Tanh())
Example #2
0
    def __init__(self, hp, inp_dim, feature_size):
        super().__init__()
        self._hp = hp

        self.inp_dim = inp_dim
        self.feature_size = feature_size
        self.linear = Linear(in_dim=inp_dim, out_dim=2*feature_size, builder=self._hp.builder)
Example #3
0
    def __init__(self, hp):
        super().__init__()
        self._hp = hp
        if self._hp.low_dim:
            self.linear1 = Linear(in_dim=4,
                                  out_dim=128,
                                  builder=self._hp.builder)
        else:
            self.encoder = ConvEncoder(self._hp)
            out_size = self.encoder.get_output_size()
            self.linear1 = Linear(in_dim=64 * 5 * 5,
                                  out_dim=128,
                                  builder=self._hp.builder)

        self.linear2 = Linear(in_dim=128 + self._hp.action_size,
                              out_dim=1,
                              builder=self._hp.builder)
Example #4
0
 def build_network(self, build_encoder=True):
     self.encoder = ConvEncoder(self._hp)
     out_size = self.encoder.get_output_size()
     self.spatial_softmax = SpatialSoftmax(
         out_size[1], out_size[2], out_size[0])  # height, width, channel
     self.linear = Linear(in_dim=out_size[0] * 2,
                          out_dim=1,
                          builder=self._hp.builder)
Example #5
0
    def __init__(self, hp):
        super().__init__()
        self._hp = hp

        self.encoder = ConvEncoder(self._hp)
        out_size = self.encoder.get_output_size()
        self.linear1 = Linear(in_dim=64 * 5 * 5,
                              out_dim=128,
                              builder=self._hp.builder)
        self.linear2 = Linear(in_dim=128,
                              out_dim=self._hp.hidden_size * 2,
                              builder=self._hp.builder)
        self.linear3 = Linear(in_dim=self._hp.hidden_size,
                              out_dim=128,
                              builder=self._hp.builder)
        self.linear4 = Linear(in_dim=128,
                              out_dim=64 * 5 * 5,
                              builder=self._hp.builder)
        self.decoder = ConvDecoder(self._hp)
Example #6
0
 def __init__(self, hp, num_outputs):
     super().__init__()
     self._hp = hp
     self.num_outputs = num_outputs
     self.ll_size = ll_size = self._hp.linear_layer_size
     self.fc_layers = torch.nn.ModuleList()
     if self._hp.low_dim:
         self.linear1 = Linear(in_dim=2 * self._hp.state_size,
                               out_dim=ll_size,
                               builder=self._hp.builder)
         self.linear2 = Linear(in_dim=ll_size + self._hp.action_size,
                               out_dim=ll_size,
                               builder=self._hp.builder)
     else:
         self.encoder = ConvEncoder(self._hp)
         out_size = self.encoder.get_output_size()
         self.linear1 = Linear(in_dim=out_size[0] * out_size[1] *
                               out_size[2],
                               out_dim=ll_size,
                               builder=self._hp.builder)
         self.linear2 = Linear(in_dim=ll_size + self._hp.action_size,
                               out_dim=ll_size,
                               builder=self._hp.builder)
     for i in range(3):
         self.fc_layers.append(
             Linear(in_dim=ll_size,
                    out_dim=ll_size,
                    builder=self._hp.builder))
     self.fc_layers.append(
         Linear(in_dim=ll_size,
                out_dim=self.num_outputs,
                builder=self._hp.builder))
Example #7
0
 def build_network(self, build_encoder=True):
     self.encoder = ConvEncoder(self._hp)
     out_size = self.encoder.get_output_size()
     if self._hp.spatial_softmax:
         self.spatial_softmax = SpatialSoftmax(
             out_size[1], out_size[2],
             out_size[0])  # height, width, channel
         self.linear = Linear(in_dim=out_size[0] * 2,
                              out_dim=1,
                              builder=self._hp.builder)
     else:
         self.linear = Linear(in_dim=256,
                              out_dim=1,
                              builder=self._hp.builder)
         self.fc_layers = []
         self.fc_layers.append(
             Linear(in_dim=out_size[0] * out_size[1] * out_size[2],
                    out_dim=256,
                    builder=self._hp.builder))
         for i in range(3):
             self.fc_layers.append(
                 Linear(in_dim=256, out_dim=256, builder=self._hp.builder))
Example #8
0
 def __init__(self, hp):
     super().__init__()
     self._hp = hp
     self.linear1 = Linear(in_dim=self._hp.hidden_size,
                           out_dim=self._hp.hidden_size,
                           builder=self._hp.builder)