具有OpenAI的Jupyter笔记本|内核似乎已经死亡。它将自动重启

时间:2018-10-31 05:18:56

标签: python amazon-web-services amazon-ec2 jupyter-notebook ubuntu-16.04

我正在r5.large AWS EC2 Ubuntu Server 16.04 LTS(HVM)64位上运行Python3脚本。 我想在jupyter笔记本中显示Open AI'CartPole-v0'。

但是如图所示,在env.render(mode ='rgb_array')之后,内核死亡并重新启动。 为什么我的内核死了,然后重新启动。

enter image description here

import gym
from matplotlib import animation
from matplotlib import pyplot as plt
%matplotlib nbagg

env = gym.make('CartPole-v0')

observation = env.reset()
cum_reward = 0
frames = []
for t in range(5000):
    # Render into buffer. 
    frames.append(env.render(mode = 'rgb_array'))
    action = env.action_space.sample()
    observation, reward, done, info = env.step(action)
    if done:
        break
env.render(close=True)

fig = plt.gcf()
patch = plt.imshow(frames[0])
plt.axis('off')

def animate(i):
    patch.set_data(frames[i])

anim = animation.FuncAnimation(fig, animate, frames = len(frames),interval=50)
anim

anim.save("CartPole-v0.gif", writer = 'imagemagick')

以下是服务器的构建步骤。

构建步骤:

更新

$ sudo apt update
$ sudo apt upgrade

安装Anaconda

$ cd ~
$ wget https://repo.continuum.io/archive/Anaconda3-4.4.0-Linux-x86_64.sh
$ bash Anaconda3-4.4.0-Linux-x86_64.sh
$ export PATH=$PATH:/home/ubuntu/anaconda3/bin
$ source .bash_profile

Jupyter设置

$ jupyter-notebook --generate-config
$ ipython
In [1]: from notebook.auth import passwd

In [2]: passwd()
Enter password: 
Verify password: 
Out[2]: 'sha1:~~~'
In [3]: exit

写入配置

$ vi .jupyter/jupyter_notebook_config.py

c.IPKernelApp.pylab = 'inline'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.password = u'sha1:~~~'
c.NotebookApp.notebook_dir = u'/home/ubuntu/jupyter'

接下来,我安装了OpenAI库。

安装OpenAI库

$ pip install gym
$ pip install gym[atari]
$ sudo apt-get install -y python-pyglet python3-opengl zlib1g-dev libjpeg-dev patchelf \
        cmake swig libboost-all-dev libsdl2-dev libosmesa6-dev xvfb ffmpeg

运行jupyter笔记本

$ nohup xvfb-run -s "-screen 0 1400x900x24" jupyter notebook &

0 个答案:

没有答案