Build and Train General AI in OpenAI Gym: Initial Setup by sykochica

View this thread on steempeak.com
· @sykochica ·
$8.13
Build and Train General AI in OpenAI Gym: Initial Setup
The [OpenAI Universe](https://universe.openai.com/) project seeks to decentralized artificial intelligence by allowing anybody to build bots that ideally can learn to play thousands of video games well. Games ranging from classic Atari, Minecraft to Grand Theft Auto V are available in this environment, but the actual building of a bot (or agent) to act in them is left to us. This is where OpenAI Gym comes in to play.
<center>http://i.imgur.com/Yt5Ojbo.jpg</center>
Instead of having to make a bot for each individual game (i.e. task-specific AI,) the goal here is to make one bot to play many games (i.e. general AI) well without knowing anything about it at the start. All we are going to have available is the ability to view the screen (visual recognition) and what controls are available such as an Atari paddle (moving left/right) or joystick (left/right/up/down and button.)

When I first read up on this, it was stated that you only needed 9 lines of Python code (which is true) to get started! That sounded too awesome to not give it a try! 

However getting the **environment** setup to be able to run these 9 lines of code successfully was another matter. Having mostly been a Windows user, this ended up taking me a little longer than I expected, with the project only supporting Linux and OSX (Apple's operating system.) 

But as of yesterday I have a running version. While the image below may not look terribly exciting, it took me some time to get an Atari game to run and render. From here I can finally start the fun part of working on the actual intelligence of the bots to play these games.
<center>http://i.imgur.com/4AUF1Do.jpg</center>
<center>http://i.imgur.com/Xs4cJOi.png</center>

## <center>Reinforcement Learning</center>
OpenAI Universe is what sets up the environments that our bots are going to play within. This can be any of the thousands of games they already have available and can even have multiple going at the same time. 
OpenAI Gym is where we are able to build and put our game bots (or agents) to then be put into the game universe. From here our agents are able to read the game screen and try to maximize their "score." This is how we are able to close the loop for reinforcement learning.
<center>http://i.imgur.com/b2ssgOv.png</center>
Using the example of a Super Mario game, a simple game bot (agent) can be to just press right, getting a higher score the farther to the right you go. As we all know, there lot's of ways we can be killed (ending the game) such as getting hit by a monster, falling down a hole, etc. So just pressing right will only get us so far, over time we need to find a way to adapt our instruction of only pressing right to include things like jumping, shooting fireballs, etc. This is where we will end up making use of reinforcement learning.

The game world is loaded up by OpenAI Universe (the Environment,) the game bot is loaded with OpenAI Gym (the agent) and over time we will refine our actions to get the highest score (reward) possible by finishing the level. 
Follow up posts will include what I do with the actual bot training with this one solely discussing the setup.

<center>http://i.imgur.com/Xs4cJOi.png</center>
## <center>How to Setup Open AI Universe and Gym</center>
**[NOTE: There are many ways you can get OpenAI running. This was just MY successful method.]**

For those who run Windows to get a linux environment download [VirtualBox](https://www.virtualbox.org/) and install it. Next you'll need to download the linux (in my case Ubuntu 16.04) system that we'll be using from [here.](http://releases.ubuntu.com/16.04/) This file (.iso) is about 1.5 GB so it may take a little while depending on your internet connection. Make sure to save this somewhere you can easily find it, such as your desktop.

Now we'll create your first virtual machine running Ubuntu by following [these steps.](http://askubuntu.com/questions/142549/how-to-install-ubuntu-on-virtualbox) Make sure to do the last step of removing the installation file (the .iso you downloaded) from the "optical drive." Otherwise when you restart your virtual machine it will try to start the installation process all over again. [If you follow the instructions, say YES to force unmount when prompted.]

From here I followed [this guide](https://alliseesolutions.wordpress.com/2016/12/08/openai-universe-installation-guide-ubuntu-16-04/) which uses [Anaconda](https://www.continuum.io/) that includes many of the libraries we are going to need such as Scipy and Numpy. Make sure to follow the "For Ubuntu 16.04" instructions, not the 14.04 ones. Everything in this guide worked well for me, except for the Tensorflow 11.0 section. [**Pip didn't work for me with Tensorflow**]

If you get messages that the Tensorflow wheel isn't compantible/available, just goto [here](https://www.tensorflow.org/get_started/os_setup#anaconda_installation) to follow the anaconda installation which has you run the commands:
`conda create -n tensorflow python=3.5`

`$ source activate tensorflow`
`(tensorflow)$  # Your prompt should change`

`# Linux/Mac OS X, Python 2.7/3.4/3.5, CPU only:`
`(tensorflow)$ conda install -c conda-forge tensorflow`

After you have Tensorflow installed you can go back to [this Guide](https://alliseesolutions.wordpress.com/2016/12/08/openai-universe-installation-guide-ubuntu-16-04/) and pick back up at the heading of "Next we can get started by installing Docker:".

This will walk you through the setup of Docker, OpenAI Universe and OpenAI Gym.
At the end it will have you install a started agent for playing Pong. To get the MsPacman game running that I had in my screenshot, just save this code into a python file (I used test.py):
```
import gym
env = gym.make('MsPacman-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample()) # take a random action
```
This code came from [here.](https://gym.openai.com/docs)

Additional Resource:
[OpenAI Universe Documentation](https://github.com/openai/universe)
[Open AI Gym Documenation](https://gym.openai.com/docs)
[OpenAI – Universe Installation Guide Ubuntu 16.04](https://alliseesolutions.wordpress.com/2016/12/08/openai-universe-installation-guide-ubuntu-16-04/)
[Tensorflow Guide](https://www.tensorflow.org/get_started/os_setup)

http://i.imgur.com/sKiCvWa.png
<center>http://i.imgur.com/Xs4cJOi.png</center>
## <center> @winstonwolfe's Crowdsourced Steemit Video </center>
<center><iframe width="560" height="315" src="https://www.youtube.com/embed/xg81u-24hE8" frameborder="0" allowfullscreen></iframe></center>
## <center>Are you new to Steemit and Looking for Answers? - Try https://www.steemithelp.net.</center>
<center>[![](http://i1280.photobucket.com/albums/a485/emailtooaj/JoinUs_BB_gif_zpsgyozsqu2.gif)
](https://steemit.com/beyondbitcoin/@sykochica/how-and-why-to-join-beyond-bitcoin-mumble)</center>
<center>http://i.imgur.com/tCAIqAB.png</center>
Image Sources:
[MultiGame Panel](https://universe.openai.com/)
[Screenshot is from me]
[Reinforcement Learning](https://github.com/nnrg/opennero/wiki/SystemOverview)
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 90 others
properties (23)
post_id1,756,841
authorsykochica
permlinkbuild-and-train-general-ai-in-openai-gym-initial-setup
categoryai
json_metadata"{"format": "markdown", "links": ["https://universe.openai.com/", "https://www.virtualbox.org/", "http://releases.ubuntu.com/16.04/", "http://askubuntu.com/questions/142549/how-to-install-ubuntu-on-virtualbox", "https://alliseesolutions.wordpress.com/2016/12/08/openai-universe-installation-guide-ubuntu-16-04/", "https://www.continuum.io/", "https://www.tensorflow.org/get_started/os_setup#anaconda_installation", "https://gym.openai.com/docs", "https://github.com/openai/universe", "https://www.tensorflow.org/get_started/os_setup", "https://www.steemithelp.net", "https://steemit.com/beyondbitcoin/@sykochica/how-and-why-to-join-beyond-bitcoin-mumble", "https://github.com/nnrg/opennero/wiki/SystemOverview"], "app": "steemit/0.1", "tags": ["ai", "technology", "programming", "python", "gaming"], "users": ["winstonwolfe"], "image": ["http://i.imgur.com/Yt5Ojbo.jpg"]}"
created2017-01-14 18:36:00
last_update2017-01-14 18:36:00
depth0
children5
net_rshares36,761,308,686,372
last_payout2017-02-14 19:37:33
cashout_time1969-12-31 23:59:59
total_payout_value6.776 SBD
curator_payout_value1.355 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length7,100
author_reputation120,534,427,956,805
root_title"Build and Train General AI in OpenAI Gym: Initial Setup"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (154)
@steemgold ·
nice post
properties (22)
post_id1,756,858
authorsteemgold
permlinkre-sykochica-build-and-train-general-ai-in-openai-gym-initial-setup-20170114t183912447z
categoryai
json_metadata"{"app": "steemit/0.1", "tags": ["ai"]}"
created2017-01-14 18:39:15
last_update2017-01-14 18:39:15
depth1
children0
net_rshares0
last_payout2017-02-14 19:37:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length9
author_reputation51,549,234,710,828
root_title"Build and Train General AI in OpenAI Gym: Initial Setup"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@automaton ·
That's cool!
properties (22)
post_id1,757,151
authorautomaton
permlinkre-sykochica-build-and-train-general-ai-in-openai-gym-initial-setup-20170114t194340863z
categoryai
json_metadata"{"app": "steemit/0.1", "tags": ["ai"]}"
created2017-01-14 19:43:42
last_update2017-01-14 19:43:42
depth1
children1
net_rshares0
last_payout2017-02-14 19:37:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length12
author_reputation2,803,998,505,223
root_title"Build and Train General AI in OpenAI Gym: Initial Setup"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@sykochica ·
Thank you! I'll show how the actual bot building and training goes in future posts.
properties (22)
post_id1,757,312
authorsykochica
permlinkre-automaton-re-sykochica-build-and-train-general-ai-in-openai-gym-initial-setup-20170114t201251311z
categoryai
json_metadata"{"app": "steemit/0.1", "tags": ["ai"]}"
created2017-01-14 20:12:45
last_update2017-01-14 20:12:45
depth2
children0
net_rshares0
last_payout2017-02-14 19:37:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length83
author_reputation120,534,427,956,805
root_title"Build and Train General AI in OpenAI Gym: Initial Setup"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@justtryme90 ·
Great post @sykochica, we need more programming explanations like this!
properties (22)
post_id1,758,196
authorjusttryme90
permlinkre-sykochica-build-and-train-general-ai-in-openai-gym-initial-setup-20170114t233604083z
categoryai
json_metadata"{"app": "steemit/0.1", "users": ["sykochica"], "tags": ["ai"]}"
created2017-01-14 23:36:03
last_update2017-01-14 23:36:03
depth1
children1
net_rshares0
last_payout2017-02-14 19:37:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length71
author_reputation140,173,741,834,676
root_title"Build and Train General AI in OpenAI Gym: Initial Setup"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@sykochica ·
Thank you! I plan to get some more programming posts out, even if not all with openAI specifically, but at least something AI or game related.
👍  
properties (23)
post_id1,763,161
authorsykochica
permlinkre-justtryme90-re-sykochica-build-and-train-general-ai-in-openai-gym-initial-setup-20170115t191452499z
categoryai
json_metadata"{"app": "steemit/0.1", "tags": ["ai"]}"
created2017-01-15 19:14:51
last_update2017-01-15 19:14:51
depth2
children0
net_rshares3,878,133,572
last_payout2017-02-14 19:37:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length142
author_reputation120,534,427,956,805
root_title"Build and Train General AI in OpenAI Gym: Initial Setup"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (1)