|
17 | 17 | # Ensure TensorFlow is importable and its version is sufficiently recent. This
|
18 | 18 | # needs to happen before anything else, since the imports below will try to
|
19 | 19 | # import tensorflow, too.
|
| 20 | + |
| 21 | +from distutils.version import LooseVersion |
| 22 | +import warnings |
| 23 | + |
| 24 | +import tensorflow as tf |
| 25 | + |
| 26 | + |
| 27 | +warning_template = """ |
| 28 | +This version of TensorFlow Addons requires TensorFlow {required}. |
| 29 | +Detected an installation of version {present}. |
| 30 | +
|
| 31 | +While some functions might work, TensorFlow Addons was not tested |
| 32 | +with this TensorFlow version. Also custom ops were not compiled |
| 33 | +against this version of TensorFlow. If you use custom ops, |
| 34 | +you might get errors (segmentation faults for example). |
| 35 | +
|
| 36 | +It might help you to fallback to pure Python ops with |
| 37 | +TF_ADDONS_PY_OPS . To do that, see |
| 38 | +https://github.com/tensorflow/addons#gpucpu-custom-ops |
| 39 | +
|
| 40 | +If you encounter errors, do *not* file bugs in GitHub because |
| 41 | +the version of TensorFlow you are using is not supported. |
| 42 | +""" |
| 43 | + |
| 44 | + |
20 | 45 | def _ensure_tf_install():
|
21 |
| - """Attempt to import tensorflow, and ensure its version is sufficient. |
22 |
| - Raises: |
23 |
| - ImportError: if either tensorflow is not importable or its version is |
24 |
| - inadequate. |
| 46 | + """Warn the user if the version of TensorFlow used is not supported. |
25 | 47 | """
|
26 |
| - import tensorflow as tf |
27 |
| - import distutils.version |
28 | 48 |
|
29 |
| - # |
30 | 49 | # Update this whenever we need to depend on a newer TensorFlow release.
|
31 |
| - # |
32 |
| - required_tensorflow_version = "2.1.0" |
33 |
| - |
34 |
| - if distutils.version.LooseVersion(tf.__version__) < distutils.version.LooseVersion( |
35 |
| - required_tensorflow_version |
36 |
| - ): |
37 |
| - raise ImportError( |
38 |
| - "This version of TensorFlow Addons requires TensorFlow " |
39 |
| - "version >= {required}; Detected an installation of version " |
40 |
| - "{present}. Please upgrade TensorFlow to proceed.".format( |
41 |
| - required=required_tensorflow_version, present=tf.__version__ |
42 |
| - ) |
| 50 | + required_tf_version = "2.1.0" |
| 51 | + |
| 52 | + if LooseVersion(tf.__version__) != LooseVersion(required_tf_version): |
| 53 | + message = warning_template.format( |
| 54 | + required=required_tf_version, present=tf.__version__ |
43 | 55 | )
|
| 56 | + warnings.warn(message, UserWarning) |
0 commit comments