Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named 'tensorflow.python.keras.mixed_precision.experimental' #48

Open
jorgelahoz opened this issue Mar 17, 2021 · 10 comments
Open
Labels
bug Something isn't working TF2.4+ wontfix This will not be worked on

Comments

@jorgelahoz
Copy link

I'm suffering a strange behaviour when importing the gradients functions:

Set up
pip install see-rnn

test.py

from see_rnn import features_0D, features_1D, features_2D
from see_rnn import get_gradients
from see_rnn import get_layer_gradients

exit()

Error

Exception has occurred: ImportError
cannot import name 'get_gradients' from 'see_rnn' (/Users/.../opt/anaconda3/envs/fns/lib/python3.8/site-packages/see_rnn/init.py)

Sames happen with "get_layer_gradients".

@OverLordGoldDragon
Copy link
Owner

Most likely you don't have TensorFlow installed; I've made the error message more informative in the latest version. Try via

pip install git+https://github.com/OverLordGoldDragon/see-rnn

and paste the error here if it doesn't mention lack of TensorFlow install.

@jorgelahoz
Copy link
Author

Same error, here is the output:

pip install git+https://github.com/OverLordGoldDragon/see-rnn
Collecting git+https://github.com/OverLordGoldDragon/see-rnn
  Cloning https://github.com/OverLordGoldDragon/see-rnn to /private/var/folders/vq/yhjbmwgj379bkvvj9csfpbx00000gn/T/pip-req-build-2_6s7aio
  Running command git clone -q https://github.com/OverLordGoldDragon/see-rnn /private/var/folders/vq/yhjbmwgj379bkvvj9csfpbx00000gn/T/pip-req-build-2_6s7aio
Requirement already satisfied: numpy in ./.local/lib/python3.8/site-packages (from see-rnn==1.15.2) (1.19.5)
Requirement already satisfied: matplotlib in ./.local/lib/python3.8/site-packages (from see-rnn==1.15.2) (3.3.4)
Requirement already satisfied: cycler>=0.10 in ./.local/lib/python3.8/site-packages (from matplotlib->see-rnn==1.15.2) (0.10.0)
Requirement already satisfied: python-dateutil>=2.1 in ./.local/lib/python3.8/site-packages (from matplotlib->see-rnn==1.15.2) (2.8.1)
Requirement already satisfied: kiwisolver>=1.0.1 in ./.local/lib/python3.8/site-packages (from matplotlib->see-rnn==1.15.2) (1.3.1)
Requirement already satisfied: pillow>=6.2.0 in ./.local/lib/python3.8/site-packages (from matplotlib->see-rnn==1.15.2) (8.1.2)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in ./.local/lib/python3.8/site-packages (from matplotlib->see-rnn==1.15.2) (2.4.7)
Requirement already satisfied: six in ./.local/lib/python3.8/site-packages (from cycler>=0.10->matplotlib->see-rnn==1.15.2) (1.15.0)
Building wheels for collected packages: see-rnn
  Building wheel for see-rnn (setup.py) ... done
  Created wheel for see-rnn: filename=see_rnn-1.15.2-py3-none-any.whl size=36164 sha256=e8392951e9be5ec11505ffde1b3c33dedec4fcf633ba3405852d7bc5db0eb72e
  Stored in directory: /private/var/folders/vq/yhjbmwgj379bkvvj9csfpbx00000gn/T/pip-ephem-wheel-cache-qx3ny0uz/wheels/ea/6d/12/91ad126da05e06f67063d34baabf0ab1d149769df23f0affd4
Successfully built see-rnn
Installing collected packages: see-rnn
  Attempting uninstall: see-rnn
    Found existing installation: see-rnn 1.15.1
    Uninstalling see-rnn-1.15.1:
      Successfully uninstalled see-rnn-1.15.1
Successfully installed see-rnn-1.15.2

And packages already installed:

pip list | grep tensor
tensorboard              2.4.1
tensorboard-plugin-wit   1.8.0
tensorflow               2.4.1
tensorflow-estimator     2.4.0
pip list | grep Keras
Keras                    2.4.3
Keras-Preprocessing      1.1.2

@OverLordGoldDragon
Copy link
Owner

It cannot be the same error; try pip uninstall see-rnn then pip install git+https://github.com/OverLordGoldDragon/see-rnn.

@jorgelahoz
Copy link
Author

After uninstalling and installing:

Traceback (most recent call last):
File "tests/test_jl.py", line 13, in
from see_rnn import get_gradients
ImportError: cannot import name 'get_gradients' from 'see_rnn' (/Users/.../opt/anaconda3/envs/fns/lib/python3.8/site-packages/see_rnn/init.py)

@OverLordGoldDragon
Copy link
Owner

Unsure what the problem is, need debug info:

  1. In __init__.py (import see_rnn; print(see_rnn.__file__)), comment lines 26, 33-35 (try, except, pass), and unindent 27-32. Save file. 1a) restart kernel, then run from see_rnn import get_gradients, paste output here.
  2. On first line of __init__.py (above import os), paste from .inspect_gen import get_gradients; repeat 1a.

@jorgelahoz
Copy link
Author

Changing init.py
New code:

...
from . import visuals_gen
from .visuals_gen import *
#try:
from . import visuals_rnn
from .visuals_rnn import *
from . import inspect_gen
from .inspect_gen import *
from . import inspect_rnn
from .inspect_rnn import *
#except:
    # handled in _backend.py
#    pass
...

Output:

No module named 'tensorflow.python.keras.mixed_precision.experimental'

Changing first line of init.py
Same output:

No module named 'tensorflow.python.keras.mixed_precision.experimental'

@jorgelahoz
Copy link
Author

Could this be linked somehow with the issue?

https://www.tensorflow.org/api_docs/python/tf/keras/mixed_precision/experimental/LossScaleOptimizer

Warning: This class is deprecated and will be removed in TensorFlow 2.5. Please use the non-experimental class tf.keras.mixed_precision.LossScaleOptimizer instead.

@OverLordGoldDragon
Copy link
Owner

OverLordGoldDragon commented Mar 18, 2021

Possibly, yes. The last tested TF version of see_rnn is 2.3.0, and I am no longer maintaining it for future compatibility. Version bugfix PRs are welcome.

Thanks for the report, but I'm afraid the only current solution is downgrading TensorFlow.

@OverLordGoldDragon OverLordGoldDragon added bug Something isn't working TF2.4+ wontfix This will not be worked on labels Mar 18, 2021
@OverLordGoldDragon OverLordGoldDragon changed the title Unable to import "get_gradients" or "get_layer_gradients" No module named 'tensorflow.python.keras.mixed_precision.experimental' Mar 18, 2021
@Juan-estudiante-uam
Copy link

Seems to be working up to version 2.9.0 so far, 10 and 11 throw the exception..

@Siddp278
Copy link

Siddp278 commented Apr 13, 2023

Hey, so what I did was I went to the venv\Lib\site-packages\deepasr\model\deepasrnetwork1.py and venv\lib\site-packages\deepasr\model\deepspeech2.py and change the the line "from tensorflow.keras.mixed_precision import experimental as mixed_precision" to "from tensorflow.keras.mixed_precision import *"
Also remove the mixed_precision calls from the script in model/deepasrnetwork1.py and model/deepspeech2.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working TF2.4+ wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants