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


Python Emulator.full_image方法代码示例

本文整理汇总了Python中emulator.Emulator.full_image方法的典型用法代码示例。如果您正苦于以下问题:Python Emulator.full_image方法的具体用法?Python Emulator.full_image怎么用?Python Emulator.full_image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在emulator.Emulator的用法示例。


在下文中一共展示了Emulator.full_image方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Visualize

# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import full_image [as 别名]
class Visualize(object):
    def __init__(self):
        self.session = tf.InteractiveSession()

        self.emulator = Emulator(settings)
        settings['num_actions'] = len(self.emulator.actions)

        with tf.variable_scope('model'):
            self.model = Model(settings)

        self.session.run(tf.initialize_all_variables())

        self.saver = tf.train.Saver(max_to_keep=1000000)
        checkpoint = tf.train.get_checkpoint_state("networks")
        if checkpoint and checkpoint.model_checkpoint_path:
            self.saver.restore(self.session, checkpoint.model_checkpoint_path)
            print("Loaded checkpoint: {}".format(checkpoint.model_checkpoint_path))
        else:
            raise RuntimeError("Unable to load checkpoint")

        cv2.startWindowThread()
        cv2.namedWindow("preview")
        cv2.namedWindow("full")

    def epsilon(self, test=False):
        return settings['final_epsilon']

    def choose_action(self, test=False):
        if np.random.rand() < self.epsilon(test):
            return random.randrange(len(self.emulator.actions)) 
        else:
            predictions = self.model.act_network.readout.eval({
                self.model.images: [self.images]
            })[0]
            print predictions, np.argmax(predictions)
            return np.argmax(predictions)

    def episode(self, test=False, push_to=None):
        self.emulator.reset()
        self.images = np.dstack((self.emulator.image(),) * settings['phi_length'])

        total_reward = 0
        updates = 0

        while True:
            action = self.choose_action(test)
            reward = self.emulator.act(action)
            image = self.emulator.image()
            cv2.imshow('preview', image)
            cv2.imshow('full', self.emulator.full_image())
            terminal = self.emulator.terminal()

            if reward > 0:
                print "reward:", reward

            if terminal:
                break

            self.images = np.dstack((image, self.images[:,:,1:]))
            total_reward += reward

            time.sleep(0.1)

        return total_reward
开发者ID:amharc,项目名称:jnp3,代码行数:66,代码来源:visualize.py


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