Skip to content

Commit e879b7a

Browse files
mdrevestf-model-analysis-team
authored and
tf-model-analysis-team
committed
Update to use importlib for imports used for registration purposes only.
PiperOrigin-RevId: 390504827
1 parent 380640d commit e879b7a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

tensorflow_model_analysis/model_util.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import collections
2020
import copy
21+
import importlib
2122
import os
2223
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set, Text, Tuple
2324

@@ -38,6 +39,8 @@
3839

3940
# TODO(b/162075791): Need to load tensorflow_ranking, tensorflow_text,
4041
# tensorflow_decision_forests, and struct2tensor for models that use those ops.
42+
# The tensorflow_ranking and tensorflow_text imports should also be changed to
43+
# dynamic imports so that user's that use them must explicitly add deps.
4144
# pylint: disable=g-import-not-at-top
4245
try:
4346
import tensorflow_ranking as _
@@ -52,12 +55,12 @@
5255
except (ImportError, tf.errors.NotFoundError) as e:
5356
logging.info('tensorflow_text is not available: %s', e)
5457
try:
55-
import tensorflow_decision_forests as _
58+
importlib.import_module('tensorflow_decision_forests')
5659
logging.info('imported tensorflow_decision_forests')
5760
except Exception as e: # pylint: disable=broad-except
5861
logging.info('tensorflow_decision_forests is not available: %s', e)
5962
try:
60-
import struct2tensor as _
63+
importlib.import_module('struct2tensor')
6164
logging.info('imported struct2tensor')
6265
except Exception as e: # pylint: disable=broad-except
6366
logging.info('struct2tensor is not available: %s', e)

0 commit comments

Comments
 (0)