1. tf2.0 导入 tensorflow.ConfigProto
报错
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