Skip to content

Commit

Permalink
Stop exporting deprecated LatestModuleExporter and register_module_fo…
Browse files Browse the repository at this point in the history
…r_export symbols

PiperOrigin-RevId: 582663489
  • Loading branch information
TensorFlow Hub Authors authored and copybara-github committed Nov 15, 2023
1 parent bbb0ca1 commit ed4b52f
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 448 deletions.
1 change: 1 addition & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ limitations under the License.
==============================================================================-->
# Current version 0.16.0-dev
* Under development
* Removed deprecated LatestModuleExporter and register_module_for_export API

# Current version 0.15.0
* Require Python 3.9+.
Expand Down
52 changes: 3 additions & 49 deletions tensorflow_hub/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,13 @@ py_library(
srcs_version = "PY3",
visibility = ["//visibility:public"],
deps = [
# Dependencies of the tensorflow_hub library.
":image_util",
":keras_layer",
":module",
":module_v2",
":native_module",
":saved_model_module",
"//tensorflow_hub:expect_tensorflow_installed",
":estimator",
":feature_column",
":feature_column_v2",
":config",
Expand All @@ -72,31 +71,6 @@ py_library(
],
)

py_library(
name = "estimator",
srcs = ["estimator.py"],
srcs_version = "PY3",
deps = [
":tf_utils",
"//tensorflow_hub:expect_tensorflow_compat_v1_estimator_installed",
"//tensorflow_hub:expect_tensorflow_installed",
],
)

py_test(
name = "estimator_test",
srcs = ["estimator_test.py"],
python_version = "PY3",
srcs_version = "PY3",
tags = ["notsan"], # b/111624588
deps = [
":tensorflow_hub",
"//tensorflow_hub:expect_tensorflow_compat_v1_estimator_installed",
"//tensorflow_hub:expect_tensorflow_installed",
":expect_tensorflow_hub_includes_estimator_apis",
],
)

py_library(
name = "feature_column",
srcs = ["feature_column.py"],
Expand All @@ -117,7 +91,6 @@ py_test(
":tensorflow_hub",
":test_utils",
"//tensorflow_hub:expect_numpy_installed",
"//tensorflow_hub:expect_tensorflow_compat_v1_estimator_installed",
"//tensorflow_hub:expect_tensorflow_installed",
":expect_tensorflow_hub_includes_feature_column_apis",
],
Expand All @@ -143,7 +116,6 @@ py_test(
":tensorflow_hub",
":test_utils",
"//tensorflow_hub:expect_numpy_installed",
"//tensorflow_hub:expect_tensorflow_estimator_installed",
"//tensorflow_hub:expect_tensorflow_installed",
":expect_tensorflow_hub_includes_feature_column_v2_apis",
],
Expand Down Expand Up @@ -439,8 +411,6 @@ py_test(
deps = [
":tensorflow_hub",
":test_utils",
"//tensorflow_hub:expect_tensorflow_compat_v1_estimator_installed",
"//tensorflow_hub:expect_tensorflow_estimator_installed",
"//tensorflow_hub:expect_tensorflow_installed",
],
)
Expand All @@ -461,12 +431,6 @@ py_library(
name = "expect_tensorflow_installed",
)

# We expect TensorFlow Hub to support Estimator related APIs (module exporter).
# This is for internal bookkeeping only and will always be true.
py_library(
name = "expect_tensorflow_hub_includes_estimator_apis",
)

# We expect TensorFlow Hub to support feature_column_v2 related APIs.
# This is for internal bookkeeping only and will always be true.
py_library(
Expand All @@ -479,18 +443,6 @@ py_library(
name = "expect_tensorflow_hub_includes_feature_column_apis",
)

# We expect TensorFlow Estimator to already be installed on the system.
# This is for internal bookkeeping only and will be true by virtue of having TensorFlow installed.
py_library(
name = "expect_tensorflow_estimator_installed",
)

# We expect TensorFlow V1 Estimator to already be installed on the system.
# This is for internal bookkeeping only and will be true by virtue of having TensorFlow installed.
py_library(
name = "expect_tensorflow_compat_v1_estimator_installed",
)

# We expect numpy to already be installed on the system, e.g. via
# `pip install numpy`
py_library(
Expand Down Expand Up @@ -566,6 +518,8 @@ py_library(
deps = [":resolver"],
)

# End of BUILD rules.

exports_files([
"copy.bara.sky",
])
3 changes: 1 addition & 2 deletions tensorflow_hub/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ def _ensure_tf_install():

# pylint: disable=g-import-not-at-top
# pylint: disable=g-bad-import-order
from tensorflow_hub.estimator import LatestModuleExporter
from tensorflow_hub.estimator import register_module_for_export
# Symbols exposed via tensorflow_hub.
from tensorflow_hub.feature_column_v2 import text_embedding_column_v2
from tensorflow_hub.feature_column import image_embedding_column
from tensorflow_hub.feature_column import sparse_text_embedding_column
Expand Down
59 changes: 0 additions & 59 deletions tensorflow_hub/feature_column_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import os
import unittest

import numpy as np
import tensorflow as tf
from tensorflow.compat.v1 import estimator as tf_estimator
import tensorflow_hub as hub

# pylint: disable=g-direct-tensorflow-import
Expand Down Expand Up @@ -172,36 +170,6 @@ def testDenseFeatures_shareAcrossApplication(self):
[5, 5, 5, 5]])
self.assertAllEqual(after_update_1, after_update_2)

def testWorksWithCannedEstimator(self):
comment_embedding_column = hub.text_embedding_column(
"comment", self.spec, trainable=False)
upvotes = tf.compat.v1.feature_column.numeric_column("upvotes")

feature_columns = [comment_embedding_column, upvotes]
estimator = tf_estimator.DNNClassifier(
hidden_units=[10],
feature_columns=feature_columns,
model_dir=self.get_temp_dir())

# This only tests that estimator apis are working with the feature
# column without throwing exceptions.
features = {
"comment": np.array([
["the quick brown fox"],
["spam spam spam"],
]),
"upvotes": np.array([
[20],
[1],
]),
}
labels = np.array([[1], [0]])
numpy_input_fn = tf_estimator.inputs.numpy_input_fn
input_fn = numpy_input_fn(features, labels, shuffle=True)
estimator.train(input_fn, max_steps=1)
estimator.evaluate(input_fn, steps=1)
estimator.predict(input_fn)

def testTrainableEmbeddingColumn(self):
feature_columns = [
hub.text_embedding_column("text", self.spec, trainable=True),
Expand Down Expand Up @@ -375,33 +343,6 @@ def testDenseFeatures_shareAcrossApplication(self):

self.assertAllClose(output_1, output_2)

def testWorksWithCannedEstimator(self):
image_column = hub.image_embedding_column("image", self.spec)
other_column = tf.compat.v1.feature_column.numeric_column("number")

feature_columns = [image_column, other_column]
estimator = tf_estimator.DNNClassifier(
hidden_units=[10],
feature_columns=feature_columns,
model_dir=self.get_temp_dir())

# This only tests that estimator apis are working with the feature
# column without throwing exceptions.
features = {
"image":
np.array([[[[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]]],
[[[0.7, 0.7, 0.7], [0.1, 0.2, 0.3]]]],
dtype=np.float32),
"number":
np.array([[20], [1]]),
}
labels = np.array([[1], [0]])
numpy_input_fn = tf_estimator.inputs.numpy_input_fn
input_fn = numpy_input_fn(features, labels, shuffle=True)
estimator.train(input_fn, max_steps=1)
estimator.evaluate(input_fn, steps=1)
estimator.predict(input_fn)

def testConfig(self):
module_path = os.path.join(self.get_temp_dir(), "module")
export_module_spec(self.spec, module_path)
Expand Down
54 changes: 0 additions & 54 deletions tensorflow_hub/feature_column_v2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import logging
import os
import numpy as np
from tensorflow import estimator as tf_estimator
import tensorflow.compat.v2 as tf
import tensorflow_hub as hub

Expand Down Expand Up @@ -172,59 +171,6 @@ def testLoadingDifferentFeatureColumnsFails(self):
".*not bound to checkpointed values.*"):
model_2.load_weights(checkpoint_path).assert_consumed()

def testWorksWithTF2DnnClassifier(self):
self.skipTest("b/154115879 - needs more investigation for timeout.")
comment_embedding_column = hub.text_embedding_column_v2(
"comment", self.model, trainable=False)
upvotes = tf.feature_column.numeric_column("upvotes")

feature_columns = [comment_embedding_column, upvotes]
estimator = tf_estimator.DNNClassifier(
hidden_units=[10],
feature_columns=feature_columns,
model_dir=self.get_temp_dir())

# This only tests that estimator apis are working with the feature
# column without throwing exceptions.
def input_fn():
features = {
"comment": np.array([
["the quick brown fox"],
["spam spam spam"],
]),
"upvotes": np.array([
[20],
[1],
]),
}
labels = np.array([[1], [0]])
return features, labels
estimator.train(input_fn, max_steps=1)
estimator.evaluate(input_fn, steps=1)
estimator.predict(input_fn)

def testWorksWithDNNEstimatorAndDataset(self):
self.skipTest("b/154115879 - needs more investigation for timeout.")
description_embeddings = hub.text_embedding_column_v2(
"descriptions", self.model_returning_dicts, output_key="outputs")

def input_fn():
features = dict(descriptions=tf.constant([["sentence"]]))
labels = tf.constant([[1]])
dataset = tf.data.Dataset.from_tensor_slices((features, labels))

data_batches = dataset.repeat().take(30).batch(5)
return data_batches

estimator = tf_estimator.DNNEstimator(
model_dir=os.path.join(self.get_temp_dir(), "estimator_export"),
hidden_units=[10],
head=tf_estimator.BinaryClassHead(),
feature_columns=[description_embeddings])

estimator.train(input_fn=input_fn, max_steps=1)


if __name__ == "__main__":
# This test is only supported in TF2 mode and only in TensorFlow version that
# has the following symbol (expected from TF2.3 onwards):
Expand Down
Loading

0 comments on commit ed4b52f

Please sign in to comment.