Fix rendering

This commit is contained in:
ebuehrle
2021-11-05 08:35:14 +01:00
parent 071c731921
commit 4ee960b104
3 changed files with 10 additions and 5 deletions

View File

@@ -34,10 +34,13 @@ class NRasterizedRouteSpeedRandomAgentLocation(RandomLocation, RandomAgent, Rewa
NormalizedActionSpace, ActionVisualization, InteractionSimulatorMarkerViz, ImitationCompat, Intersimple): NormalizedActionSpace, ActionVisualization, InteractionSimulatorMarkerViz, ImitationCompat, Intersimple):
pass pass
class NoBSTimeLimit(TimeLimit): class TransparentTimeLimit(TimeLimit):
def __getattr__(self, name): def __getattr__(self, name):
return getattr(self.env, name) return getattr(self.env, name)
def close(self, *args, **kwargs):
return self.env.close(*args, **kwargs)
def TLNRasterizedRouteRandomAgentLocation(max_episode_steps, *args, **kwargs): def TLNRasterizedRouteRandomAgentLocation(max_episode_steps, *args, **kwargs):
return NoBSTimeLimit(NRasterizedRouteRandomAgentLocation(*args, **kwargs), max_episode_steps=max_episode_steps) return TransparentTimeLimit(NRasterizedRouteRandomAgentLocation(*args, **kwargs), max_episode_steps=max_episode_steps)

View File

@@ -91,7 +91,7 @@ class RenderOptions(OptionsEnv):
def _ll_step(self, action): def _ll_step(self, action):
out = super()._ll_step(action) out = super()._ll_step(action)
self.env.render() self.env.render(mode='post')
return out return out
def close(self, *args, **kwargs): def close(self, *args, **kwargs):

View File

@@ -19,7 +19,6 @@ from stable_baselines3.common.vec_env.dummy_vec_env import DummyVecEnv
model_name = 'gail_options_image_random_location' model_name = 'gail_options_image_random_location'
env_settings = {'width': 70, 'height': 70, 'm_per_px': 1, 'mu': 0.001, 'random_skip': True, 'max_episode_steps': 50} env_settings = {'width': 70, 'height': 70, 'm_per_px': 1, 'mu': 0.001, 'random_skip': True, 'max_episode_steps': 50}
env = TLNRasterizedRouteRandomAgentLocation(**env_settings)
ALL_OPTIONS = [(v,t) for v in [0,2,4,6,8] for t in [5, 10, 20]] # option 0 is safe fallback ALL_OPTIONS = [(v,t) for v in [0,2,4,6,8] for t in [5, 10, 20]] # option 0 is safe fallback
@@ -33,6 +32,7 @@ def train(
discount=0.99, discount=0.99,
epochs=100, epochs=100,
): ):
env = TLNRasterizedRouteRandomAgentLocation(**env_settings)
tempdir = tempfile.TemporaryDirectory(prefix="quickstart") tempdir = tempfile.TemporaryDirectory(prefix="quickstart")
tempdir_path = pathlib.Path(tempdir.name) tempdir_path = pathlib.Path(tempdir.name)
@@ -79,7 +79,6 @@ def train(
return generator return generator
def video(model_name, env): def video(model_name, env):
env = RenderOptions(env, options=ALL_OPTIONS)
model = stable_baselines3.PPO.load(model_name) model = stable_baselines3.PPO.load(model_name)
done = False done = False
@@ -91,6 +90,9 @@ def video(model_name, env):
env.close(filestr='render/'+model_name) env.close(filestr='render/'+model_name)
def evaluate(): def evaluate():
video_settings = { **env_settings, 'random_skip': False, 'max_episode_steps': 1000 }
env = TLNRasterizedRouteRandomAgentLocation(**video_settings)
env = RenderOptions(env, options=ALL_OPTIONS)
video( video(
model_name=model_name, model_name=model_name,
env=env env=env