关于python:您必须使用dtype float输入占位符张量’占位符’的值

You must feed a value for placeholder tensor 'Placeholder' with dtype float

我是tensorflow的新手,我真的不知道如何解决该问题。

代码类似于:

  • 为火车提供以下值:

    1
    sess.run(train_op, feed_dict={images: e, labels: l, keep_prob_fc2: 0.5})
  • 使用CNN中的值:

    1
    x = tf.placeholder(tf.float32, [None, 10 * 1024])
  • 然后出现错误

    1
    2
    InvalidArgumentError (see above for traceback): You must feed a value for placeholder tensor 'Placeholder' with dtype float
         [[Node: Placeholder = Placeholder[dtype=DT_FLOAT, shape=[], _device="/job:localhost/replica:0/task:0/gpu:0"]()]]

    我使用print(e.dtype)打印输入值类型,结果是float32e.shape:(10, 32, 32, 1)

    我真的不知道为什么会发生此错误。

    代码格式

    第一位:

    1
    2
     define the CNN model
          "image = tf.placeholder(tf.float32, [FLAGS.batch_size, 32,32,1])" is here

    第二个:

    1
    2
     loss funtion and train_op is here
          "label = tf.placeholder(tf.float32, [None, FLAGS.batch_size])" is here

    第三个会话:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    images, labels = getShuffleimage()#here will get shuffle data
    num_examples = 0
    init = tf.initialize_local_variables()

    with tf.Session() as sess:
        # Start populating the filename queue.
        sess.run(init)
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord, sess=sess)

        try:
            step = 0
            while not coord.should_stop():
                start_time = time.time()
                image, label = sess.run([images, labels])#get shuffle images
                print(image.shape)
                print(image.dtype)
                sess.run(train_op, feed_dict={image: image, label: label , keep_prob_fc2: 0.5})
                duration = time.time() - start_time

        except tf.errors.OutOfRangeError:
            print('Done training after reading all data')
        finally:
            # When done, ask the threads to stop.
            coord.request_stop()

            # Wait for threads to finish.
            coord.join(threads)
            sess.close()

    一些问题

    第一
    为什么同时使用sess = tf.InteractiveSession()with tf.Session() as sess:的原因,只是好奇


    您的占位符名称ximages是什么?
    如果名称是x,则{images: x_data...}不会将x_data馈送到x,它将覆盖(?)images
    我认为feed_dict应该是{x: x_data...}

    如果名称为images,程序中是否有两个images,分别是placeholdershuffle data,请尝试修改变量的名称


    我看到了代码的一个问题。有两个具有相同名称label的变量。其中一个引用张量,另一个引用一些数据。在feed_dict中设置label: label时,需要区分两个变量。
    也许您可以尝试更改其中一个变量的名称?