Skip to content

Commit

Permalink
Update to use importlib for imports used for registration purposes only.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 390504827
  • Loading branch information
mdreves authored and tf-model-analysis-team committed Aug 13, 2021
1 parent 380640d commit e879b7a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tensorflow_model_analysis/model_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import collections
import copy
import importlib
import os
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set, Text, Tuple

Expand All @@ -38,6 +39,8 @@

# TODO(b/162075791): Need to load tensorflow_ranking, tensorflow_text,
# tensorflow_decision_forests, and struct2tensor for models that use those ops.
# The tensorflow_ranking and tensorflow_text imports should also be changed to
# dynamic imports so that user's that use them must explicitly add deps.
# pylint: disable=g-import-not-at-top
try:
import tensorflow_ranking as _
Expand All @@ -52,12 +55,12 @@
except (ImportError, tf.errors.NotFoundError) as e:
logging.info('tensorflow_text is not available: %s', e)
try:
import tensorflow_decision_forests as _
importlib.import_module('tensorflow_decision_forests')
logging.info('imported tensorflow_decision_forests')
except Exception as e: # pylint: disable=broad-except
logging.info('tensorflow_decision_forests is not available: %s', e)
try:
import struct2tensor as _
importlib.import_module('struct2tensor')
logging.info('imported struct2tensor')
except Exception as e: # pylint: disable=broad-except
logging.info('struct2tensor is not available: %s', e)
Expand Down

0 comments on commit e879b7a

Please sign in to comment.