Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and render OpenAI-Gym on Windows

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to install and render OpenAI-Gym on Windows, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

OpenAI Gym is a good place to learn and develop reinforcement learning algorithms. It provides a lot of interesting games (the so-called "environment"), and you can use your strategy for testing. For example, it has some simple games, such as balancing the vertical bar on the trolley ("CartPole-v1"), swinging the pendulum to the upright position ("Pendulum-v0"), and some classic video games such as Space Invader and Pin Ball.

However, gym is designed to run on Linux. Although it can be installed on Windows using Conda or PIP, it cannot be displayed on Windows because its rendering is responsive on the Linux-based package PyVirtualDisplay. Therefore, it is very inconvenient to play OpenAI Gym on Windows.

So how do Windows users visualize gym?

A simple solution is to use Google Colab. It can be accessed through a web browser, and most of the packages are set up correctly. But Colab has its drawbacks:

Frequent session timeouts and disconnections. Your session may time out after the meal and all your data will be lost.

The machine configuration is not high. Even my Dell XPS laptop runs twice as fast as the free Colab on many neural network models. If you already have a good machine, why not use it?

It is not convenient to install a local drive. You need to do this every time you start a conversation.

Installing Linux / Windows dual booting is the cleanest solution. However, if you just want to do some coding from time to time, setting up a complete operating system seems to be too big a choice. Installing Linux VM takes less effort than dual booting, but it still requires a lot of effort to set up the entire virtual system, resolve potential compatibility issues, resolve library and package dependencies, and so on. Using the docker image should be easy, but the image generated by a quick search on docker hub will not run on my computer. The code on the other github has only "experimental" Windows support and requires building a seemingly complex Docker image from the source code. It is well known that building from source code on another operating system is far from straightforward.

Genevieve Hayes [3] describes a pure Windows solution in detail in this article. It uses a combination of Visual Studio, Conda, Pip and Xming. This is not a short list of steps. I followed these steps step by step, but still couldn't build atari-py and box2d. In addition, I'm a little worried that the Windows native solution may require some source code modifications in the future.

After evaluating many options, I finally built a minimalist docker image myself. It's not nearly as difficult as it sounds. But if you want to skip setting up the environment, you can enjoy Gym directly through the following three simple steps:

Download and install Docker

Pull my docker image from Dock:

Docker pull jxu305/openai_gym_docker:v1.0

Run the docker image from the command line (you can mount your favorite file if you like)

Docker run-p: 8888-it-v: jxu305/openai_gym_docker:v1.0

Or just launch from the Docker Desktop GUI

For ease of testing, I added a small notebook to the image to test the rendering sample environment: Cart Pole v1, Mountain Car v0, Pendulum v0, Lunar Lander v2, Space Invaders v0, and Car Racing v0.

If you are interested in how to make this docker, please read on. This is actually very simple, all you need is a Dockerfile with less than 30 lines. Here, I will introduce Dockerfile step by step.

First of all, to avoid building from scratch, I started with the jupyter notebook environment. Since Geron's machine learning books use tensorflow, I decided to build on jupyter/tensorflow-notebook images.

FROM jupyter/tensorflow-notebook

Next, install some of the libraries required to render the environment.

USER root

RUN apt-get update-y & &\

Apt-get install-y xvfb & &\

Apt-get install-y python-opengl

Then install OpenAI-gym, as well as PyVirtualDisplay.

USER ${NB_USER}

RUN pip install gym pyvirtualdisplay

That's all. With these lines of code, you can run and render

I added a few lines of code to Dockerfile to support environments that require Box2D, Toy Text, and Atari. For example, the classic lunar lander and space invader environment.

RUN apt-get install-y cmake & &\

Apt-get install-y zlib1g zlib1g-dev

RUN conda install swig

RUN pip install box2d-py atari_py pystan

The last two lines just copy some files into the image for testing convenience.

COPY. / example/env_render.ipynb / home/$ {NB_USER} / env_render.ipynb

COPY. / example/18_reinforcement_learning.ipynb / home/$ {NB_USER} / 18_reinforcement_learning.ipynb

That's what Dockerfile is all about. Building this simple docker is also easy, as long as you run the following command on the command line:

$docker build-t:.

Congratulations! All you have to do is build your own OpenAI-gym docker! Now you can start it with the Docker desktop and start your code.

Thank you for reading this article carefully. I hope the article "how to install and render OpenAI-Gym on Windows" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report