'Tensorboard either shows unrelated outcome or does not start

I would like to use Tensorboard toghether with StableBaselines 3 to display the results of the reinforcement learning. I use the following code for that:

from stable_baselines3 import A2C
import os
from tensorflow.python.keras.callbacks import TensorBoard
from time import time


env = Custom_Env()
models_dir = "models/A2C"
logdir = "logs"

#tensorboard = TensorBoard(logdir)

timesteps = 1000
if not os.path.exists(models_dir):
    os.makedirs(models_dir)
    
if not os.path.exists(logdir):
    os.makedirs(logdir)
    


model = A2C('MlpPolicy', env, verbose=1, tensorboard_log=logdir)

timesteps = 1000
for i in range (1, 10):
    model.learn(total_timesteps=timesteps, reset_num_timesteps=False,  tb_log_name = "A2C")
    model.save(f"{models_dir}/{timesteps*i} ")

When I comment this line out #tensorboard = TensorBoard(logdir), I can start Tensorboard by typing tensorboard --logdir=logdir --host localhost --port 8088 into the console of Spyder and then start Tesorboard in the browser by typing in "http://localhost:8088 ". However, Tensorboard now shows something quite unreleated (seems to be a random thing) to my problem. It has something to do with PCA which I never used. When not commeting out the line tensorboard = TensorBoard(logdir), I can run the code but when I try to start Tensorboard by using tensorboard --logdir=logdir --host localhost --port 8088, I get an error "SyntaxError: invalid syntax".

Any idea what the problem is and how I can display the correct results in Tensorboard?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source