ImportError: cannot import name 'transpose_shape'

Viewed 14249

I am following the Coursera, Deep Learning course with Andrew Ng for object detection with YOLO algorithm, I am trying to run the algorithm on my PC using Windows and Anaconda Navigator, I installed Keras to run on TensorFlow backend. But when I typed the following:

import tensorflow as tf
from keras import backend as K

It showed me the following:

Using TensorFlow backend.
Traceback (most recent call last):

  File "<ipython-input-8-0bcaeab92875>", line 2, in <module>
    from keras import backend as K

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\__init__.py", line 3, in <module>
    from . import utils

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\utils\__init__.py", line 6, in <module>
    from . import conv_utils

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\utils\conv_utils.py", line 9, in <module>
    from .. import backend as K

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\backend\__init__.py", line 89, in <module>
    from .tensorflow_backend import *

  File "C:\Users\AbanoubMamdouh\Anaconda3\lib\site-packages\keras\backend\tensorflow_backend.py", line 24, in <module>
    from ..utils.generic_utils import transpose_shape

ImportError: cannot import name 'transpose_shape'

Seems like it has a problem with this line in the tensorflow_backend.py file:

from ..utils.generic_utils import transpose_shape

Help would be much appreciated! Cheers

4 Answers

Try to uninstall tensorflow and keras and install keras using pip, it also installs tensorflow. It worked for me!!!

Probably a misconfiguration of the installed packages:

pip uninstall -y tensorflow keras tf-nightly keras-nightly

and then:

pip install tensorflow

Tried re-install of existing versions, didnt work.

I'm running windows 10, Python 3.7.5 64 bit version

What worked for me - installing Keras 2.3.1, Tensorflow 2.0

Use from tensorflow.keras import backend as K instead of from keras import backend as K.

Related