-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_Evaluation.py
55 lines (49 loc) · 1.73 KB
/
main_Evaluation.py
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
import gym
import pybulletgym
import time
import os
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--env',type=str)
parser.add_argument('--alg',type=str)
parser.add_argument('--file', type=str)
args = parser.parse_args()
ckpt_path = os.path.join(os.path.dirname(os.path.abspath(__file__)),args.file)
print(ckpt_path)
if args.env == 'w' or args.env == 'Walker2DPyBulletEnv-v0':
env = gym.make('Walker2DPyBulletEnv-v0')
elif args.env == 'h' or args.env == 'HumanoidPyBulletEnv-v0':
env = gym.make('HumanoidPyBulletEnv-v0')
else:
raise ValueError('No such environment!')
env.render()
if args.alg == 'td3' or args.alg=='TD3':
from stable_baselines import TD3
model = TD3.load(args.file)
elif args.alg == 'ddpg' or args.alg == 'DDPG':
from stable_baselines import DDPG
model = DDPG.load(args.file)
elif args.alg == 'SAC' or args.alg == 'sac':
from stable_baselines import SAC
model = SAC.load(args.file)
elif args.alg == 'ppo1' or args.alg == 'PPO1':
from stable_baselines import PPO1
model = PPO1.load(args.file)
elif args.alg == 'ppo2' or args.alg == 'PPO2':
from stable_baselines import PPO2
model = PPO2.load(args.file)
else:
raise ValueError('No such algorithm')
ob = env.reset()
reward = 0
while True:
action, _states = model.predict(ob)
ob, r, done, info = env.step(action)
reward += r
time.sleep(0.01)
if done:
ob = env.reset()
print('r is {}'.format(r))
print('Episode reward is {}'.format(reward))
reward = 0