1. 程式人生 > >強化學習系列3:Open AI的baselines和Spinning Up

強化學習系列3:Open AI的baselines和Spinning Up

1. Baselines簡介

Baselines是一個傳統強化學習的資源庫,github地址為:https://github.com/openai/baselines
Baselines需要python3的環境,建議使用3.6版本。安裝openmpi和相關庫(tensorflow、gym),mac可以使用brew安裝,ubuntu可以使用apt-get,centos可以使用pip安裝。

git clone https://github.com/openai/baselines.git
cd baselines
pip install -e .

用下面的語句檢查是否安裝成功。如果提示缺少某個庫,安裝即可

pip install pytest
pytest

安裝完可進行視覺化:

python -m baselines.run --alg=ppo2 --env=PongNoFrameskip-v4 --num_timesteps=2e7 --save_path=~/models/pong_20M_ppo2
python -m baselines.run --alg=ppo2 --env=PongNoFrameskip-v4 --num_timesteps=0 --load_path=~/models/pong_20M_ppo2 --play

根據官方文件,spinning up實現的演算法包括:

  • A2C
  • ACER
  • ACKTR
  • DDPG
  • DQN
  • GAIL
  • HER
  • PPO1
  • PPO2
  • TRPO

2. Spinning Up簡介

spinning up是一個深度強化學習的很好的資源,其網址是:https://spinningup.openai.com/en/latest/
首先需要python3.6環境,建議下載anaconda3~這裡要注意安裝版本問題,目前使用python3.5和python3.7都存在問題。然後安裝openmpi和相關庫(tensorflow、gym),mac可以使用brew安裝,ubuntu可以使用apt-get,centos可以使用pip安裝。接下來執行下面的步驟:

git clone https://github.com/openai/spinningup.git
cd spinningup
pip install -e .

用下面的語句檢查是否安裝成功。如果提示缺少某個庫,安裝即可

python -m spinup.run ppo --hid "[32,32]" --env LunarLander-v2 --exp_name installtest --gamma 0.999

安裝完可進行視覺化:

python -m spinup.run test_policy data/installtest/installtest_s0
python -m spinup.run plot data/installtest/installtest_s0

根據官方文件,spinning up實現的演算法包括:

  • Vanilla Policy Gradient (VPG)
  • Trust Region Policy Optimization (TRPO)
  • Proximal Policy Optimization (PPO)
  • Deep Deterministic Policy Gradient (DDPG)
  • Twin Delayed DDPG (TD3)
  • Soft Actor-Critic (SAC)