-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems reasonable. I'll check with the team, but I don't think there would be objections to this. Would you mind adding a small test for it? There seems to already be a test for using an explicit writer:
github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/hparams/_keras_test.py#L133
Sounds very reasonable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to the suggestions Riley left, there's a test failing, because the error message needs to be updated in this test:
github.com/tensorflow/tensorboard/blob/master/tensorboard/plugins/hparams/_keras_test.py#L168
additional linebreak Co-authored-by: Riley Jones <[email protected]>
removed trailing whitespace Co-authored-by: Riley Jones <[email protected]>
Thanks for the Change requests. |
@@ -62,10 +62,14 @@ 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" |
There was a problem hiding this comment.
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
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None" | |
"writer must be a `SummaryWriter`, `str`, or `PathLike`, not None" |
@@ -165,7 +174,7 @@ def test_reuse_failure(self): | |||
def test_invalid_writer(self): | |||
with self.assertRaisesRegex( | |||
TypeError, | |||
"writer must be a `SummaryWriter` or `str`, not None", | |||
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above
"writer must be a `SummaryWriter`, `str` or `PathLike`, not None", | |
"writer must be a `SummaryWriter`, `str`, or `PathLike`, not None" |
Motivation for features / changes
Most other Tensorflow functions accept Paths in other form than strings.
This small change makes the plugin more consistent and users do not need to cast their Path objects to string manually.
Technical description of changes
elif isinstance(writer, os.PathLike):
self._writer = tf.compat.v2.summary.create_file_writer(os.fsdecode(writer))
Detailed steps to verify changes work correctly (as executed by you)
Barely tested to be honest. Just ran the tutorial code here: https://www.tensorflow.org/tensorboard/hyperparameter_tuning_with_hparams
with my version
Alternate designs / implementations considered
Once all Tensorflow functions accept pathlikes instead of just strings the distinction between str and PathLike will be unnecessary.