【问题标题】:You must feed a value for placeholder tensor 'Placeholder' with dtype int32您必须使用 dtype int32 为占位符张量“Placeholder”提供一个值
【发布时间】:2019-11-28 04:45:13
【问题描述】:

以下代码给了我错误:

您必须使用 dtype int32 为占位符张量“Placeholder”提供一个值

为什么会出现此错误?我正在使用带有 Google colab GPU 的 Python 3。

    import tensorflow as tf  

    d1 = tf.placeholder(tf.int32)
    d2 = tf.add(6, 2, name="Add_these_numbers2")
    d3 = tf.add(d1, d2, name="res5")
    d4 = tf.add(d1, d3, name="res5")

    with tf.Session() as sess:
       # writer = tf.summary.FileWriter("output", sessi.graph)
        print(sess.run(d3))
        print(sess.run(d4,feed_dict={d1:0}))

【问题讨论】:

    标签: python tensorflow google-colaboratory


    【解决方案1】:

    sess.run(d3) 期间你没有喂d1(即d3 依赖于d1)。

    以下作品。

    import tensorflow as tf  
    
    d1 = tf.placeholder(tf.int32)
    d2 = tf.add(6, 2, name="Add_these_numbers2")
    d3 = tf.add(d1, d2, name="res5")
    d4 = tf.add(d1, d3, name="res5")
    
    with tf.Session() as sess:
       # writer = tf.summary.FileWriter("output", sessi.graph)
        print(sess.run(d3, feed_dict={d1:0}))
        print(sess.run(d4, feed_dict={d1:0}))
    

    【讨论】:

      猜你喜欢
      • 2017-05-27
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多