微信扫一扫打赏支持

【强化学习玩转超级马里奥】04-stable-baselines3 库介绍

【强化学习玩转超级马里奥】04-stable-baselines3 库介绍

stable-baselines3库介绍

github:https://github.com/DLR-RM/stable-baselines3

doc:https://stable-baselines3.readthedocs.io/en/master/

一、stable-baselines3库是干什么的

Stable Baselines3 (SB3) is a set of reliable implementations of reinforcement learning algorithms in PyTorch. It is the next major version of Stable Baselines.

二、为什么要用公共库

简单,方便

三、stable-baselines3简单实例

import gym

from stable_baselines3 import PPO
from stable_baselines3.common.env_util import make_vec_env

# Parallel environments
env = make_vec_env("CartPole-v1", n_envs=4)

model = PPO("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=25000)
model.save("ppo_cartpole")

del model # remove to demonstrate saving and loading

model = PPO.load("ppo_cartpole")

obs = env.reset()
# while True:
#     action, _states = model.predict(obs)
#     obs, rewards, dones, info = env.step(action)
#     env.render()
import gym

from stable_baselines3 import PPO
from stable_baselines3.common.env_util import make_vec_env

# Parallel environments
env = make_vec_env("CartPole-v1", n_envs=4)

model = PPO.load("ppo_cartpole")

obs = env.reset()
# while True:
#     action, _states = model.predict(obs)
#     obs, rewards, dones, info = env.step(action)
#     env.render()

四、没有训练的效果

import gym
env = gym.make("CartPole-v1")

done = True
for step in range(5000):
    if done:
        state = env.reset()
    state, reward, done, info = env.step(env.action_space.sample())
    env.render()

env.close()

五、不使用并行环境

import gym

from stable_baselines3 import PPO


env = gym.make("CartPole-v1")

model = PPO("MlpPolicy", env, verbose=1)
model.learn(total_timesteps=200)
model.save("ppo_cartpole1")

del model # remove to demonstrate saving and loading

model = PPO.load("ppo_cartpole1")

obs = env.reset()
done = True
while True:
    if done:
        state = env.reset()
    action, _states = model.predict(obs)
    obs, rewards, done, info = env.step(action)
    env.render()

视频位置

强化学习玩超级马里奥【2022 年 3 月最新】(学不会可以来打我)_哔哩哔哩_bilibili
https://www.bilibili.com/video/BV1iL411A7zo?spm_id_from=333.999.0.0

强化学习库 Stable-Baselines3_哔哩哔哩_bilibili
https://www.bilibili.com/video/BV1ca41187qB?spm_id_from=333.999.0.0

超参数调优框架 optuna_哔哩哔哩_bilibili
https://www.bilibili.com/video/BV1ni4y1C7Sv?spm_id_from=333.999.0.0

强化学习玩超级马里奥-读书编程笔记
https://fanrenyi.com/lesson/48

超参数调优框架 optuna-读书编程笔记
https://fanrenyi.com/lesson/49

强化学习库 Stable-Baselines3-读书编程笔记
https://fanrenyi.com/lesson/50

《强化学习玩超级马里奥》课程讲解如何用强化学习来训练超级马里奥。本课程是保姆级教程,通俗易懂,一步步带你敲代码。深度学习库用的 Pytorch,强化学习库用的是 Stable-Baselines3,超参数调优框架用的是 Optuna。代码及资料 github 地址:【 https://github.com/fry404006308/fry_course_materials/tree/master 】中的【220310_强化学习玩马里奥】

代码 github 位置

fry_course_materials/220310_强化学习玩马里奥 at master · fry404006308/fry_course_materials · GitHub
https://github.com/fry404006308/fry_course_materials/tree/master/220310_强化学习玩马里奥

博客位置

其它更多博客内容可以去 github 代码中查看

https://github.com/fry404006308/fry_course_materials/tree/master/

【强化学习玩转超级马里奥】05-最最简单的超级马里奥训练过程 - 范仁义 - 博客园
https://www.cnblogs.com/Renyi-Fan/p/16021552.html

【强化学习玩转超级马里奥】04-stable-baselines3 库介绍 - 范仁义 - 博客园
https://www.cnblogs.com/Renyi-Fan/p/16021529.html

【强化学习玩转超级马里奥】03-马里奥环境代码说明 - 范仁义 - 博客园
https://www.cnblogs.com/Renyi-Fan/p/16021518.html

【强化学习玩转超级马里奥】02-运行超级马里奥 - 范仁义 - 博客园
https://www.cnblogs.com/Renyi-Fan/p/16021507.html

【强化学习玩转超级马里奥】01-nes-py 包安装实例 - 范仁义 - 博客园
https://www.cnblogs.com/Renyi-Fan/p/16021496.html

【强化学习玩转超级马里奥】01-超级马里奥环境安装 - 范仁义 - 博客园
https://www.cnblogs.com/Renyi-Fan/p/16021460.html

【强化学习玩转超级马里奥】00-强化学习玩马里奥课程介绍 - 范仁义 - 博客园
https://www.cnblogs.com/Renyi-Fan/p/16021398.html

课程内容

【强化学习玩转超级马里奥】00-强化学习玩马里奥课程介绍

【强化学习玩转超级马里奥】01-超级马里奥环境安装

【强化学习玩转超级马里奥】01-nes-py 包安装实例

【强化学习玩转超级马里奥】02-运行超级马里奥

【强化学习玩转超级马里奥】03-马里奥环境代码说明

【强化学习玩转超级马里奥】04-stable-baselines3 库介绍

【强化学习玩转超级马里奥】05-最最简单的超级马里奥训练过程

【强化学习玩转超级马里奥】06-1-预处理与矢量化环境-预处理

【强化学习玩转超级马里奥】06-2-预处理与矢量化环境-矢量化环境

【强化学习玩转超级马里奥】07-1-模型训练参数设置-模型训练参数设置

【强化学习玩转超级马里奥】07-2-模型训练参数设置-修改参数接着训练

【强化学习玩转超级马里奥】07-3-模型训练参数设置-打印模型的参数

【强化学习玩转超级马里奥】08-保存最优模型

【强化学习玩转超级马里奥】09-1-隔多少步保存模型

【强化学习玩转超级马里奥】09-2-隔多少步保存模型-测试保存的模型

【强化学习玩转超级马里奥】10-阶段二训练与测试

【强化学习玩转超级马里奥】11-超参数调优库 optuna 介绍

【强化学习玩转超级马里奥】12-1-optuna 库选择超参数-optuna 库选择超参数

【强化学习玩转超级马里奥】12-2-optuna 库选择超参数-超参数选择具体实例

【强化学习玩转超级马里奥】12-3-optuna 库选择超参数-测试超参数调优出来的模型

【强化学习玩转超级马里奥】13-用选好超参数的模型去训练

posted @ 2022-03-18 14:08  范仁义  阅读(1425)  评论(0编辑  收藏  举报