1. tf2.0 导入tensorflow.ConfigProto报错
- 解决方案:
from tensorflow.compat.v1 import ConfigProto
按照上述2种方法可以导入成功
参考文档:https://www.tensorflow.org/api_docs/python/tf/compat/v1/ConfigProto
2. tf2.0 image 模块没有resize_images 属性
AttributeError: module ‘tensorflow_core._api.v2.image’ has no attribute ‘resize_images’
解决方案:把接口改成 resize 即可,类似如下:
import tensorflow as tf
img_final = tf.image.resize(img_tensor, [192, 192])
参考文档:https://www.tensorflow.org/api_docs/python/tf/image/resize
3.tf2.0 使用Session时,报错AttributeError: module ‘tensorflow’ has no attribute ‘Session’
- 解决方案1:
如果安装的是tensorflow2.0 版本又想利用Session属性,可以将tf.Session()更改为:
import tensorflow as tf
tf.compat.v1.Session()
但是会有其它问题,主要原因是2.0与1.0版本不兼容,在程序开始部分添加以下代码:
tf.compat.v1.disable_eager_execution()
综上解决办法:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
tf.compat.v1.Session()
- 解决方案2:
最佳解决方案是在导入时修改:
import tensorflow.compat.v1 as tf
tf.Session()
建议大家使用 方案2

这篇博客介绍了在从TensorFlow 1.0升级到2.0时遇到的三个常见问题及解决方案:1) 导入错误,可通过引入`tf.compat.v1`来解决;2) `resize_images`属性缺失,可以改用`tf.image.resize`;3) `Session`不存在,需使用`tf.compat.v1.Session()`或直接导入`tensorflow.compat.v1`。

6799

被折叠的 条评论
为什么被折叠?



