1

So, I have written python ML code with many packages, some of which are tensorflow, keras and stuff like this. The code didn't have any problem, it was running, until 2 days ago the interpreter displayed this error:

ImportError: cannot import name 'convert_kernel' from partially initialized module 'keras.utils.conv_utils' (most likely due to a circular import) (/home/UbuntuUser/.local/lib/python3.8/site-packages/keras/utils/conv_utils.py)

I am trying since yesterday to fix it. I found this suggested solution: AttributeError: keras.backend ,no attribute 'eager' but it does not make any difference. Still the same error. I updated tensorflow to 2.2 -> nothing, I installed previous Keras edition prior to 2.2.5 as I figured out from the above link + tensorflow 2.0 -> nothing...

This also, didn't work for me: ImportError: cannot import name 'convert_kernel'

I have no idea how to fix it. I am searching google, github, stackoverflow links to find a solution however without any success. What I cannot understand is how this can happen, I mean how did I get this error, since my program was running without any problems and I haven't done any updates recently.

I also changed keras to tensorflow.keras command (as this post suggests: How to fix ' module 'keras.backend.tensorflow_backend' has no attribute '_is_tf_1'') and I got something similar:

ImportError: cannot import name 'constant' from partially initialized module 'tensorflow.python.framework.constant_op' (most likely due to a circular import) (/home/UbuntuUser/.local/lib/python3.8/site-packages/tensorflow/python/framework/constant_op.py)

I also changed filename, as this post suggests: ImportError: cannot import name '...' from partially initialized module '...' (most likely due to a circular import) without anything improved. Similar error.

I am using the latest Kubuntu 20.04.2 LTS OS. Has anyone faced something similar and how he fixed it??

just_learning
  • 413
  • 2
  • 11
  • 24
  • 1
    https://stackoverflow.com/questions/7336802/how-to-avoid-circular-imports-in-python – Ajay Feb 20 '21 at 14:53
  • Ok, I understood something, but what I do in situations like this: "from PyQt5 import Qt as qt". I believe that I cannot write only: "import Qt" or "import PyQt5 " – just_learning Feb 22 '21 at 20:49

1 Answers1

1

In order to use convert_kernel function from Keras, Use Tensorflow 2.3 with following import statement

from tensorflow.compat.v1.keras.utils import convert_all_kernels_in_model

As tf.compat.v1.keras.utils.convert_all_kernels_in_model is deprecated after 2020-06-23 Use Tf 2.3.