-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rllib] Added evaluation script to RLLib #1295
Changes from 1 commit
c25094b
ec16345
d0e1de3
0d2012d
ebd9ef3
938fc9f
35ddce2
a7ed5e2
d21d236
b915195
3e4e1b8
76664e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env python | ||
|
||
import argparse | ||
import gym | ||
import ray | ||
|
||
from dqn import DQNAgent | ||
from agent import get_agent_class | ||
|
||
|
||
EXAMPLE_USAGE = """ | ||
example usage: | ||
./train.py /tmp/ray/checkpoint_dir/checkpoint-0 --run DQN --env CartPole-v0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should say ./eval.py right? |
||
""" | ||
|
||
|
||
parser = argparse.ArgumentParser( | ||
formatter_class=argparse.RawDescriptionHelpFormatter, | ||
description="Evaluates a reinforcement learning agent given a checkpoint.", | ||
epilog=EXAMPLE_USAGE) | ||
|
||
parser.add_argument("checkpoint", type=str, help="Checkpoint which to evaluate.") | ||
required_named = parser.add_argument_group("required named arguments") | ||
required_named.add_argument( | ||
"--run", type=str, required=True, | ||
help="The algorithm or model to train. This may refer to the name " | ||
"of a built-on algorithm (e.g. RLLib's DQN or PPO), or a " | ||
"user-defined trainable function or class registered in the " | ||
"tune registry.") | ||
required_named.add_argument( | ||
"--env", type=str, required=True, help="The gym environment to use.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also need --config? |
||
parser.add_argument( | ||
"--hide", default=False, action="store_const", const=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --no-render |
||
help="Surpress rendering of the environment.") | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
ray.init() | ||
|
||
cls = get_agent_class(args.run) | ||
agent = cls(env=args.env) | ||
agent._restore(args.checkpoint) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
env = gym.make(args.env) | ||
state = env.reset() | ||
done = False | ||
while not done: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider doing it in an infinite loop. |
||
action = agent.compute_action(state) | ||
state, reward, done, _ = env.step(action) | ||
if not args.hide: | ||
env.render() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you do the import future stuff from train.py as well here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed in the latest commit