module 'tensorflow' has no attribute 'ConfigProto'/'Session'解决方法

因为tensorflow2.0版本与之前版本有所更新,故将代码修改即可:

#原 config = tf.ConfigProto(allow_soft_placement=True)
config = tf.compat.v1.ConfigProto(allow_soft_placement=True)
#原 sess = tf.Session(config=config)
sess =tf.compat.v1.Session(config=config)

或使用

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

替换

import tensorflow as tf

猜你喜欢

转载自www.cnblogs.com/yuanxiaochou/p/12572761.html
今日推荐