-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into main
- Loading branch information
Showing
6 changed files
with
120 additions
and
42 deletions.
There are no files selected for viewing
8 changes: 4 additions & 4 deletions
8
experiments/hardware_experiments/api_experiments/data_recording.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
experiments/hardware_experiments/api_experiments/offline_policy/offline_policy_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pickle | ||
import jax.numpy as jnp | ||
import numpy as np | ||
from mbpo.optimizers.policy_optimizers.sac.sac_networks import SACNetworksModel, make_inference_fn | ||
from brax.training.acme import running_statistics | ||
import flax.linen as nn | ||
import jax.random as jr | ||
from sim_transfer.hardware.car_env import CarEnv | ||
|
||
ENCODE_ANGLE = True | ||
|
||
normalize_fn = running_statistics.normalize | ||
sac_networks_model = SACNetworksModel( | ||
x_dim=7, u_dim=2, | ||
preprocess_observations_fn=normalize_fn, | ||
policy_hidden_layer_sizes=(64, 64), | ||
policy_activation=nn.swish, | ||
critic_hidden_layer_sizes=(64, 64), | ||
critic_activation=nn.swish) | ||
|
||
inference_fn = make_inference_fn(sac_networks_model.get_sac_networks()) | ||
|
||
with open('params.pkl', 'rb') as file: | ||
params = pickle.load(file) | ||
|
||
|
||
def policy(obs): | ||
dummy_obs = obs[0:7] | ||
return np.asarray(inference_fn(params, deterministic=True)(dummy_obs, jr.PRNGKey(0))[0]) | ||
|
||
env = CarEnv(encode_angle=ENCODE_ANGLE) | ||
obs, _ = env.reset() | ||
for i in range(200): | ||
action = policy(obs) | ||
obs, reward, terminate, info = env.step(action) | ||
print(obs) | ||
env.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters