MCPcopy Create free account
hub / github.com/OpenDriveLab/TCP / __init__

Method __init__

roach/models/ppo_policy.py:13–60  ·  view source on GitHub ↗
(self,
                 observation_space: gym.spaces.Space,
                 action_space: gym.spaces.Space,
                 policy_head_arch=[256, 256],
                 value_head_arch=[256, 256],
                 features_extractor_entry_point=None,
                 features_extractor_kwargs={},
                 distribution_entry_point=None,
                 distribution_kwargs={})

Source from the content-addressed store, hash-verified

11class PpoPolicy(nn.Module):
12
13 def __init__(self,
14 observation_space: gym.spaces.Space,
15 action_space: gym.spaces.Space,
16 policy_head_arch=[256, 256],
17 value_head_arch=[256, 256],
18 features_extractor_entry_point=None,
19 features_extractor_kwargs={},
20 distribution_entry_point=None,
21 distribution_kwargs={}):
22
23 super(PpoPolicy, self).__init__()
24 self.observation_space = observation_space
25 self.action_space = action_space
26 self.features_extractor_entry_point = features_extractor_entry_point
27 self.features_extractor_kwargs = features_extractor_kwargs
28 self.distribution_entry_point = distribution_entry_point
29 self.distribution_kwargs = distribution_kwargs
30
31 if th.cuda.is_available():
32 self.device = 'cuda'
33 else:
34 self.device = 'cpu'
35
36 self.optimizer_class = th.optim.Adam
37 self.optimizer_kwargs = {'eps': 1e-5}
38
39 features_extractor_entry_point = features_extractor_entry_point.replace("agents.rl_birdview","roach")
40 features_extractor_class = load_entry_point(features_extractor_entry_point)
41 self.features_extractor = features_extractor_class(observation_space, **features_extractor_kwargs)
42
43 distribution_entry_point = distribution_entry_point.replace("agents.rl_birdview","roach")
44 distribution_class = load_entry_point(distribution_entry_point)
45 self.action_dist = distribution_class(int(np.prod(action_space.shape)), **distribution_kwargs)
46
47 if 'StateDependentNoiseDistribution' in distribution_entry_point:
48 self.use_sde = True
49 self.sde_sample_freq = 4
50 else:
51 self.use_sde = False
52 self.sde_sample_freq = None
53
54 # best_so_far
55 # self.net_arch = [dict(pi=[256, 128, 64], vf=[128, 64])]
56 self.policy_head_arch = list(policy_head_arch)
57 self.value_head_arch = list(value_head_arch)
58 self.activation_fn = nn.ReLU
59 self.ortho_init = False
60 self._build()
61
62 def reset_noise(self, n_envs: int = 1) -> None:
63 assert self.use_sde, 'reset_noise() is only available when using gSDE'

Callers

nothing calls this directly

Calls 2

_buildMethod · 0.95
load_entry_pointFunction · 0.90

Tested by

no test coverage detected