Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 4dc28ce

Browse files
BrianWiedertensorflower-gardener
authored andcommitted
Update references of tensorflow/python:platform to use the public API if available and remove references to the deprecated tensorflow/python:platform target
PiperOrigin-RevId: 524913413
1 parent c77347d commit 4dc28ce

File tree

7 files changed

+33
-28
lines changed

7 files changed

+33
-28
lines changed

tensorflow_estimator/python/estimator/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,7 @@ py_library(
768768
name = "analytics_tools",
769769
srcs = ["tools/analytics.py"],
770770
srcs_version = "PY3",
771+
deps = ["//tensorflow_estimator/python/estimator:expect_tensorflow_installed"],
771772
)
772773

773774
py_test(
@@ -1906,7 +1907,7 @@ py_test(
19061907
srcs_version = "PY3",
19071908
deps = [
19081909
":estimator_export",
1909-
":expect_tensorflow_installed",
1910+
"//tensorflow_estimator/python/estimator:expect_tensorflow_installed",
19101911
],
19111912
)
19121913

tensorflow_estimator/python/estimator/early_stopping.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import os
2020

2121
import tensorflow as tf
22-
from tensorflow.python.platform import tf_logging
2322
from tensorflow_estimator.python.estimator import estimator as estimator_lib
2423
from tensorflow_estimator.python.estimator.estimator_export import estimator_export
2524

@@ -578,15 +577,15 @@ def after_run(self, run_context, run_values):
578577
should_early_stop = run_values.results['stop_var']
579578

580579
if should_early_stop > 0:
581-
tf_logging.info('Early stopping requested, suspending run.')
580+
tf.compat.v1.logging.info('Early stopping requested, suspending run.')
582581
run_context.request_stop()
583582
return
584583
if self._timer.should_trigger_for_step(global_step):
585584
self._timer.update_last_triggered_step(global_step)
586585
if self._should_stop_fn():
587586
run_context.session.run(
588587
self._stop_op, feed_dict={self._stop_placeholder: 1})
589-
tf_logging.info('Requesting early stopping at global step %d',
588+
tf.compat.v1.logging.info('Requesting early stopping at global step %d',
590589
global_step)
591590
else:
592591
run_context.session.run(

tensorflow_estimator/python/estimator/estimator.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from tensorflow.python.eager import context
3636
from tensorflow.python.eager import monitoring
3737
from tensorflow.python.framework import ops
38-
from tensorflow.python.platform import tf_logging as logging
3938
from tensorflow.python.profiler import trace
4039
from tensorflow.python.saved_model import path_helpers
4140
from tensorflow.python.summary import summary
@@ -349,15 +348,17 @@ def train(self,
349348
if max_steps is not None:
350349
start_step = _load_global_step_from_checkpoint_dir(self._model_dir)
351350
if max_steps <= start_step:
352-
logging.info('Skipping training since max_steps has already saved.')
351+
tf.compat.v1.logging.info(
352+
'Skipping training since max_steps has already saved.'
353+
)
353354
return self
354355

355356
hooks = _check_hooks_type(hooks)
356357
hooks.extend(self._convert_train_steps_to_hooks(steps, max_steps))
357358

358359
saving_listeners = _check_listeners_type(saving_listeners)
359360
loss = self._train_model(input_fn, hooks, saving_listeners)
360-
logging.info('Loss for final step: %s.', loss)
361+
tf.compat.v1.logging.info('Loss for final step: %s.', loss)
361362
return self
362363

363364
def _convert_train_steps_to_hooks(self, steps, max_steps):
@@ -1021,9 +1022,11 @@ def _get_features_from_input_fn(self, input_fn, mode):
10211022

10221023
def _validate_features_in_predict_input(self, result):
10231024
if not _has_dataset_or_queue_runner(result):
1024-
logging.warning('Input graph does not use tf.data.Dataset or contain a '
1025-
'QueueRunner. That means predict yields forever. '
1026-
'This is probably a mistake.')
1025+
tf.compat.v1.logging.warning(
1026+
'Input graph does not use tf.data.Dataset or contain a '
1027+
'QueueRunner. That means predict yields forever. '
1028+
'This is probably a mistake.'
1029+
)
10271030

10281031
def _get_iterator_from_input_fn(self, input_fn, mode, distribution=None):
10291032
"""Calls `input_fn` and returns an iterator."""
@@ -1169,9 +1172,9 @@ def _call_model_fn(self, features, labels, mode, config):
11691172
if 'config' in model_fn_args:
11701173
kwargs['config'] = config
11711174

1172-
logging.info('Calling model_fn.')
1175+
tf.compat.v1.logging.info('Calling model_fn.')
11731176
model_fn_results = self._model_fn(features=features, **kwargs)
1174-
logging.info('Done calling model_fn.')
1177+
tf.compat.v1.logging.info('Done calling model_fn.')
11751178

11761179
if not isinstance(model_fn_results, model_fn_lib.EstimatorSpec):
11771180
raise ValueError('model_fn should return an EstimatorSpec.')

tensorflow_estimator/python/estimator/estimator_export_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"""estimator_export tests."""
1616

1717
import sys
18+
import tensorflow as tf
1819

19-
from tensorflow.python.platform import test
2020
from tensorflow.python.platform import tf_logging as logging
2121
from tensorflow.python.util import tf_export
2222
# pylint: disable=g-deprecated-tf-checker
@@ -27,7 +27,7 @@ class TestClass(object):
2727
pass
2828

2929

30-
class ValidateExportTest(test.TestCase):
30+
class ValidateExportTest(tf.test.TestCase):
3131
"""Tests for estimator_export class."""
3232

3333
def setUp(self):
@@ -49,7 +49,9 @@ def testExportClassInEstimator(self):
4949
self.assertNotIn('_tf_api_names', TestClass.__dict__)
5050
self.assertEqual(['estimator.TestClass'], tf_export.get_v1_names(TestClass))
5151

52-
@test.mock.patch.object(logging, 'warning', autospec=True)
52+
@tf.compat.v1.test.mock.patch.object(
53+
logging, 'warning', autospec=True
54+
)
5355
def testExportDeprecated(self, mock_warning):
5456
export_decorator = estimator_export.estimator_export('estimator.TestClass')
5557
export_decorator(TestClass)
@@ -63,4 +65,4 @@ def testExportDeprecated(self, mock_warning):
6365

6466

6567
if __name__ == '__main__':
66-
test.main()
68+
tf.test.main()

tensorflow_estimator/python/estimator/estimator_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,7 @@ def _model_fn(features, labels, mode):
19251925

19261926
est = estimator.EstimatorV2(model_fn=_model_fn)
19271927
est.train(dummy_input_fn, steps=1)
1928-
with tf.test.mock.patch.object(logging, 'warning') as mock_log:
1928+
with tf.test.mock.patch.object(tf.logging, 'warning') as mock_log:
19291929
next(est.predict(dummy_input_fn))
19301930
self.assertRegexpMatches(
19311931
str(mock_log.call_args),
@@ -1948,7 +1948,7 @@ def _input_fn():
19481948

19491949
est = estimator.EstimatorV2(model_fn=_model_fn)
19501950
est.train(dummy_input_fn, steps=1)
1951-
with tf.test.mock.patch.object(logging, 'warning') as mock_log:
1951+
with tf.test.mock.patch.object(tf.logging, 'warning') as mock_log:
19521952
next(est.predict(_input_fn))
19531953
# The warning should not have keyword QueueRunner.
19541954
self.assertRegexpMatches(str(mock_log.call_args), '^((?!QueueRunner).)*$')
@@ -1971,7 +1971,7 @@ def _input_fn():
19711971

19721972
est = estimator.EstimatorV2(model_fn=_model_fn)
19731973
est.train(dummy_input_fn, steps=1)
1974-
with tf.test.mock.patch.object(logging, 'warning') as mock_log:
1974+
with tf.test.mock.patch.object(tf.logging, 'warning') as mock_log:
19751975
next(est.predict(_input_fn))
19761976
# The warning should not have keyword QueueRunner.
19771977
self.assertRegexpMatches(str(mock_log.call_args), '^((?!QueueRunner).)*$')

tensorflow_estimator/python/estimator/training.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import six
2727
import tensorflow as tf
2828
from tensorflow.python.distribute import estimator_training as distribute_coordinator_training
29-
from tensorflow.python.platform import tf_logging as logging
3029
from tensorflow.python.training import basic_session_run_hooks
3130
from tensorflow.python.training import server_lib
3231
from tensorflow_estimator.python.estimator import estimator as estimator_lib
@@ -851,7 +850,7 @@ def _start_continuous_evaluation(self):
851850
tf.compat.v1.GraphKeys.GLOBAL_STEP)
852851
if (global_step and self._train_spec.max_steps and
853852
global_step >= self._train_spec.max_steps):
854-
logging.info(
853+
tf.compat.v1.logging.info(
855854
'Exiting evaluation, global_step=%s >= train max_steps=%s',
856855
global_step, self._train_spec.max_steps)
857856
return
@@ -894,11 +893,13 @@ def _execute_evaluator_once(self, evaluator, continuous_eval_listener,
894893
elapsed_time = time.time() - start
895894
difference = throttle_secs - elapsed_time
896895
if difference > 0:
897-
logging.info('Waiting %f secs before starting next eval run.', difference)
896+
tf.compat.v1.logging.info(
897+
'Waiting %f secs before starting next eval run.', difference
898+
)
898899
time.sleep(difference)
899900
elif (throttle_secs == 0 and eval_result.status != _EvalStatus.EVALUATED):
900901
# Prints a user-actionable warning to avoid unnecessary load on evaluator.
901-
logging.warning(
902+
tf.compat.v1.logging.warning(
902903
'EvalSpec.throttle_secs is set as 0. This might overload the job '
903904
'before finding (next) new checkpoint. Please consider to increase '
904905
'it.')
@@ -978,7 +979,7 @@ def _log_err_msg(self, message):
978979
"""Prints warning `message` every 10 mins."""
979980
current_time = time.time()
980981
if current_time - self._last_warning_time > 600:
981-
logging.warning(message)
982+
tf.compat.v1.logging.warning(message)
982983
self._last_warning_time = current_time
983984

984985
def _export_eval_result(self, eval_result, is_the_final_export):

tensorflow_estimator/python/estimator/training_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
import numpy as np
3030
import tensorflow as tf
31-
from tensorflow.python.platform import tf_logging as logging
3231
from tensorflow.python.training import basic_session_run_hooks
3332
from tensorflow.python.training import server_lib
3433
from tensorflow_estimator.python.estimator import estimator as estimator_lib
@@ -1371,7 +1370,7 @@ def test_skip_evaluation_due_to_ckpt(self):
13711370
input_fn=lambda: 1, start_delay_secs=0, throttle_secs=2)
13721371

13731372
executor = training._TrainingExecutor(mock_est, mock_train_spec, eval_spec)
1374-
with tf.compat.v1.test.mock.patch.object(logging, 'warning') as mock_log:
1373+
with tf.compat.v1.test.mock.patch.object(tf.compat.v1.logging, 'warning') as mock_log:
13751374
executor.run_evaluator()
13761375

13771376
# Three checkpoint paths are invalid.
@@ -1399,7 +1398,7 @@ def test_warning_if_throttle_secs_is_zero(self):
13991398
input_fn=lambda: 1, start_delay_secs=0, throttle_secs=0)
14001399

14011400
executor = training._TrainingExecutor(mock_est, mock_train_spec, eval_spec)
1402-
with tf.compat.v1.test.mock.patch.object(logging, 'warning') as mock_log:
1401+
with tf.compat.v1.test.mock.patch.object(tf.compat.v1.logging, 'warning') as mock_log:
14031402
executor.run_evaluator()
14041403

14051404
# First ckpt is invalid.
@@ -1513,7 +1512,7 @@ def test_throttle_secs(self, mock_sleep, mock_time):
15131512

15141513
executor = training._TrainingExecutor(mock_est, mock_train_spec, eval_spec)
15151514
# Disable logging as it calls time.time also.
1516-
with tf.compat.v1.test.mock.patch.object(logging, 'info'):
1515+
with tf.compat.v1.test.mock.patch.object(tf.compat.v1.logging, 'info'):
15171516
executor.run_evaluator()
15181517
mock_sleep.assert_called_with(throttle_secs - operation_secs)
15191518
self.assertTrue(mock_est.evaluate.called)

0 commit comments

Comments
 (0)