how to solve this error ? : AttributeError: module 'keras._tf_keras.keras.layers' has no attribute 'experimental' 
Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/64349">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/64349">No</a>
 after installing tf.nightly same issue is occuring.

```
from tensorflow.keras.layers.experimental import einsum
print("Done")
```

ModuleNotFoundError                       Traceback (most recent call last)
[<ipython-input-3-fd5e9e3ce5fb>](https://localhost:8080/#) in <cell line: 1>()
----> 1 from tensorflow.keras.layers.experimental import einsum
      2 print("Done")

ModuleNotFoundError: No module named 'tensorflow.keras.layers.experimental'

> How to reslove this. workaround is to limit the tensorflow version and comment out keras from object detection>packages>tf2>setup.py as:
```
 'tf-models-official >=2.5.1, <2.16.0',
    'tensorflow_io',
    #'keras',
```
 Hi **@Rajcr2** ,
-Sorry for the delay, Make sure you have the latest versions of TensorFlow and TensorFlow Object Detection API installed.
```
pip install --upgrade tensorflow
pip install --upgrade tf-models-official
```
-Verify the versions of TensorFlow and Keras you have installed to ensure compatibility.
```
import tensorflow as tf
print(tf.__version__)
print(tf.keras.__version__)
```
-In your script model_builder_tf2_test.py, ensure that you're importing the correct modules and classes. 
-Ensure that your environment is correctly set up with the necessary libraries and dependencies. You might need to restart your environment or kernel after making changes.
Thank you! hey how do i ensure whether i'm importing the correct modules and classes in the script model_builder_tf2_test.py? Same issue. @DineshNeupane  commenting **keras** also not working. Did you solve it?

On Fri, 5 Apr 2024, 11:00 am Girraj Sharma, ***@***.***>
wrote:

> Same issue
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/tensorflow/tensorflow/issues/64349#issuecomment-2038973957>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A7CL4324T2VJ3VFP7TREMYLY3YZGVAVCNFSM6AAAAABFEPPIFCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZYHE3TGOJVG4>
> .
> You are receiving this because you commented.Message ID:
> ***@***.***>
>
 try this, helped for me
`pip install tensorflow==2.13.1` Hi @Rajcr2 ,

The issue seems to be a compatible issues related to TF/Keras version vs tf_models version. As Keras3 now built to support multiple backends there are some changes in design. Please provide more context and environment details like which TF/keras version,tf-models-official version etc for more details.

Please check [setup.py ](https://github.com/tensorflow/models/blob/master/official/pip_package/setup.py) of models repo for TF version compatibility. This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you. If you are using the latest version of tensorflow, you will likey encounter this error. Tensorflow no longer have 'experimental' module under the 'keras.layers' module. You can access the preprocessing libraries directly under tf.keras.layers instead of tf.keras.layers.experimental.preprocessing. For example, you can do:

tf.keras.layers.RandomRotation(0.15),
tf.keras.layers.RandomFlip('horizontal'),
tf.keras.layers.RandomZoom(0.12),
tf.keras.layers.RandomContrast(0.12),

instead of:

tf.keras.layers.experimental.preprocessing.RandomRotation(0.15),
tf.keras.layers.experimental.preprocessing.RandomFlip('horizontal'),
tf.keras.layers.experimental.preprocessing.RandomZoom(0.12),
tf.keras.layers.experimental.preprocessing.RandomContrast(0.12), > If you are using the latest version of tensorflow, you will likey encounter this error. Tensorflow no longer have 'experimental' module under the 'keras.layers' module. You can access the preprocessing libraries directly under tf.keras.layers instead of tf.keras.layers.experimental.preprocessing. For example, you can do:
> 
> tf.keras.layers.RandomRotation(0.15), tf.keras.layers.RandomFlip('horizontal'), tf.keras.layers.RandomZoom(0.12), tf.keras.layers.RandomContrast(0.12),
> 
> instead of:
> 
> tf.keras.layers.experimental.preprocessing.RandomRotation(0.15), tf.keras.layers.experimental.preprocessing.RandomFlip('horizontal'), tf.keras.layers.experimental.preprocessing.RandomZoom(0.12), tf.keras.layers.experimental.preprocessing.RandomContrast(0.12),

Hi im still facing this error can you please help me  > > If you are using the latest version of tensorflow, you will likey encounter this error. Tensorflow no longer have 'experimental' module under the 'keras.layers' module. You can access the preprocessing libraries directly under tf.keras.layers instead of tf.keras.layers.experimental.preprocessing. For example, you can do:
> > tf.keras.layers.RandomRotation(0.15), tf.keras.layers.RandomFlip('horizontal'), tf.keras.layers.RandomZoom(0.12), tf.keras.layers.RandomContrast(0.12),
> > instead of:
> > tf.keras.layers.experimental.preprocessing.RandomRotation(0.15), tf.keras.layers.experimental.preprocessing.RandomFlip('horizontal'), tf.keras.layers.experimental.preprocessing.RandomZoom(0.12), tf.keras.layers.experimental.preprocessing.RandomContrast(0.12),
> 
> Hi im still facing this error can you please help me

Can I see your code ? yea can i text you in private ? Also seeing this.  This is for automation so would rather the fix come from upstream than any manual patch so I'll be watching - appreciate the effort!

  File "models/official/modeling/optimization/lr_schedule.py", line 89, in <module>
    tf.keras.experimental.CosineDecay)
AttributeError: module 'keras._tf_keras.keras' has no attribute 'experimental' I am also dealing with this problem.  Ok so I found the solution for this. 
**TL;DR: there is more information about migrating to tf 2versions here: https://www.tensorflow.org/guide/migrate**

I found that tensorflow version 2.16.1 changed keras module such as the current calls using 1.x fail.

I found the fix by searching similar issues and looking at tf docs.
old version tf 1.15 --> https://typeoverflow.com/developer/docs/tensorflow~1.15/keras/experimental/cosinedecay
tf.keras.experimental.CosineDecay(
initial_learning_rate, decay_steps, alpha=0.0, name=None
)

latest version 2.16.1 --> https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/schedules/CosineDecay
tf.keras.optimizers.schedules.CosineDecay(
initial_learning_rate,
decay_steps,
alpha=0.0,
name='CosineDecay',
warmup_target=None,
warmup_steps=0
)


@Rajcr2 Please, consider trying this and marking it as solved.  So, can we do object detection in latest version of tf? shits not working bro > Ok so I found the solution for this. **TL;DR: there is more information about migrating to tf 2versions here: https://www.tensorflow.org/guide/migrate**
> 
> I found that tensorflow version 2.16.1 changed keras module such as the current calls using 1.x fail.
> 
> I found the fix by searching similar issues and looking at tf docs. old version tf 1.15 --> https://typeoverflow.com/developer/docs/tensorflow~1.15/keras/experimental/cosinedecay tf.keras.experimental.CosineDecay( initial_learning_rate, decay_steps, alpha=0.0, name=None )
> 
> latest version 2.16.1 --> https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/schedules/CosineDecay tf.keras.optimizers.schedules.CosineDecay( initial_learning_rate, decay_steps, alpha=0.0, name='CosineDecay', warmup_target=None, warmup_steps=0 )
> 
> @Rajcr2 Please, consider trying this and marking it as solved.

Hi @devVegaAn , thanks for your reply. May I know what did you do in detail? All I can imagine is you might replace "experimental" with "optimizers" in the python code? Was it what you did? Did it work? Thanks! 
### Issue type

Bug

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

tf 2.15.0

### Custom code

Yes

### OS platform and distribution

_No response_

### Mobile device

_No response_

### Python version

_No response_

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

Got this Error while installing object detection tensorflow api.

command :
!python object_detection/builders/model_builder_tf2_test.py

### Standalone code to reproduce the issue

```shell
2024-03-23 08:19:24.008197: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Traceback (most recent call last):
  File "/content/tf_CrimeDetection/models/research/object_detection/builders/model_builder_tf2_test.py", line 24, in <module>
    from object_detection.builders import model_builder
  File "/usr/local/lib/python3.10/dist-packages/object_detection/builders/model_builder.py", line 26, in <module>
    from object_detection.builders import hyperparams_builder
  File "/usr/local/lib/python3.10/dist-packages/object_detection/builders/hyperparams_builder.py", line 27, in <module>
    from object_detection.core import freezable_sync_batch_norm
  File "/usr/local/lib/python3.10/dist-packages/object_detection/core/freezable_sync_batch_norm.py", line 20, in <module>
    class FreezableSyncBatchNorm(tf.keras.layers.experimental.SyncBatchNormalization
AttributeError: module 'keras._tf_keras.keras.layers' has no attribute 'experimental'
```


### Relevant log output

_No response_