From c5b63854fed8b15d35d14fd6a14176546c40b509 Mon Sep 17 00:00:00 2001 From: Aakash Kumar Nain Date: Thu, 16 May 2019 20:54:03 +0530 Subject: [PATCH 1/7] add metrics module --- tensorflow_addons/metrics/BUILD | 14 +++++++++++ tensorflow_addons/metrics/README.md | 34 +++++++++++++++++++++++++++ tensorflow_addons/metrics/__init__.py | 19 +++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 tensorflow_addons/metrics/BUILD create mode 100644 tensorflow_addons/metrics/README.md create mode 100644 tensorflow_addons/metrics/__init__.py diff --git a/tensorflow_addons/metrics/BUILD b/tensorflow_addons/metrics/BUILD new file mode 100644 index 0000000000..93979903a1 --- /dev/null +++ b/tensorflow_addons/metrics/BUILD @@ -0,0 +1,14 @@ +licenses(["notice"]) # Apache 2.0 + +package(default_visibility = ["//visibility:public"]) + +py_library( + name = "metrics", + srcs = [ + "__init__.py", + ], + srcs_version = "PY2AND3", + deps = [ + "//tensorflow_addons/utils", + ], +) diff --git a/tensorflow_addons/metrics/README.md b/tensorflow_addons/metrics/README.md new file mode 100644 index 0000000000..752afddf4b --- /dev/null +++ b/tensorflow_addons/metrics/README.md @@ -0,0 +1,34 @@ +# Addons - Metrics + +## Maintainers +| Submodule | Maintainers | Contact Info | +|:---------- |:------------- |:--------------| +| | | | + +## Contents +| Submodule | Activation | Reference | +|:----------------------- |:-------------------|:---------------| +| | | | + + +## Contribution Guidelines +#### Standard API +In order to conform with the current API standard, all metrics +must: + * Be a `tf.function`. + * Have the signature `fn(input, axis=-1, name=None)`. + * [Register as a keras global object](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/utils/python/keras_utils.py) + so it can be serialized properly. + * Add the addon to the `py_library` in this sub-package's BUILD file. + +#### Testing Requirements + * Simple unittests that demonstrate the layer is behaving as expected. + * When applicable, run all unittests with TensorFlow's + `@run_in_graph_and_eager_modes` (for test method) + or `run_all_in_graph_and_eager_modes` (for TestCase subclass) + decorator. + * Add a `py_test` to this sub-package's BUILD file. + +#### Documentation Requirements + * Update the table of contents in this sub-package's README. + diff --git a/tensorflow_addons/metrics/__init__.py b/tensorflow_addons/metrics/__init__.py new file mode 100644 index 0000000000..5ef2f13641 --- /dev/null +++ b/tensorflow_addons/metrics/__init__.py @@ -0,0 +1,19 @@ +# 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. +# ============================================================================== +"""A module containing metrics that conform to Keras API.""" + +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function From f85ba5000b5df0eaf2a2efe01bf86af61985df6b Mon Sep 17 00:00:00 2001 From: Aakash Kumar Nain Date: Thu, 16 May 2019 20:54:36 +0530 Subject: [PATCH 2/7] add Metric class import --- tensorflow_addons/utils/keras_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorflow_addons/utils/keras_utils.py b/tensorflow_addons/utils/keras_utils.py index a738e406ff..0de1a6df86 100644 --- a/tensorflow_addons/utils/keras_utils.py +++ b/tensorflow_addons/utils/keras_utils.py @@ -21,6 +21,7 @@ # TODO: find public API alternative to these from tensorflow.python.keras.losses import LossFunctionWrapper # pylint: disable=unused-import +from tensorflow.python.keras.metrics import Metric # pylint: disable=unused-import def register_keras_custom_object(cls): From a8b9f400296623aed1a3baf0036c3a55db7c733e Mon Sep 17 00:00:00 2001 From: Aakash Kumar Nain Date: Thu, 16 May 2019 20:55:15 +0530 Subject: [PATCH 3/7] add import for metrics module --- tensorflow_addons/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorflow_addons/__init__.py b/tensorflow_addons/__init__.py index aae841e757..0e1bf2fa17 100644 --- a/tensorflow_addons/__init__.py +++ b/tensorflow_addons/__init__.py @@ -75,6 +75,7 @@ def _ensure_tf_install(): from tensorflow_addons import image from tensorflow_addons import layers from tensorflow_addons import losses +from tensorflow_addons import metrics from tensorflow_addons import optimizers from tensorflow_addons import rnn from tensorflow_addons import seq2seq From b1753bc751bb0b33762dd0f6d42965a3fed1fda6 Mon Sep 17 00:00:00 2001 From: Aakash Kumar Nain Date: Thu, 16 May 2019 20:57:30 +0530 Subject: [PATCH 4/7] add metrics module --- tensorflow_addons/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/tensorflow_addons/BUILD b/tensorflow_addons/BUILD index 43e7ae6f63..e2df92782c 100644 --- a/tensorflow_addons/BUILD +++ b/tensorflow_addons/BUILD @@ -13,6 +13,7 @@ py_library( "//tensorflow_addons/image", "//tensorflow_addons/layers", "//tensorflow_addons/losses", + "//tensorflow_addons/metrics", "//tensorflow_addons/optimizers", "//tensorflow_addons/rnn", "//tensorflow_addons/seq2seq", From afd064653d17775a7690d5ab711120d030695f2d Mon Sep 17 00:00:00 2001 From: Aakash Kumar Nain Date: Sat, 18 May 2019 11:49:27 +0530 Subject: [PATCH 5/7] remove internal Metric import as it is already in public API --- tensorflow_addons/utils/keras_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tensorflow_addons/utils/keras_utils.py b/tensorflow_addons/utils/keras_utils.py index 0de1a6df86..a738e406ff 100644 --- a/tensorflow_addons/utils/keras_utils.py +++ b/tensorflow_addons/utils/keras_utils.py @@ -21,7 +21,6 @@ # TODO: find public API alternative to these from tensorflow.python.keras.losses import LossFunctionWrapper # pylint: disable=unused-import -from tensorflow.python.keras.metrics import Metric # pylint: disable=unused-import def register_keras_custom_object(cls): From 3563871109367974b12e111b1d00a9827f85980c Mon Sep 17 00:00:00 2001 From: Aakash Kumar Nain Date: Sat, 18 May 2019 11:54:10 +0530 Subject: [PATCH 6/7] update testing requirements --- tensorflow_addons/metrics/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tensorflow_addons/metrics/README.md b/tensorflow_addons/metrics/README.md index 752afddf4b..291c816838 100644 --- a/tensorflow_addons/metrics/README.md +++ b/tensorflow_addons/metrics/README.md @@ -15,14 +15,13 @@ #### Standard API In order to conform with the current API standard, all metrics must: - * Be a `tf.function`. - * Have the signature `fn(input, axis=-1, name=None)`. + * Inherit from `tf.metrics.Metric`. * [Register as a keras global object](https://github.com/tensorflow/addons/blob/master/tensorflow_addons/utils/python/keras_utils.py) so it can be serialized properly. * Add the addon to the `py_library` in this sub-package's BUILD file. #### Testing Requirements - * Simple unittests that demonstrate the layer is behaving as expected. + * Simple unittests that demonstrate the metric is behaving as expected. * When applicable, run all unittests with TensorFlow's `@run_in_graph_and_eager_modes` (for test method) or `run_all_in_graph_and_eager_modes` (for TestCase subclass) From 23701333526364034106e604598d707b7b42d9a5 Mon Sep 17 00:00:00 2001 From: Aakash Kumar Nain Date: Sat, 18 May 2019 13:50:54 +0530 Subject: [PATCH 7/7] remove extra line --- tensorflow_addons/metrics/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/tensorflow_addons/metrics/README.md b/tensorflow_addons/metrics/README.md index 291c816838..a6ae7ec2e3 100644 --- a/tensorflow_addons/metrics/README.md +++ b/tensorflow_addons/metrics/README.md @@ -30,4 +30,3 @@ must: #### Documentation Requirements * Update the table of contents in this sub-package's README. -