Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 必须为占位符张量';占位符';使用dtype float_Python_Tensorflow - Fatal编程技术网

Python 必须为占位符张量';占位符';使用dtype float

Python 必须为占位符张量';占位符';使用dtype float,python,tensorflow,Python,Tensorflow,我是tensorflow的新手,我真的不知道如何解决这个问题 代码如下: 向列车提供以下值: sess.run(train_op, feed_dict={images: e, labels: l, keep_prob_fc2: 0.5}) 使用CNN中的值: x = tf.placeholder(tf.float32, [None, 10 * 1024]) 那就有错误了 我使用print(e.dtype)打印输入值类型,结果是float32和e.shape:(10,32,32,1) 我真

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

代码如下:

  • 向列车提供以下值:

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

    x = tf.placeholder(tf.float32, [None, 10 * 1024])
    
  • 那就有错误了

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

    我真的不知道为什么会发生这种错误


    代码格式

    第一:

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

     loss funtion and train_op is here
           "label = tf.placeholder(tf.float32, [None, FLAGS.batch_size])" is here
    
    第三是会议:

    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()
    将tf.Session()作为sess:
    ,只是好奇而已

    第二 您的占位符名称是什么 如果名称是
    x
    {images:x_data…}
    不会将
    x_data
    馈送到
    x
    ,它会覆盖(?)
    图像

    我认为feed_dict应该是
    {x:x_data…}


    如果名称是
    images
    ,您的程序中是否有两个
    图像
    占位符
    随机数据
    ,请尝试修改变量的名称

    我发现代码有一个问题。有两个变量具有相同的名称
    标签
    。其中一个是指张量,另一个是指一些数据。在
    feed_dict
    中设置
    label:label
    时,需要区分这两个变量。
    也许您可以尝试更改其中一个变量的名称?

    首先,我的bach_大小是10,imagesize是32*32*1,所以我将占位符替换为:x=tf.placeholder(tf.float32,[10,1024]),其次,g也用于序列运算。但是,错误是输入图像的相同形状是1D还是3D?如果形状是3D,占位符的形状应该类似于
    [None,32,32,1]
    。如果形状为1D,则提要的
    键和
    占位符的名称应相同。您的提要是
    {images:e…}
    ,因此有一个名为images的
    占位符
    ,我已将图像转换为3D,并将其洗牌为baches。“e”是批处理_输出的一个,其形状为[10,32,32,1],类型为“float32”。我把“e”送入火车。x=tf.placeholder(tf.float32,[10,32,32,1]用于获取数据,但出现错误“您必须为带有dtype float和shape[10,32,32,1]的占位符张量'placeholder'提供一个值。”您是否在
    x=tf.place….
    之前运行
    sess.run
    ?先定义模型,然后再运行
    sess.run
    ,或者您是否可以粘贴更精确的代码?所有参数都按照您的建议同步,如问题中所示。但我遇到另一个错误:“unhable type:'numpy.ndarray',需要您的帮助吗?
    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()