當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。