MCPcopy Create free account
hub / github.com/RoboVerseOrg/RoboVerse / build_actor

Function build_actor

scripts/render_cartpole_rollout.py:21–38  ·  view source on GitHub ↗
(state_dict, device)

Source from the content-addressed store, hash-verified

19
20
21def build_actor(state_dict, device):
22 keys = sorted(
23 [k for k in state_dict if k.startswith("mlp.") and k.endswith(".weight")],
24 key=lambda k: int(k.split(".")[1]),
25 )
26 mods = []
27 for i, k in enumerate(keys):
28 w = state_dict[k]
29 mods.append(nn.Linear(w.shape[1], w.shape[0]))
30 if i < len(keys) - 1:
31 mods.append(nn.ELU())
32 actor = nn.Sequential(*mods).to(device)
33 actor.load_state_dict(
34 {k[len("mlp.") :]: v for k, v in state_dict.items() if k.startswith("mlp.")},
35 strict=False,
36 )
37 actor.eval()
38 return actor
39
40
41def main():

Callers 1

mainFunction · 0.70

Calls 2

toMethod · 0.80
itemsMethod · 0.80

Tested by

no test coverage detected