美文网首页人工智能
深度学习的坑--module 'tensorflow' has

深度学习的坑--module 'tensorflow' has

作者: 麦芽maiya | 来源:发表于2020-09-30 17:32 被阅读0次

    最近自己的深度学习基于scikit-neuralnetwork的已经学完,在学习tensorflow的时候遇到了一个很狗血的问题。

    import tensorflow as tf

    data1 =  tf.constant(2.5)

    data2 = tf.Variable(10,name='var')

    print(data1)

    print(data2)

    tf.compat.v1.disable_eager_execution()

    sess= tf.compat.v1.Session()

    sess.run(tf.global_variables_initializer())

    print(sess.run(data1))

    print(sess.run(data2))

    如下错误:

    module 'tensorflow' has no attribute 'global_variables_initializer'

    后来又在网上搜索,网友给出的答案是使用variables_all_initializer,但是依然报同样的错误。

    于是我自己开始琢磨,查找了tf中的方法也没有初始化变量的。后来我想上述错误是因为版本不一致导致的,那么如果让版本一致不就可以了吗,于是我把代码改成了tf.compat.v1.global_variables_initializer().

    相关文章

      网友评论

        本文标题:深度学习的坑--module 'tensorflow' has

        本文链接:https://www.haomeiwen.com/subject/qmqpuktx.html