Skip to content

Commit

Permalink
hparams: extract api wrapper over summary_v2
Browse files Browse the repository at this point in the history
Summary:
We’ll shortly extract the Keras callback out of `summary_v2` such that
`summary_v2` does not need to depend on TensorFlow. It will continue to
be exposed from `api`.

Part of a reorganization to match the structure described here:
<#2139 (comment)>

wchargin-branch: hparams-api-refactor
  • Loading branch information
wchargin committed Apr 30, 2019
1 parent 9734867 commit 0fac530
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
26 changes: 25 additions & 1 deletion tensorboard/plugins/hparams/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ py_binary(
srcs = ["hparams_demo.py"],
srcs_version = "PY2AND3",
deps = [
":api",
":protos_all_py_pb2",
":summary",
":summary_v2",
"//tensorboard:expect_absl_app_installed",
"//tensorboard:expect_absl_flags_installed",
"//tensorboard:expect_numpy_installed",
Expand Down Expand Up @@ -149,6 +149,30 @@ sh_test(
],
)

py_library(
name = "api",
srcs = ["api.py"],
srcs_version = "PY2AND3",
visibility = [
"//visibility:public",
],
deps = [
":summary_v2",
],
)

py_test(
name = "api_test",
size = "small",
srcs = ["api_test.py"],
srcs_version = "PY2AND3",
deps = [
":api",
":summary_v2",
"//tensorboard:test",
],
)

py_library(
name = "summary_v2",
srcs = ["summary_v2.py"],
Expand Down
37 changes: 37 additions & 0 deletions tensorboard/plugins/hparams/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Experimental public APIs for the HParams plugin."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorboard.plugins.hparams import summary_v2


Discrete = summary_v2.Discrete
Domain = summary_v2.Domain
HParam = summary_v2.HParam
IntInterval = summary_v2.IntInterval
KerasCallback = summary_v2.KerasCallback
Metric = summary_v2.Metric
RealInterval = summary_v2.RealInterval
hparams_config = summary_v2.hparams_config


del absolute_import
del division
del print_function
del summary_v2
35 changes: 35 additions & 0 deletions tensorboard/plugins/hparams/api_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from tensorboard import test
from tensorboard.plugins.hparams import api
from tensorboard.plugins.hparams import summary_v2


class ApiTest(test.TestCase):

def test_has_core_attributes(self):
self.assertIs(api.HParam, summary_v2.HParam)

def test_has_keras_dependent_attributes(self):
self.assertIs(api.KerasCallback, summary_v2.KerasCallback)


if __name__ == "__main__":
test.main()
2 changes: 1 addition & 1 deletion tensorboard/plugins/hparams/hparams_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from six.moves import xrange # pylint: disable=redefined-builtin
import tensorflow as tf

from tensorboard.plugins.hparams import summary_v2 as hp
from tensorboard.plugins.hparams import api as hp


if int(tf.__version__.split(".")[0]) < 2:
Expand Down

0 comments on commit 0fac530

Please sign in to comment.