简体   繁体   中英

AttributeError: module 'tensorflow.keras.models' has no attribute 'experimental'

I am attempting to use the tf.keras.models.experimental.SharpnessAwareMinimization class from tf-nightly. I installed tf-nightly with pip install tf-nightly and tf-nightly-gpu with pip install tf-nightly-gpu .

Then, I import tensorflow with import tensorflow as tf . May I know how to proceed from here?

tf.__vesion__ is 2.9.1

I am able to run this code and import SharpnessAwareMinimization api successfully and it shows below tensorflow version:

!pip install tf_nightly

import tensorflow as tf
tf.__version__

from tensorflow.keras.models.experimental import SharpnessAwareMinimization

Output: (I got the same output in Google colab and Jupyter notebook )

2.11.0-dev20220806

Please run this code again !pip install tf_nightly and retstart the kernel (runtime). Check again the tensorflow version and let us know if the issue still persists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM