-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdino_web_callback.py
29 lines (21 loc) · 1013 Bytes
/
dino_web_callback.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
# Import os for file path management
import os
# Import Base Callback for saving models
from stable_baselines3.common.callbacks import BaseCallback
from game_drivers.dino_web_base_game_driver import DinoGameDriver
class DinoWebCallback(BaseCallback):
def __init__(self, check_freq, model_name, save_path, driver_type=DinoGameDriver.BASIC, verbose=1):
super(DinoWebCallback, self).__init__(verbose)
self.check_freq = check_freq
self.save_path = save_path
self.model_name = model_name + '_' + driver_type.name.lower()
##-------------------------------------##
def _init_callback(self):
if self.save_path is not None:
os.makedirs(self.save_path, exist_ok=True)
##-------------------------------------##
def _on_step(self):
if self.n_calls % self.check_freq == 0:
model_path = os.path.join(self.save_path, '{}_{}'.format(self.model_name, self.n_calls))
self.model.save(model_path)
return True