Gymnasium 借游戏来学习人工智能

既然有了免费的linux系统+GPU,干脆演示一下使用drive+colab套件来训练模型。

!apt-get install -y build-essential swig

!pip install box2d-py

!pip install gymnasium[all]

!pip install gymnasium[atari] gymnasium[accept-rom-license]

!pip install stable_baselines3

!pip install moviepy

如果你要训练模型,记得选GPU,默认是CPU ,两者的速度完全不可同日而语。

为了保持连接避免断线,请记得在浏览器的console(F12)输入JS代码 - 

function ConnectButton(){
    console.log("Connect pushed"); 
    document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click() 
}
setInterval(ConnectButton,60000);

现在测试一下环境吧 = 

import gymnasium as gym
from gymnasium.wrappers import RecordVideo

env = gym.make("LunarLander-v2",render_mode="rgb_array")
env = RecordVideo(env, './video')
observation, info = env.reset(seed=42)
for _ in range(1000):
   action = env.action_space.sample()  # this is where you would insert your policy
   observation, reward, terminated, truncated, info = env.step(action)
 
   if terminated or truncated:
      observation, info = env.reset()
env.close()

您的进步和反馈是我最大的动力,小伙伴来个三连呗!共勉。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值