本文整理汇总了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