AttributeError: module 'keras.api._v2.keras.mixed_precision' has no attribute 'experimental'

Hi, I am a beginner in using tensoflow and I want to build up an object detection android app. I need to build my own dataset to detect the object. Therefore, I would like to use pip install tflite-model-maker to make it.

However, when I run the code spec = model_spec.get(‘efficientdet_lite2’), there is an attribute error occured which says the module ‘keras.api._v2.keras.mixed_precision’ has no attribute ‘experimental’.

I have tried to reinstall different version of tensorflow, including 2.5.0, 2.8.0 and 2.9.1, but it is still in vein. I have also tried to reinstall keras and tflite-model-maker but it is still in vein again.

All of the instruction that I follow depends on Google Colab , I am really frustrated with that situation. Can anyone help me? Thank you.

1 Like

The tf.keras.mixed_precision.experimental API has been removed. The non-experimental symbols under tf.keras.mixed_precision have been available since TensorFlow 2.4 and should be used instead.

Please uninstall all existing installations of Tensorflow and keras . Only go with Tensorflow 2.9 or nightly in a new environment( Don’t install keras again in the same environment). Thank you.

1 Like

Yes, The experimental version was removed depreciating the experimental functions.
Those functionality is now exposed with another API.
Go to the source file where these lines are defined
policy = tf.keras.mixed_precision.experimental.Policy(precision)

MODIFY these lines to
policy = tf.keras.mixed_precision.Policy(precision)

precision = ‘mixed_float16’ if you have GPU
precision =‘float32’ if you have CPU.

It worked for me while training object detector model with tflite-model-maker using efficientnet backbone.

**Hi, **
I change 2 lines and I have the same problem.

policy = tf.keras.mixed_precision.Policy(precision)*
234 tf.keras.mixed_precision.set_global_policy(policy)*

AttributeError: module ‘keras.api._v2.keras.mixed_precision’ has no attribute ‘experimental’

It’OK after reboot!

Thank a lot.

I’m a but confused on how you access the source file, any help would be appreciated

@ Bjarne_Ungemach,

Check the error description and trace the line where the error comes from traceback

E.g.: File "/.../..../..../..../..../.../.../", line XX, in <module> 'XXXX':

The file path above with the line number gives you the exact source of the problem. Thank you!