예제 #1
0
 def __init__(
         self,
         image_shape,
         output_size,
         fc_sizes=512,
         use_maxpool=False,
         channels=None,  # None uses default.
         kernel_sizes=None,
         strides=None,
         paddings=None,
         baselines_init=True,
         init_v=1.,
         init_pi=.01
         ):
     """Instantiate neural net module according to inputs."""
     super().__init__()
     if channels is not None:
         self.conv = Conv2dHeadModel(
             image_shape=image_shape,
             channels=channels,
             kernel_sizes=kernel_sizes,
             strides=strides,
             paddings=paddings,
             use_maxpool=use_maxpool,
             hidden_sizes=fc_sizes,  # Applies nonlinearity at end.
         )
     else:
         self.conv = Conv2dHeadModel(image_shape=image_shape, **CONVNET_DQN, hidden_sizes=fc_sizes)
     #self.pi = torch.jit.script(layer_init(torch.nn.Linear(self.conv.output_size, output_size), init_pi))
     #self.value = torch.jit.script(layer_init(torch.nn.Linear(self.conv.output_size, 1), init_v))
     #self.conv = torch.jit.script(self.conv)
     self.pi = layer_init(torch.nn.Linear(self.conv.output_size, output_size), init_pi)
     self.value = layer_init(torch.nn.Linear(self.conv.output_size, 1), init_v)
예제 #2
0
파일: oc.py 프로젝트: DavidSlayback/rlpyt
 def __init__(self,
              input_size,
              num_options,
              num_actions,
              ortho_init=True,
              ortho_init_value=O_INIT_VALUES['pi']):
     super().__init__()
     pi = layer_init(Linear(input_size, num_options * num_actions),
                     ortho_init_value) if ortho_init else Linear(
                         input_size, num_options * num_actions)
     self.pi = Sequential(pi, View((num_options, num_actions)))
예제 #3
0
 def __init__(
         self,
         image_shape,
         output_size,
         fc_sizes=256,
         use_maxpool=False,
         channels=None,  # None uses default.
         kernel_sizes=None,
         strides=None,
         paddings=None,
         baselines_init=True,
         init_v=1.,
         init_pi=.01):
     """Instantiate neural net module according to inputs."""
     super().__init__()
     self.conv = IMPALAConvModel(image_shape, fc_sizes=fc_sizes)
     self.pi = torch.jit.script(
         layer_init(torch.nn.Linear(self.conv.output_size, output_size),
                    init_pi))
     self.value = torch.jit.script(
         layer_init(torch.nn.Linear(self.conv.output_size, 1), init_v))
     self.conv = torch.jit.script(self.conv)
예제 #4
0
파일: mlp.py 프로젝트: DavidSlayback/rlpyt
 def __init__(
         self,
         input_size,
         hidden_sizes,  # Can be empty list or None for none.
         output_size=None,  # if None, last layer has nonlinearity applied.
         nonlinearity=torch.nn.ReLU,  # Module, not Functional.
         inits=None):
     super().__init__()
     if isinstance(hidden_sizes, int):
         hidden_sizes = [hidden_sizes]
     elif hidden_sizes is None:
         hidden_sizes = []
     if inits is None:
         hidden_layers = [
             torch.nn.Linear(n_in, n_out)
             for n_in, n_out in zip([input_size] +
                                    hidden_sizes[:-1], hidden_sizes)
         ]
     else:
         hidden_layers = [
             layer_init(torch.nn.Linear(n_in, n_out), inits[0])
             for n_in, n_out in zip([input_size] +
                                    hidden_sizes[:-1], hidden_sizes)
         ]
     sequence = list()
     for layer in hidden_layers:
         sequence.extend([layer, nonlinearity()])
     if output_size is not None:
         last_size = hidden_sizes[-1] if hidden_sizes else input_size
         if inits is None:
             sequence.append(torch.nn.Linear(last_size, output_size))
         else:
             sequence.append(
                 layer_init(torch.nn.Linear(last_size, output_size),
                            inits[1]))
     self.model = torch.nn.Sequential(*sequence)
     self._output_size = (hidden_sizes[-1]
                          if output_size is None else output_size)
예제 #5
0
 def __init__(
         self,
         image_shape,
         output_size,
         option_size,
         fc_sizes=256,
         use_maxpool=False,
         channels=None,  # None uses default.
         kernel_sizes=None,
         strides=None,
         paddings=None,
         baselines_init=True,
         init_v=1.,
         init_pi=.01,
         use_interest=False):
     """Instantiate neural net module according to inputs."""
     super().__init__()
     self.use_interest = use_interest
     self.conv = IMPALAConvModel(image_shape, fc_sizes=fc_sizes)
     self.pi = torch.jit.script(
         DiscreteIntraOptionPolicy(self.conv.output_size, option_size,
                                   output_size, baselines_init, init_pi))
     self.q = torch.jit.script(
         layer_init(torch.nn.Linear(self.conv.output_size, option_size),
                    init_v))
     self.beta = torch.jit.script(
         torch.nn.Sequential(
             layer_init(torch.nn.Linear(self.conv.output_size, option_size),
                        init_v), torch.nn.Sigmoid()))
     self.pi_omega = torch.jit.script(
         torch.nn.Sequential(
             layer_init(torch.nn.Linear(self.conv.output_size, option_size),
                        init_pi), torch.nn.Softmax(-1)))
     self.pi_omega_I = torch.jit.script(
         torch.nn.Sequential(
             layer_init(torch.nn.Linear(self.conv.output_size, option_size),
                        init_v), torch.nn.Sigmoid()))
     self.conv = torch.jit.script(self.conv)
예제 #6
0
파일: oc.py 프로젝트: DavidSlayback/rlpyt
 def __init__(self,
              input_size,
              num_options,
              num_actions,
              ortho_init=True,
              ortho_init_value=O_INIT_VALUES['pi'],
              init_log_std=0.,
              mu_nonlinearity=nn.Identity):
     super().__init__()
     pi_mu = layer_init(Linear(input_size, num_options * num_actions),
                        ortho_init_value) if ortho_init else Linear(
                            input_size, num_options * num_actions)
     self.pi_mu = Sequential(pi_mu, View((num_options, num_actions)),
                             mu_nonlinearity())
     self.log_std = nn.Parameter(init_log_std * torch.ones(
         (num_options, num_actions)))  # State-independent vector of log_std