forked from Sentdex/SC2RL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trainppo.py
46 lines (33 loc) · 997 Bytes
/
trainppo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from stable_baselines3 import PPO
import os
from sc2env import Sc2Env
import time
from wandb.integration.sb3 import WandbCallback
import wandb
model_name = f"{int(time.time())}"
models_dir = f"models/{model_name}/"
logdir = f"logs/{model_name}/"
conf_dict = {"Model": "v19",
"Machine": "Main",
"policy":"MlpPolicy",
"model_save_name": model_name}
run = wandb.init(
project=f'SC2RLv6',
entity="sentdex",
config=conf_dict,
sync_tensorboard=True, # auto-upload sb3's tensorboard metrics
save_code=True, # optional
)
if not os.path.exists(models_dir):
os.makedirs(models_dir)
if not os.path.exists(logdir):
os.makedirs(logdir)
env = Sc2Env()
model = PPO('MlpPolicy', env, verbose=1, tensorboard_log=logdir)
TIMESTEPS = 10000
iters = 0
while True:
print("On iteration: ", iters)
iters += 1
model.learn(total_timesteps=TIMESTEPS, reset_num_timesteps=False, tb_log_name=f"PPO")
model.save(f"{models_dir}/{TIMESTEPS*iters}")