forked from fcomlop/BabyBench2025_Starter_Kit
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathevaluation.py
More file actions
73 lines (57 loc) · 2.31 KB
/
evaluation.py
File metadata and controls
73 lines (57 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
import os
import gymnasium as gym
import time
import argparse
import mujoco
import yaml
import mimoEnv
from mimoEnv.envs.mimo_env import MIMoEnv
import mimoEnv.utils as env_utils
import babybench.utils as bb_utils
import babybench.eval as bb_eval
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--config', default='examples/config_test_installation.yml', type=str,
help='The configuration file to set up environment variables')
parser.add_argument('--render', default=True, type=bool,
help='Renders a video for each episode during the evaluation.')
parser.add_argument('--duration', default=1000, type=int,
help='Total timesteps per evaluation episode')
parser.add_argument('--episodes', default=10, type=int,
help='Number of evaluation episode')
args = parser.parse_args()
with open(args.config) as f:
config = yaml.safe_load(f)
env = bb_utils.make_env(config, training=False)
env.reset()
# Initialize evaluation object
evaluation = bb_eval.EVALS[config['behavior']](
env=env,
duration=args.duration,
render=args.render,
save_dir=config['save_dir'],
)
# Preview evaluation of training log
evaluation.eval_logs()
for ep_idx in range(args.episodes):
print(f'Running evaluation episode {ep_idx+1}/{args.episodes}')
# Reset environment and evaluation
obs, _ = env.reset()
evaluation.reset()
for t_idx in range(args.duration):
# Select action
action = env.action_space.sample()
# ---------------------------------------------------#
# #
# TODO REPLACE WITH CALL TO YOUR TRAINED POLICY HERE #
# action = policy(obs) #
# #
# ---------------------------------------------------#
# Perform step in simulation
obs, _, _, _, info = env.step(action)
# Perform evaluations of step
evaluation.eval_step(info)
evaluation.end(episode=ep_idx)
if __name__ == '__main__':
main()