2626
2727# pylint: disable=g-direct-tensorflow-import
2828from tensorflow .python .framework import composite_tensor
29- from tensorflow .python .framework import func_graph
3029from tensorflow .python .framework import ops
3130from tensorflow .python .ops import lookup_ops
3231from tensorflow .python .util import object_identity
@@ -652,14 +651,12 @@ def make_tfrecord_vocabulary_lookup_initializer(filename_tensor,
652651 return_indicator_as_value = False ,
653652 has_indicator = False ):
654653 """Makes a lookup table initializer from a compressed tfrecord file."""
655- graph = ops .get_default_graph ()
656654 with contextlib .ExitStack () as stack :
657- # TODO(b/165884902): Use tf.inside_function after dropping TF 2.3 support.
658655 # If filename_tensor is a graph tensor (e.g. temporary analyzer output), the
659656 # following operation cannot be lifted to init scope. Hence, check it is an
660657 # eager tensor or a string constant.
661- if isinstance ( graph , func_graph . FuncGraph ) and isinstance (
662- filename_tensor , (ops .EagerTensor , str )):
658+ if ( tf . inside_function ( ) and
659+ isinstance ( filename_tensor , (ops .EagerTensor , str ) )):
663660 # Lift the dataset creation out of graph construction to avoid
664661 # repeated initialization in TF2.
665662 stack .enter_context (tf .init_scope ())
@@ -668,8 +665,7 @@ def make_tfrecord_vocabulary_lookup_initializer(filename_tensor,
668665 value_dtype ,
669666 return_indicator_as_value ,
670667 has_indicator )
671- # TODO(b/165884902): Use tf.inside_function after dropping TF 2.3 support.
672- if isinstance (graph , func_graph .FuncGraph ):
668+ if tf .inside_function ():
673669 annotators .track_object (dataset , name = None )
674670 return _DatasetInitializerCompat (dataset )
675671
@@ -1642,16 +1638,14 @@ def construct_and_lookup_table(construct_table_callable: Callable[
16421638 A tuple of the result from looking x up in a table and the table's size.
16431639
16441640 """
1645- graph = ops .get_default_graph ()
16461641 # If table is lifted into an initialization scope, add a control dependency
16471642 # on the graph tensor used to track this analyzer in
16481643 # `analyzer_nodes.TENSOR_REPLACEMENTS`.
16491644 asset_filepath , control_dependency = (
16501645 _get_asset_analyzer_output_and_control_dependency (asset_filepath ))
16511646 with contextlib .ExitStack () as stack :
1652- # TODO(b/165884902): Use tf.inside_function after dropping TF 2.3 support.
1653- if isinstance (graph , func_graph .FuncGraph ) and isinstance (
1654- asset_filepath , (ops .EagerTensor , str )):
1647+ if (tf .inside_function () and
1648+ isinstance (asset_filepath , (ops .EagerTensor , str ))):
16551649 # Lift the table initialization out of graph construction to avoid
16561650 # repeated initialization in TF2.
16571651 stack .enter_context (tf .init_scope ())
0 commit comments