简体   繁体   中英

ImportError: cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental' import Keras

I'm getting following Error while importing Keras.

ImportError: cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental' (C:\Users\User\AppData\Roaming\Python\Python38\site-packages\tensorflow\_api\v2\compat\v2\experimental\__init__.py)

Tensorflow v. 2.6, Keras v. 2.6

Do anyone have an idea to solve this Error? I would appreciate any help!

DTensor is part of the TensorFlow 2.9.0 release. To import dtensor you can upgrade tensorflow 2.6 to tensorflow 2.9 as follows:

pip install --upgrade tensorflow==2.9

Now, you can import dtensor either from tensorflow.experimental or from tensorflow.keras as follows:

#Using tensorflow.experimental
from tensorflow.experimental import dtensor

#Using tensorflow.keras
from tensorflow.keras import dtensor

For more information, please refer to this guide . Thank you.

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