【tensorflow2.x如何运行1.x版本的代码,报错ImportError: cannot import name ‘dtensor‘ from ‘tensorflow.compat.v2】

我的是tfg2.4.0,在代码文件开头加入

import tensorflow._api.v2.compat.v1 as tf
tf.disable_v2_behavior()

ImportError: cannot import name ‘dtensor‘ from ‘tensorflow.compat.v2.experimental‘报错

就是tensorflow和keras版本不匹配

检查keras版本

pip show keras

【tensorflow2.x如何运行1.x版本的代码,报错ImportError: cannot import name ‘dtensor‘ from ‘tensorflow.compat.v2】_第1张图片

我的tensorflowgpu版本是2.4,所以

pip install keras==2.4

 接下来就可以正常运行文件了

你可能感兴趣的:(tensorflow,tensorflow,人工智能,python)