既然有了免费的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 RecordVideoenv = 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 policyobservation, reward, terminated, truncated, info = env.step(action)if terminated or truncated:observation, info = env.reset()
env.close()
