当前位置: 首页>>代码示例>>Python>>正文


Python rendering.SimpleImageViewer方法代码示例

本文整理汇总了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 
开发者ID:MaxSobolMark,项目名称:HardRLWithYoutube,代码行数:18,代码来源:subproc_vec_env.py

示例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) 
开发者ID:uber-research,项目名称:ape-x,代码行数:18,代码来源:atari_wrappers.py

示例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 
开发者ID:ArztSamuel,项目名称:DRL_DeliveryDuel,代码行数:21,代码来源:cube_crash.py

示例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. 
开发者ID:fabiopardo,项目名称:qmap,代码行数:21,代码来源:gridworld.py

示例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 
开发者ID:koulanurag,项目名称:ma-gym,代码行数:24,代码来源:pong_duel.py

示例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 
开发者ID:koulanurag,项目名称:ma-gym,代码行数:18,代码来源:switch_one_corridor.py

示例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 
开发者ID:alex-petrenko,项目名称:sample-factory,代码行数:23,代码来源:doom_gym.py

示例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 
开发者ID:mpSchrader,项目名称:gym-sokoban,代码行数:27,代码来源:sokoban_env.py

示例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 
开发者ID:zuoxingdong,项目名称:dm2gym,代码行数:22,代码来源:dm_suite_env.py

示例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)) 
开发者ID:kengz,项目名称:SLM-Lab,代码行数:21,代码来源:vizdoom_env.py

示例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 
开发者ID:MaxSobolMark,项目名称:HardRLWithYoutube,代码行数:17,代码来源:shmem_vec_env.py

示例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 
开发者ID:quantumiracle,项目名称:Reinforcement_Learning_for_Traffic_Light_Control,代码行数:7,代码来源:__init__.py

示例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 
开发者ID:ArztSamuel,项目名称:DRL_DeliveryDuel,代码行数:12,代码来源:atari_env.py

示例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 
开发者ID:medipixel,项目名称:rl_algorithms,代码行数:8,代码来源:multiprocessing_env.py

示例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 
开发者ID:honeynet,项目名称:droidbot,代码行数:10,代码来源:env.py


注:本文中的gym.envs.classic_control.rendering.SimpleImageViewer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。