-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrain_model.py
More file actions
38 lines (31 loc) · 1.14 KB
/
Copy pathtrain_model.py
File metadata and controls
38 lines (31 loc) · 1.14 KB
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
#! /usr/bin/env python3
from environment import RaceEnvironment
from stable_baselines3 import PPO
import time
import os
import glob
EPISODES = 10
if __name__ == "__main__":
models_dir = "models/PPO" + str(int(time.time()))
log_dir = "logs/PPO" + str(int(time.time()))
if not os.path.exists(models_dir):
os.makedirs(models_dir)
if not os.path.exists(log_dir):
os.makedirs(log_dir)
tracks_path = "tracks/"
track_files = glob.glob(os.path.join(tracks_path, "*.track"))
print("----Available Tracks----")
for i in range(len(track_files)):
print(f"[{i+1}]: {os.path.basename(track_files[i])}")
while True:
selected = int(input("Select Track: "))
if selected < len(track_files) + 1:
track_path = track_files[selected-1]
break
angle = int(input("Start Angle: "))
env = RaceEnvironment(track_path, start_angle=angle)
env.reset()
model = PPO("MlpPolicy", env, verbose=1, tensorboard_log=log_dir)
for episode in range(1, EPISODES + 1):
model.learn(total_timesteps=5000, reset_num_timesteps=False)
model.save(f"{models_dir}/{episode}")