I am new to reinforcement learning and I am trying to use OpenAI Gym environments.
First, I installed gym by this command: !pip install gym
in jupyter
And after running again to making sure it is installed completely, I got this output:
Requirement already satisfied: gym in c:\program files\anaconda3\lib\site-packages (0.10.5) Requirement already satisfied: pyglet>=1.2.0 in c:\program files\anaconda3\lib\site-packages (from gym) (1.3.2) Requirement already satisfied: six in c:\program files\anaconda3\lib\site-packages (from gym) (1.11.0) Requirement already satisfied: requests>=2.0 in c:\program files\anaconda3\lib\site-packages (from gym) (2.19.1) Requirement already satisfied: numpy>=1.10.4 in c:\program files\anaconda3\lib\site-packages (from gym) (1.13.3) Requirement already satisfied: future in c:\program files\anaconda3\lib\site-packages (from pyglet>=1.2.0->gym) (0.16.0) Requirement already satisfied: urllib3=1.21.1 in c:\program files\anaconda3\lib\site-packages (from requests>=2.0->gym) (1.23) Requirement already satisfied: certifi>=2017.4.17 in c:\program files\anaconda3\lib\site-packages (from requests>=2.0->gym) (2018.4.16) Requirement already satisfied: chardet=3.0.2 in c:\program files\anaconda3\lib\site-packages (from requests>=2.0->gym) (3.0.4) Requirement already satisfied: idna=2.5 in c:\program files\anaconda3\lib\site-packages (from requests>=2.0->gym) (2.7)
As mentioned on OpenAI Gym Doc page, I tried this code to make sure everything is fine:
import gym env = gym.make('CartPole-v0') for i_episode in range(20): observation = env.reset() #The process gets started by calling reset(), which returns an initial observation. for t in range(100): env.render() print(observation) action = env.action_space.sample() observation, reward, done, info = env.step(action) if done: print("Episode finished after {} timesteps".format(t+1)) break
After running this code, a new window opens and all things are exactly as provided video on doc page.
But the problem is when agent done (all episodes ran), kernel dies and restart again.
I found in some specific versions, gym.make(close=true)
could solve the problem. But not in the latest version of anaconda and Gym. the other solution is using this code: env = gym.make('name') env.close()
. but the problem is, this close()
function, will delete env
object so every time we create envrironment.
Regards
I don't know how to solve this, but I used a different code in gym-retro and it works pretty well.
env = retro.make(game="StreetFighterIISpecialChampionEdition-Genesis", state="ChunLiVsBlanka.1star")
env = wrapper(env)
model = PPO2.load("D:/Python/Projects/Hakisa/rl_model_1000000_steps")
obs = env.reset()
total_reward = []
steps = 0
end = False
while end != True and steps < 100:
env.render()
action, state = model.predict(obs)
obs, reward, end, info = env.step(action)
steps += 1
total_reward.append(reward)
time.sleep(0.05)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.