本文整理匯總了Python中gym.envs.classic_control.rendering.SimpleImageViewer方法的典型用法代碼示例。如果您正苦於以下問題:Python rendering.SimpleImageViewer方法的具體用法?Python rendering.SimpleImageViewer怎麽用?Python rendering.SimpleImageViewer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類gym.envs.classic_control.rendering
的用法示例。
在下文中一共展示了rendering.SimpleImageViewer方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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
示例2: _render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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)
示例3: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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
示例4: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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.
示例5: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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
示例6: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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
示例7: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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
示例8: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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
示例9: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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
示例10: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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))
示例11: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
def render(self, mode='human'):
for pipe in self.parent_pipes:
pipe.send(('render', None))
imgs = [pipe.recv() for pipe in self.parent_pipes]
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
示例12: get_viewer
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
def get_viewer(self):
if self.viewer is None:
from gym.envs.classic_control import rendering
self.viewer = rendering.SimpleImageViewer()
return self.viewer
示例13: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
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
示例14: get_viewer
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
def get_viewer(self):
if self.viewer is None:
from gym.envs.classic_control import rendering
self.viewer = rendering.SimpleImageViewer()
return self.viewer
示例15: render
# 需要導入模塊: from gym.envs.classic_control import rendering [as 別名]
# 或者: from gym.envs.classic_control.rendering import SimpleImageViewer [as 別名]
def render(self, mode='human'):
if mode == 'human':
from gym.envs.classic_control import rendering
if self.viewer is None:
self.viewer = rendering.SimpleImageViewer()
print(self.device.get_current_state().to_dict())
#self.viewer.imshow(self.device.get_current_state())
return self.viewer.isopen