Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not getting any TensorBoard logs for DQN model #506

Closed
saulable opened this issue Jul 7, 2021 · 2 comments · Fixed by #522
Closed

Not getting any TensorBoard logs for DQN model #506

saulable opened this issue Jul 7, 2021 · 2 comments · Fixed by #522
Labels
custom gym env Issue related to Custom Gym Env documentation Improvements or additions to documentation question Further information is requested

Comments

@saulable
Copy link

saulable commented Jul 7, 2021

Hi Guys,

I am having a problem with the DQN logging to TensorBoard, I don't get when the log is getting called. At the moment, to me it seems the log is only made when the "done" parameter returns True from step(), and this is only after the second iteration, done needs to return true twice?!

My code doesn't return a done = True unless it completely fails.

The code works fine in PPO method without the done returning true, and logs my values just fine at each iteration.

My data CSV is around 160k steps long. Am I missing something? Here's my model call. I also get the max score at every step when I print here, just my tensorboard is not working.... How do we get it working like PPO? I.E on every iteration after X steps? Thanks!

class TensorboardCallback(BaseCallback):
    Custom callback for plotting additional values in tensorboard.
 
    def __init__(self, verbose=0):
        super(TensorboardCallback, self).__init__(verbose)

    def _on_step(self) -> bool:
        # Log scalar value (here a random variable)
        # print(self.locals["rewards"])
        # print(self.locals)
        global top_score
        score = self.locals["infos"][0]["score"]
        self.logger.record('a_score', score)
        if (top_score == None):
            top_score = score
            model.save("./model_DQN")
        elif (score > top_score):
            top_score = score
            model.save("./model_DQN")
        return True

model = DQN("MlpPolicy", env, verbose=1, tensorboard_log="./a2c_cartpole_tensorboard/", device="cpu")
model.learn(total_timesteps=int(1e10), callback=TensorboardCallback())
@saulable saulable added custom gym env Issue related to Custom Gym Env question Further information is requested labels Jul 7, 2021
@araffin
Copy link
Member

araffin commented Jul 7, 2021

I.E on every iteration after X steps?

You have to manually call self.logger.dump(self.num_timesteps) for that in the callback, see issue #457 and PR #492

@saulable
Copy link
Author

saulable commented Jul 7, 2021

I.E on every iteration after X steps?

You have to manually call self.logger.dump(self.num_timesteps) for that in the callback, see issue #457 and PR #492

Excellent. Quick fix with the below code done the damage. Muchos gracias! Can we update the docs with this 👍

if (self.num_timesteps % 10000 == 0):
            self.logger.dump(self.num_timesteps)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom gym env Issue related to Custom Gym Env documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
2 participants