Logger¶
To overwrite the default logger, you can pass one to the algorithm.
Available formats are ["stdout", "csv", "log", "tensorboard", "json"]
.
Warning
When passing a custom logger object,
this will overwrite tensorboard_log
and verbose
settings
passed to the constructor.
from stable_baselines3 import A2C
from stable_baselines3.common.logger import configure
tmp_path = "/tmp/sb3_log/"
# set up logger
new_logger = configure(tmp_path, ["stdout", "csv", "tensorboard"])
model = A2C("MlpPolicy", "CartPole-v1", verbose=1)
# Set new logger
model.set_logger(new_logger)
model.learn(10000)
- class stable_baselines3.common.logger.Figure(figure, close)[source]¶
Figure data class storing a matplotlib figure and whether to close the figure after logging it
- Parameters:
figure (
figure
) – figure to logclose (
bool
) – if true, close the figure after logging it
- exception stable_baselines3.common.logger.FormatUnsupportedError(unsupported_formats, value_description)[source]¶
- class stable_baselines3.common.logger.HumanOutputFormat(filename_or_file)[source]¶
- class stable_baselines3.common.logger.Image(image, dataformats)[source]¶
Image data class storing an image and data format
- Parameters:
image (
Union
[Tensor
,ndarray
,str
]) – image to logdataformats (
str
) – Image data format specification of the form NCHW, NHWC, CHW, HWC, HW, WH, etc. More info in add_image method doc at https://pytorch.org/docs/stable/tensorboard.html Gym envs normally use ‘HWC’ (channel last)
- class stable_baselines3.common.logger.Logger(folder, output_formats)[source]¶
The logger class.
- Parameters:
folder (
Optional
[str
]) – the logging locationoutput_formats (
List
[KVWriter
]) – the list of output formats
- debug(*args)[source]¶
Write the sequence of args, with no separators, to the console and output files (if you’ve configured an output file). Using the DEBUG level.
- Parameters:
args – log the arguments
- Return type:
None
- error(*args)[source]¶
Write the sequence of args, with no separators, to the console and output files (if you’ve configured an output file). Using the ERROR level.
- Parameters:
args – log the arguments
- Return type:
None
- get_dir()[source]¶
Get directory that log files are being written to. will be None if there is no output directory (i.e., if you didn’t call start)
- Return type:
str
- Returns:
the logging directory
- info(*args)[source]¶
Write the sequence of args, with no separators, to the console and output files (if you’ve configured an output file). Using the INFO level.
- Parameters:
args – log the arguments
- Return type:
None
- log(*args, level=20)[source]¶
Write the sequence of args, with no separators, to the console and output files (if you’ve configured an output file).
- level: int. (see logger.py docs) If the global logger level is higher than
the level argument here, don’t print to stdout.
- Parameters:
args – log the arguments
level (
int
) – the logging level (can be DEBUG=10, INFO=20, WARN=30, ERROR=40, DISABLED=50)
- Return type:
None
- record(key, value, exclude=None)[source]¶
Log a value of some diagnostic Call this once for each diagnostic quantity, each iteration If called many times, last value will be used.
- Parameters:
key (
str
) – save to log this keyvalue (
Any
) – save to log this valueexclude (
Union
[str
,Tuple
[str
,...
],None
]) – outputs to be excluded
- Return type:
None
- record_mean(key, value, exclude=None)[source]¶
The same as record(), but if called many times, values averaged.
- Parameters:
key (
str
) – save to log this keyvalue (
Any
) – save to log this valueexclude (
Union
[str
,Tuple
[str
,...
],None
]) – outputs to be excluded
- Return type:
None
- class stable_baselines3.common.logger.Video(frames, fps)[source]¶
Video data class storing the video frames and the frame per seconds
- Parameters:
frames (
Tensor
) – frames to create the video fromfps (
Union
[float
,int
]) – frames per second
- stable_baselines3.common.logger.configure(folder=None, format_strings=None)[source]¶
Configure the current logger.
- Parameters:
folder (
Optional
[str
]) – the save location (if None, $SB3_LOGDIR, if still None, tempdir/SB3-[date & time])format_strings (
Optional
[List
[str
]]) – the output logging format (if None, $SB3_LOG_FORMAT, if still None, [‘stdout’, ‘log’, ‘csv’])
- Return type:
- Returns:
The logger object.
- stable_baselines3.common.logger.filter_excluded_keys(key_values, key_excluded, _format)[source]¶
Filters the keys specified by
key_exclude
for the specified format- Parameters:
key_values (
Dict
[str
,Any
]) – log dictionary to be filteredkey_excluded (
Dict
[str
,Union
[str
,Tuple
[str
,...
]]]) – keys to be excluded per format_format (
str
) – format for which this filter is run
- Return type:
Dict
[str
,Any
]- Returns:
dict without the excluded keys
- stable_baselines3.common.logger.make_output_format(_format, log_dir, log_suffix='')[source]¶
return a logger for the requested format
- Parameters:
_format (
str
) – the requested format to log to (‘stdout’, ‘log’, ‘json’ or ‘csv’ or ‘tensorboard’)log_dir (
str
) – the logging directorylog_suffix (
str
) – the suffix for the log file
- Return type:
- Returns:
the logger