Fix default logdir for TensorBoard Keras callback on Windows

As cl/235232824, but this one probably hits production users who do not
specify a logdir, because the default argument value is not portable.
For root cause, see:
<#26021>

Tested:
Added a regression test. On Unix, the test passes both before and after
this change. On Windows, the test fails before this change with

    tensorflow.python.framework.errors_impl.NotFoundError: Failed to create a directory: ./logs\train; No such file or directory [Op:CreateSummaryFileWriter]

and passes after this change.

RELNOTES: n/a
PiperOrigin-RevId: 236228230
This commit is contained in:
William Chargin 2019-02-28 17:20:58 -08:00 committed by TensorFlower Gardener
parent 48f2aa607a
commit e91d746e0b
3 changed files with 27 additions and 2 deletions

View File

@ -1149,7 +1149,7 @@ class TensorBoard(Callback):
# pylint: enable=line-too-long
def __init__(self,
log_dir='./logs',
log_dir='logs',
histogram_freq=0,
write_graph=True,
write_images=False,

View File

@ -1048,6 +1048,31 @@ class TestTensorBoardV2(keras_parameterized.TestCase):
model.compile('sgd', 'mse', run_eagerly=testing_utils.should_run_eagerly())
return model
def test_TensorBoard_default_logdir(self):
"""Regression test for cross-platform pathsep in default logdir."""
os.chdir(self.get_temp_dir())
model = self._get_model()
x, y = np.ones((10, 10, 10, 1)), np.ones((10, 1))
tb_cbk = keras.callbacks.TensorBoard() # no logdir specified
model.fit(
x,
y,
batch_size=2,
epochs=2,
validation_data=(x, y),
callbacks=[tb_cbk])
summary_file = list_summaries(logdir='.')
train_dir = os.path.join('.', 'logs', 'train')
validation_dir = os.path.join('.', 'logs', 'validation')
self.assertEqual(
summary_file.scalars, {
_ObservedSummary(logdir=train_dir, tag='epoch_loss'),
_ObservedSummary(logdir=validation_dir, tag='epoch_loss'),
})
def test_TensorBoard_basic(self):
model = self._get_model()
x, y = np.ones((10, 10, 10, 1)), np.ones((10, 1))

View File

@ -5,7 +5,7 @@ tf_class {
is_instance: "<type \'object\'>"
member_method {
name: "__init__"
argspec: "args=[\'self\', \'log_dir\', \'histogram_freq\', \'write_graph\', \'write_images\', \'update_freq\', \'profile_batch\'], varargs=None, keywords=kwargs, defaults=[\'./logs\', \'0\', \'True\', \'False\', \'epoch\', \'2\'], "
argspec: "args=[\'self\', \'log_dir\', \'histogram_freq\', \'write_graph\', \'write_images\', \'update_freq\', \'profile_batch\'], varargs=None, keywords=kwargs, defaults=[\'logs\', \'0\', \'True\', \'False\', \'epoch\', \'2\'], "
}
member_method {
name: "on_batch_begin"