Python gym.envs.classic_control.rendering.SimpleImageViewer() Examples
The following are 30
code examples of gym.envs.classic_control.rendering.SimpleImageViewer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gym.envs.classic_control.rendering
, or try the search function
.
Example #1
Source File: switch_one_corridor.py From ma-gym with Apache License 2.0 | 6 votes |
def render(self, mode='human'): img = copy.copy(self._base_img) for agent_i in range(self.n_agents): draw_circle(img, self.agent_pos[agent_i], cell_size=CELL_SIZE, fill=AGENT_COLORS[agent_i], radius=0.3) write_cell_text(img, text=str(agent_i + 1), pos=self.agent_pos[agent_i], cell_size=CELL_SIZE, fill='white', margin=0.4) img = np.asarray(img) if mode == 'rgb_array': return img elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img) return self.viewer.isopen
Example #2
Source File: sokoban_env.py From gym-sokoban with MIT License | 6 votes |
def render(self, mode='human', close=None, scale=1): assert mode in RENDERING_MODES img = self.get_image(mode, scale) if 'rgb_array' in mode: return img elif 'human' in mode: from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img) return self.viewer.isopen elif 'raw' in mode: arr_walls = (self.room_fixed == 0).view(np.int8) arr_goals = (self.room_fixed == 2).view(np.int8) arr_boxes = ((self.room_state == 4) + (self.room_state == 3)).view(np.int8) arr_player = (self.room_state == 5).view(np.int8) return arr_walls, arr_goals, arr_boxes, arr_player else: super(SokobanEnv, self).render(mode=mode) # just raise an exception
Example #3
Source File: cube_crash.py From ia-course with MIT License | 6 votes |
def render(self, mode='human', close=False): if close: if self.viewer is not None: self.viewer.close() self.viewer = None return if mode == 'rgb_array': return self.last_obs elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(self.last_obs) return self.viewer.isopen else: assert 0, "Render mode '%s' is not supported" % mode
Example #4
Source File: subproc_vec_env.py From pytorch-pommerman-rl with MIT License | 6 votes |
def render(self, mode='human'): for pipe in self.remotes: pipe.send(('render', None)) imgs = [pipe.recv() for pipe in self.remotes] bigimg = tile_images(imgs) if mode == 'human': if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(bigimg[:, :, ::-1]) elif mode == 'rgb_array': return bigimg else: raise NotImplementedError
Example #5
Source File: gridworld.py From qmap with MIT License | 6 votes |
def render(self, mode='human', close=False): if close: if self.viewer is not None: self.viewer.close() self.viewer = None img = self.get_obs()[0] if mode == 'rgb_array': return img elif mode == 'human': from gym.envs.classic_control import rendering from scipy.ndimage import zoom if self.viewer is None: self.viewer = rendering.SimpleImageViewer() img = zoom(img, [5, 5, 1], order=0) self.viewer.imshow(img) else: raise NotImplementedError # Generate ground truth Q-frames by finding the smallest number of steps towards all coordinates given a window position.
Example #6
Source File: memorize_digits.py From ia-course with MIT License | 6 votes |
def render(self, mode='human', close=False): if close: if self.viewer is not None: self.viewer.close() self.viewer = None return if mode == 'rgb_array': return self.last_obs elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(self.last_obs) return self.viewer.isopen else: assert 0, "Render mode '%s' is not supported" % mode
Example #7
Source File: pong_duel.py From ma-gym with Apache License 2.0 | 6 votes |
def render(self, mode='human'): img = copy.copy(self._base_img) for agent_i in range(self.n_agents): for row in range(self.agent_pos[agent_i][0] - 2, self.agent_pos[agent_i][0] + 3): fill_cell(img, (row, self.agent_pos[agent_i][1]), cell_size=CELL_SIZE, fill=AGENT_COLORS[agent_i]) ball_cells = self.__ball_cells fill_cell(img, ball_cells[0], cell_size=CELL_SIZE, fill=BALL_HEAD_COLOR) fill_cell(img, ball_cells[1], cell_size=CELL_SIZE, fill=BALL_TAIL_COLOR) fill_cell(img, ball_cells[2], cell_size=CELL_SIZE, fill=BALL_TAIL_COLOR) img = draw_border(img, border_width=2, fill='gray') img = np.asarray(img) if mode == 'rgb_array': return img elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img) return self.viewer.isopen
Example #8
Source File: memorize_digits.py From DRL_DeliveryDuel with MIT License | 6 votes |
def render(self, mode='human', close=False): if close: if self.viewer is not None: self.viewer.close() self.viewer = None return if mode == 'rgb_array': return self.last_obs elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(self.last_obs) return self.viewer.isopen else: assert 0, "Render mode '%s' is not supported" % mode
Example #9
Source File: cube_crash.py From DRL_DeliveryDuel with MIT License | 6 votes |
def render(self, mode='human', close=False): if close: if self.viewer is not None: self.viewer.close() self.viewer = None return if mode == 'rgb_array': return self.last_obs elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(self.last_obs) return self.viewer.isopen else: assert 0, "Render mode '%s' is not supported" % mode
Example #10
Source File: dm_suite_env.py From dm2gym with MIT License | 6 votes |
def render(self, mode='human', **kwargs): if 'camera_id' not in kwargs: kwargs['camera_id'] = 0 # Tracking camera use_opencv_renderer = kwargs.pop('use_opencv_renderer', False) img = self.env.physics.render(**kwargs) if mode == 'rgb_array': return img elif mode == 'human': if self.viewer is None: if not use_opencv_renderer: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer(maxwidth=1024) else: from . import OpenCVImageViewer self.viewer = OpenCVImageViewer() self.viewer.imshow(img) return self.viewer.isopen else: raise NotImplementedError
Example #11
Source File: atari_wrappers.py From ape-x with Apache License 2.0 | 6 votes |
def _render(self, mode='human', close=False): if close: return if mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(np.max(np.stack(self._obs_buffer), axis=0)) return np.max(np.stack(self._obs_buffer), axis=0) else: return np.max(np.stack(self._obs_buffer), axis=0) # class ClipRewardEnv(gym.RewardWrapper): # def _reward(self, reward): # """Bin reward to {+1, 0, -1} by its sign.""" # return np.sign(reward)
Example #12
Source File: doom_gym.py From sample-factory with MIT License | 6 votes |
def render(self, mode='human'): try: img = self.game.get_state().screen_buffer img = np.transpose(img, [1, 2, 0]) if mode == 'rgb_array': return img h, w = img.shape[:2] render_w = 1280 if w < render_w: render_h = int(render_w * h / w) img = cv2.resize(img, (render_w, render_h)) if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer(maxwidth=render_w) self.viewer.imshow(img) return img except AttributeError: return None
Example #13
Source File: vizdoom_env.py From SLM-Lab with MIT License | 6 votes |
def render(self, mode='human', close=False): if close: if self._viewer is not None: self._viewer.close() self._viewer = None return img = None state = self.game.get_state() if state is not None: img = state.screen_buffer if img is None: # at the end of the episode img = np.zeros(shape=self.observation_space.shape, dtype=np.uint8) if mode == 'rgb_array': return img elif mode is 'human': if self._viewer is None: self._viewer = rendering.SimpleImageViewer() self._viewer.imshow(util.to_opencv_image(img))
Example #14
Source File: subproc_vec_env.py From HardRLWithYoutube with MIT License | 6 votes |
def render(self, mode='human'): for pipe in self.remotes: pipe.send(('render', None)) imgs = [pipe.recv() for pipe in self.remotes] bigimg = tile_images(imgs) if mode == 'human': if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(bigimg[:, :, ::-1]) elif mode == 'rgb_array': return bigimg else: raise NotImplementedError
Example #15
Source File: gym_wrapper.py From bsuite with Apache License 2.0 | 5 votes |
def render(self, mode: str = 'rgb_array') -> Union[np.ndarray, bool]: if self._last_observation is None: raise ValueError('Environment not ready to render. Call reset() first.') if mode == 'rgb_array': return self._last_observation if mode == 'human': if self.viewer is None: # pylint: disable=import-outside-toplevel # pylint: disable=g-import-not-at-top from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(self._last_observation) return self.viewer.isopen
Example #16
Source File: vec_env.py From baselines with MIT License | 5 votes |
def get_viewer(self): if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() return self.viewer
Example #17
Source File: indoor_env.py From minos with MIT License | 5 votes |
def _render(self, mode='human', close=False): """Renders the environment. The set of supported modes varies per environment. (And some environments do not support rendering at all.) By convention, if mode is: - human: render to the current display or terminal and return nothing. Usually for human consumption. - rgb_array: Return an numpy.ndarray with shape (x, y, 3), representing RGB values for an x-by-y pixel image, suitable for turning into a video. - ansi: Return a string (str) or StringIO.StringIO containing a terminal-style text representation. The text can include newlines and ANSI escape sequences (e.g. for colors). Note: Make sure that your class's metadata 'render.modes' key includes the list of supported modes. It's recommended to call super() in implementations to use the functionality of this method. Args: mode (str): the mode to render with close (bool): close all open renderings """ if close: if self.viewer is not None: self.viewer.close() self.viewer = None # If we don't None out this reference pyglet becomes unhappy return if self._last_state is not None: img = self._last_state['observation']['sensors']['color']['data'] if len(img.shape) == 2: # assume gray img = np.dstack([img, img, img]) else: # assume rgba img = img[:, :, :-1] img = img.reshape((img.shape[1], img.shape[0], img.shape[2])) if mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img) elif mode == 'rgb_array': return img
Example #18
Source File: core.py From schema-games with MIT License | 5 votes |
def _render(self, mode='human', close=False): if self.reset_has_never_been_called: raise ResetHasNeverBeenCalledError if mode == 'rgb_array': return self._get_image() elif mode == 'human': if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(self._get_image())
Example #19
Source File: __init__.py From carla-rl with MIT License | 5 votes |
def get_viewer(self): if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() return self.viewer
Example #20
Source File: vizdoomenv.py From vizdoomgym with MIT License | 5 votes |
def render(self, mode="human"): if turn_off_rendering: return try: img = self.game.get_state().screen_buffer img = np.transpose(img, [1, 2, 0]) if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img) except AttributeError: pass
Example #21
Source File: cube_crash.py From DQN-DDPG_Stock_Trading with MIT License | 5 votes |
def render(self, mode='human'): if mode == 'rgb_array': return self.last_obs elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(self.last_obs) return self.viewer.isopen else: assert 0, "Render mode '%s' is not supported" % mode
Example #22
Source File: memorize_digits.py From DQN-DDPG_Stock_Trading with MIT License | 5 votes |
def render(self, mode='human'): if mode == 'rgb_array': return self.last_obs elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(self.last_obs) return self.viewer.isopen else: assert 0, "Render mode '%s' is not supported" % mode
Example #23
Source File: atari_env.py From DQN-DDPG_Stock_Trading with MIT License | 5 votes |
def render(self, mode='human'): img = self._get_image() if mode == 'rgb_array': return img elif mode == 'human': from gym.envs.classic_control import rendering if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img) return self.viewer.isopen
Example #24
Source File: doomenv.py From bezos with MIT License | 5 votes |
def render(self, mode='human'): try: img = self.game.get_state().screen_buffer img = np.transpose(img, [1, 2, 0]) if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img) except AttributeError: pass
Example #25
Source File: vizdoomenv.py From bezos with MIT License | 5 votes |
def render(self, mode='human'): try: img = self.game.get_state().screen_buffer img = np.transpose(img, [1, 2, 0]) if self.viewer is None: self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img) except AttributeError: pass
Example #26
Source File: dm_control.py From FractalAI with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, name: str = "cartpole-balance", visualize_reward: bool = True, n_repeat_action: int = 1, custom_death: "CustomDeath" = None): """ Creates DMControlEnv and initializes the environment. :param domain_name: match dm_control interface. :param task_name: match dm_control interface. :param visualize_reward: match dm_control interface. :param fixed_steps: The number of consecutive times that an action will be applied. This allows us to set the frequency at which the policy will play. :param custom_death: Pro hack to beat the shit out of DeepMind even further. """ from dm_control import suite domain_name, task_name = name.split("-") super(DMControlEnv, self).__init__(name=name, n_repeat_action=n_repeat_action) self._render_i = 0 self._env = suite.load(domain_name=domain_name, task_name=task_name, visualize_reward=visualize_reward) self._name = name self.viewer = [] self._last_time_step = None self._viewer = rendering.SimpleImageViewer() self._custom_death = custom_death self.reset()
Example #27
Source File: mupen64plus_env.py From gym-mupen64plus with MIT License | 5 votes |
def _render(self, mode='human', close=False): if close: if hasattr(self, 'viewer') and self.viewer is not None: self.viewer.close() self.viewer = None return img = self.pixel_array if mode == 'rgb_array': return img elif mode == 'human': if not hasattr(self, 'viewer') or self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() self.viewer.imshow(img)
Example #28
Source File: vec_env.py From SLM-Lab with MIT License | 5 votes |
def get_viewer(self): if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() return self.viewer
Example #29
Source File: __init__.py From vel with MIT License | 5 votes |
def get_viewer(self): if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() return self.viewer
Example #30
Source File: multiprocessing_env.py From rl_algorithms with MIT License | 5 votes |
def get_viewer(self): if self.viewer is None: from gym.envs.classic_control import rendering self.viewer = rendering.SimpleImageViewer() return self.viewer