mirror of
https://github.com/wassname/kair_algorithms_draft.git
synced 2026-09-09 11:25:10 +08:00
Refactoring demo collector (#56)
This commit is contained in:
@@ -80,7 +80,7 @@ class AbstractAgent(object):
|
||||
path = os.path.join("./save/" + save_name + "_ep_" + str(n_episode) + ".pt")
|
||||
torch.save(params, path)
|
||||
|
||||
print ("[INFO] Saved the model and optimizer to", path)
|
||||
print("[INFO] Saved the model and optimizer to", path)
|
||||
|
||||
@abstractmethod
|
||||
def write_log(self, *args):
|
||||
@@ -109,7 +109,7 @@ class AbstractAgent(object):
|
||||
score += reward
|
||||
step += 1
|
||||
|
||||
print (
|
||||
print(
|
||||
"[INFO] episode %d\tstep: %d\ttotal score: %d"
|
||||
% (i_episode, step, score)
|
||||
)
|
||||
|
||||
@@ -201,7 +201,7 @@ class Agent(SACAgent):
|
||||
def pretrain(self):
|
||||
"""Pretraining steps."""
|
||||
pretrain_loss = list()
|
||||
print ("[INFO] Pre-Train %d steps." % self.hyper_params["PRETRAIN_STEP"])
|
||||
print("[INFO] Pre-Train %d steps." % self.hyper_params["PRETRAIN_STEP"])
|
||||
for i_step in range(1, self.hyper_params["PRETRAIN_STEP"] + 1):
|
||||
loss = self.update_model()
|
||||
pretrain_loss.append(loss) # for logging
|
||||
|
||||
@@ -180,7 +180,7 @@ class Agent(TD3Agent):
|
||||
def pretrain(self):
|
||||
"""Pretraining steps."""
|
||||
pretrain_loss = list()
|
||||
print ("[INFO] Pre-Train %d steps." % self.hyper_params["PRETRAIN_STEP"])
|
||||
print("[INFO] Pre-Train %d steps." % self.hyper_params["PRETRAIN_STEP"])
|
||||
for i_step in range(1, self.hyper_params["PRETRAIN_STEP"] + 1):
|
||||
loss = self.update_model()
|
||||
pretrain_loss.append(loss) # for logging
|
||||
|
||||
@@ -264,7 +264,7 @@ class Agent(AbstractAgent):
|
||||
def load_params(self, path):
|
||||
"""Load model and optimizer parameters."""
|
||||
if not os.path.exists(path):
|
||||
print ("[ERROR] the input path does not exist. ->", path)
|
||||
print("[ERROR] the input path does not exist. ->", path)
|
||||
return
|
||||
|
||||
params = torch.load(path)
|
||||
@@ -281,7 +281,7 @@ class Agent(AbstractAgent):
|
||||
if self.hyper_params["AUTO_ENTROPY_TUNING"]:
|
||||
self.alpha_optimizer.load_state_dict(params["alpha_optim"])
|
||||
|
||||
print ("[INFO] loaded the model and optimizer from", path)
|
||||
print("[INFO] loaded the model and optimizer from", path)
|
||||
|
||||
def save_params(self, n_episode):
|
||||
"""Save model and optimizer parameters."""
|
||||
@@ -306,7 +306,7 @@ class Agent(AbstractAgent):
|
||||
"""Write log about loss and score"""
|
||||
total_loss = loss.sum()
|
||||
|
||||
print (
|
||||
print(
|
||||
"[INFO] episode %d, episode_step %d, total step %d, total score: %d\n"
|
||||
"total loss: %.3f actor_loss: %.3f qf_1_loss: %.3f qf_2_loss: %.3f "
|
||||
"vf_loss: %.3f alpha_loss: %.3f\n"
|
||||
|
||||
@@ -177,7 +177,7 @@ class Agent(AbstractAgent):
|
||||
def load_params(self, path):
|
||||
"""Load model and optimizer parameters."""
|
||||
if not os.path.exists(path):
|
||||
print ("[ERROR] the input path does not exist. ->", path)
|
||||
print("[ERROR] the input path does not exist. ->", path)
|
||||
return
|
||||
|
||||
params = torch.load(path)
|
||||
@@ -189,7 +189,7 @@ class Agent(AbstractAgent):
|
||||
self.critic2_target.load_state_dict(params["critic2_target_state_dict"])
|
||||
self.actor_optim.load_state_dict(params["actor_optim_state_dict"])
|
||||
self.critic_optim.load_state_dict(params["critic_optim_state_dict"])
|
||||
print ("[INFO] loaded the model and optimizer from", path)
|
||||
print("[INFO] loaded the model and optimizer from", path)
|
||||
|
||||
def save_params(self, n_episode):
|
||||
"""Save model and optimizer parameters."""
|
||||
@@ -210,7 +210,7 @@ class Agent(AbstractAgent):
|
||||
"""Write log about loss and score"""
|
||||
total_loss = loss.sum()
|
||||
|
||||
print (
|
||||
print(
|
||||
"[INFO] total_steps: %d episode: %d total score: %d, total loss: %f\n"
|
||||
"actor_loss: %.3f critic1_loss: %.3f critic2_loss: %.3f\n"
|
||||
% (self.total_steps, i, score, total_loss, loss[0], loss[1], loss[2])
|
||||
|
||||
Reference in New Issue
Block a user