DOSMA icon indicating copy to clipboard operation
DOSMA copied to clipboard

[BUG] TensorFlow 2.5.0 not supported

Open ad12 opened this issue 3 years ago • 0 comments

Describe the bug With tensorflow==2.5.0, we get an error message like the one below:

tests/util.py:18: in <module>
    from dosma.cli import SUPPORTED_SCAN_TYPES, parse_args
dosma/cli.py:36: in <module>
    from dosma.models.seg_model import SegModel
dosma/models/__init__.py:1: in <module>
    from dosma.models import oaiunet2d, util
dosma/models/oaiunet2d.py:14: in <module>
    from keras.models import Model
/opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/keras/__init__.py:20: in <module>
    from . import initializers
/opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/keras/initializers/__init__.py:124: in <module>
    populate_deserializable_objects()
/opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/keras/initializers/__init__.py:49: in populate_deserializable_objects
    LOCAL.GENERATED_WITH_V2 = tf.__internal__.tf2.enabled()
E   AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'tf2'

To Reproduce

import dosma

Expected behavior No error.

Stopgap solution Install tensorflow and Keras with pip install tensorflow==2.4.1 keras==2.4.3

Potential Fix As mentioned in this issue, tensorflow>=2.0 should import keras tools using import tensorflow.keras instead of import keras. All files where packages are imported from keras should first check the version for tensorflow and then rename keras. In pseudo-code, this is:

if tensorflow_version >= 2.0:
    import tensorflow.keras as keras

from keras...

ad12 avatar May 14 '21 01:05 ad12