windowsでTensorFlow その14
1999 ワード
概要
windowsのTensorFlowの環境で、OpenAiやってみた。
'Pendulum-v0'を手でやってみた。
写真
サンプルコード
from __future__ import print_function
import math
import sys
import gym
import gym.spaces
import numpy as np
from gym import core, spaces
from gym.utils import seeding
from numpy import sin, cos, pi
import time
env = gym.make('Pendulum-v0')
ROLLOUT_TIME = 1000
SKIP_CONTROL = 0
human_agent_action = 0
human_wants_restart = False
human_sets_pause = False
def key_press(key, mod):
global human_agent_action, human_wants_restart, human_sets_pause
if key == 0xff0d:
human_wants_restart = True
if key == 32:
human_sets_pause = not human_sets_pause
a = int(key - ord('0'))
if a == 0:
a = -1
if a == 1:
a = 1
human_agent_action = a
def key_release(key, mod):
global human_agent_action
a = int(key - ord('0'))
if a == 0:
a = -1
if a == 1:
a = 1
if human_agent_action == a:
human_agent_action = 0
env.reset()
env.render()
env.unwrapped.viewer.window.on_key_press = key_press
env.unwrapped.viewer.window.on_key_release = key_release
def rollout(env):
global human_agent_action, human_wants_restart, human_sets_pause
human_wants_restart = False
obser = env.reset()
skip = 0
for t in range(ROLLOUT_TIME):
if not skip:
a = human_agent_action
skip = SKIP_CONTROL
else:
skip -= 1
print(a)
obser, r, done, info = env.step([a])
env.render()
if done:
break
if human_wants_restart:
break
while 1:
rollout(env)
Author And Source
この問題について(windowsでTensorFlow その14), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/fd5cd520b54527dff7d9著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .