Loading

tensorflow问题

如果你的Tensorflow程序很简单,比如这样:

那么出现AttributeError: module 'tensorflow' has no attribute 'constant'的原因是:

该文件命名错误,不要用tensorflow这个名字,换个别的就好了大笑大笑大笑

 

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)  #注意 ,这里为tensorflow2.0版本,与第1.0有差距。

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

 

posted @ 2020-03-26 11:51  李旭2018  阅读(215)  评论(0编辑  收藏  举报