# AttributeError: module 'keras.api.\_v2.keras.mixed\_precision' has no attribute 'experimental'

**URL:** <https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993>\
**Category:** General Discussion\
**Tags:** android, keras, datasets, help\_request\
**Created:** [August 5, 2022, 4:39am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993 "2022-08-05T04:39:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kokomenji](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/kokomenji/32/11285_2.png) [@kokomenji](https://discuss.ai.google.dev/u/kokomenji)\
**Post date:** [August 5, 2022, 4:39am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/1 "2022-08-05T04:39:35Z")

</div>

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](https://colab.research.google.com/github/khanhlvg/tflite_raspberry_pi/blob/main/object_detection/Train_custom_model_tutorial.ipynb#scrollTo=GZOojrDHAY1J) , I am really frustrated with that situation. Can anyone help me? Thank you.

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [August 5, 2022, 5:46am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/3 "2022-08-05T05:46:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Mausam-Rajbanshi](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/mausam-rajbanshi/32/11698_2.png) [@Mausam-Rajbanshi](https://discuss.ai.google.dev/u/Mausam-Rajbanshi)\
**Post date:** [August 17, 2022, 4:43am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/5 "2022-08-17T04:43:36Z")

</div>

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)  
tf.keras.mixed\_precision.experimental.set\_policy(policy)

MODIFY these lines to  
policy = tf.keras.mixed\_precision.Policy(precision)  
tf.keras.mixed\_precision.set\_global\_policy(policy)

USE:  
precision = ‘mixed\_float16’ if you have GPU  
OR  
precision =‘float32’ if you have CPU.

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

---

<div class="post-metadata">

**Author:** ![Jean-Herman\_Guay](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/jean-herman_guay/32/11406_2.png) [@Jean-Herman\_Guay](https://discuss.ai.google.dev/u/Jean-Herman_Guay)\
**Post date:** [August 29, 2022, 3:45am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/7 "2022-08-29T03:45:25Z")

</div>

\*\*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.

---

<div class="post-metadata">

**Author:** ![Bjarne\_Ungemach](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/bjarne_ungemach/32/15112_2.png) [@Bjarne\_Ungemach](https://discuss.ai.google.dev/u/Bjarne_Ungemach)\
**Post date:** [September 6, 2022, 8:00am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/9 "2022-09-06T08:00:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [October 31, 2022, 12:55pm UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/12 "2022-10-31T12:55:43Z")

</div>

@ [Bjarne\_Ungemach](http://discuss.ai.google.dev/u/Bjarne_Ungemach),

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

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

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

---

<div class="post-metadata">

**Author:** ![Sidath\_GUEYE](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sidath_gueye/32/18158_2.png) [@Sidath\_GUEYE](https://discuss.ai.google.dev/u/Sidath_GUEYE)\
**Post date:** [May 5, 2023, 4:02am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/16 "2023-05-05T04:02:10Z")

</div>

Hello,

Here’s the adapted and clarified message for the technical context of computer science, translated into English:

Today is May 4th, 2023, and the problem that has been persisting since 2020 is still ongoing. I am using `TensorFlow 2.8.4 and Python 3.8.16` for training, and the process goes smoothly, resulting in my tflite model. However, when I try to use it on Android, I keep getting the same error:

```auto
java.lang.AssertionError: Error occurred when initializing ObjectDetector: Output tensor at index 0 is expected to have 3 dimensions, found 2.
at org.tensorflow.lite.task.vision.detector.ObjectDetector.initJniWithByteBuffer(Native Method)

```

Additionally, when I try to switch to a virtual environment with Conda, using `python=3.8, tensorflow=2.5, and tflite_model_maker=0.3.2`, I still encounter an error with Keras:  
Error:

```auto
policy = tf.keras.mixed_precision.experimental.Policy(precision)
AttributeError: module 'keras.api._v2.keras.mixed_precision' has no attribute 'experimental'

```

I am wondering how I can make my tflite model usable on Android, and I am asking for help if anyone has a solution so that I can create my models with the latest versions of the various technologies.

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![chunduriv](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@chunduriv](https://discuss.ai.google.dev/u/chunduriv)\
**Post date:** [May 11, 2023, 10:52am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/18 "2023-05-11T10:52:46Z")

</div>

@Sidath_GUEYE,

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

```

This issue is due to Tensorflow removed `tf.keras.mixed_precision.experimental` API.

```auto
java.lang.AssertionError: Error occurred when initializing ObjectDetector: Output tensor at index 0 is expected to have 3 dimensions, found 2.
at org.tensorflow.lite.task.vision.detector.ObjectDetector.initJniWithByteBuffer(Native Method)

```

This issue will be resolved by using the latest version of the Android app example for TensorFlow.

Thank you!

---

<div class="post-metadata">

**Author:** ![Sidath\_GUEYE](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/sidath_gueye/32/18158_2.png) [@Sidath\_GUEYE](https://discuss.ai.google.dev/u/Sidath_GUEYE)\
**Post date:** [May 11, 2023, 10:54am UTC](https://discuss.ai.google.dev/t/attributeerror-module-keras-api-v2-keras-mixed-precision-has-no-attribute-experimental/28993/19 "2023-05-11T10:54:33Z")

</div>

Thank you! resovelved also!
