OpenAI Gym (https://gym.openai.com) is an open source Python toolkit that offers many simulated environments to help you develop, compare, and train reinforcement learning algorithms, so you don't have to buy all the sensors and train your robot in the real environment, which can be costly in both time and money. In this section, we'll show you how to develop, compare, and train different reinforcement learning models on Raspberry Pi using TensorFlow in an OpenAI Gym's simulated environment called CartPole (https://gym.openai.com/envs/CartPole-v0).
To install OpenAI Gym, run the following commands:
git clone https://github.com/openai/gym.git
cd gym
sudo pip install -e .
You can verify that you have TensorFlow 1.6 and gym installed by running pip list (the last part of the Setting up TensorFlow on Raspberry Pi section covered how to install TensorFlow 1.6):
pi@raspberrypi:~ $ pip list
gym (0.10.4, /home/pi/gym)
tensorflow (1.6.0)
Or you can start iPython then import TensorFlow and gym:
pi@raspberrypi:~ $ ipython
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
IPython 5.5.0 -- An enhanced Interactive Python.
In [1]: import tensorflow as tf
In [2]: import gym
In [3]: tf.__version__
Out[3]: '1.6.0'
In [4]: gym.__version__
Out[4]: '0.10.4'
We're now all set to use TensorFlow and gym to build some interesting reinforcement learning model running on Raspberry Pi.