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

Viewed 2755

I'm trying to create object detection using tensorflow as an assignment.

ImportError: cannot import name 'dtensor' from 'tensorflow.compat.v2.experimental' (c:\Project\.venv\lib\site-packages\tensorflow\_api\v2\compat\v2\experimental\__init__.py) I would appreciate any help!

2 Answers

I got the same error. I downgraded to Keras v2.6.0, which fixed the issue. Hence, as of 16.05.2022, this seems to be caues by a bug in v2.9.*

To downgrade to v2.6.0, run:

!pip install keras==2.6.*

Please try again by upgrading the TensorFlow version to the latest version 2.9 and restart the kernel(runtime) to fix this issue.

!pip install tensorflow==2.9
#Or
!pip install --quiet --upgrade --pre tensorflow

For example:

import tensorflow as tf
from tensorflow.experimental import dtensor

print('TensorFlow version:', tf.__version__)

mesh_1d = dtensor.create_mesh([('x', 6)])#, devices=DEVICES)
print(mesh_1d)

Output:

TensorFlow version: 2.9.1
<tensorflow.dtensor.python.layout.Mesh object at 0x7f890d7ce690>

Please check this link for more details.

Related