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

Added support for pathlib paths as a logdir using the recommended os.PathLike class. #5905

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions tensorboard/plugins/hparams/_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Use `tensorboard.plugins.hparams.api` to access this module's contents.
"""


import os
mspils marked this conversation as resolved.
Show resolved Hide resolved
import tensorflow as tf

from tensorboard.plugins.hparams import api_pb2
Expand All @@ -39,7 +39,7 @@ def __init__(self, writer, hparams, trial_id=None):

Args:
writer: The `SummaryWriter` object to which hparams should be
written, or a logdir (as a `str`) to be passed to
written, or a logdir (as a `str` or `PathLike`) to be passed to
`tf.summary.create_file_writer` to create such a writer.
hparams: A `dict` mapping hyperparameters to the values used in
this session. Keys should be the names of `HParam` objects used
Expand All @@ -62,10 +62,12 @@ def __init__(self, writer, hparams, trial_id=None):
summary_v2.hparams_pb(self._hparams, trial_id=self._trial_id)
if writer is None:
raise TypeError(
"writer must be a `SummaryWriter` or `str`, not None"
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nitpick here but it would be nice to keep the formatting consistent

Suggested change
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None"
"writer must be a `SummaryWriter`, `str`, or `PathLike`, not None"

)
elif isinstance(writer, str):
self._writer = tf.compat.v2.summary.create_file_writer(writer)
elif isinstance(writer, os.PathLike):
self._writer = tf.compat.v2.summary.create_file_writer(os.fsdecode(writer))
arcra marked this conversation as resolved.
Show resolved Hide resolved
else:
self._writer = writer

Expand Down