- 損失やエピソードごとのリターンなどのメトリクスを記録します。
- ゲームをプレイするエージェントの動画をアップロードします。
- トレーニング済みモデルを保存します。
- モデルのハイパーパラメーターをログします。
- モデルの勾配ヒストグラムをログします。
SB3 Experimentsをログする

Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Help us improve these docs. Take our quick survey.
W&B を Stable Baselines3 と統合して、強化学習の実験をトラッキングし、トレーニングのパフォーマンスをログします。
from wandb.integration.sb3 import WandbCallback
model.learn(..., callback=WandbCallback())

| 引数 | 用途 |
|---|---|
verbose | sb3 出力の詳細レベル |
model_save_path | モデルを保存するフォルダーのパス。デフォルト値は None で、その場合モデルはログされません |
model_save_freq | モデルを保存する頻度 |
gradient_save_freq | 勾配をログする頻度。デフォルト値は 0 のため、勾配はログされません |
import gym
from stable_baselines3 import PPO
from stable_baselines3.common.monitor import Monitor
from stable_baselines3.common.vec_env import DummyVecEnv, VecVideoRecorder
import wandb
from wandb.integration.sb3 import WandbCallback
config = {
"policy_type": "MlpPolicy",
"total_timesteps": 25000,
"env_name": "CartPole-v1",
}
run = wandb.init(
project="sb3",
config=config,
sync_tensorboard=True, # sb3のtensorboardメトリクスを自動アップロード
monitor_gym=True, # エージェントがゲームをプレイする動画を自動アップロード
save_code=True, # 任意
)
def make_env():
env = gym.make(config["env_name"])
env = Monitor(env) # リターンなどの統計を記録
return env
env = DummyVecEnv([make_env])
env = VecVideoRecorder(
env,
f"videos/{run.id}",
record_video_trigger=lambda x: x % 2000 == 0,
video_length=200,
)
model = PPO(config["policy_type"], env, verbose=1, tensorboard_log=f"runs/{run.id}")
model.learn(
total_timesteps=config["total_timesteps"],
callback=WandbCallback(
gradient_save_freq=100,
model_save_path=f"models/{run.id}",
verbose=2,
),
)
run.finish()
Was this page helpful?