Tensorflow placholder运行错误“ ValueError:设置具有序列的数组元素。”

时间:2018-11-02 01:04:32

标签: python tensorflow

我已检查我的batch_image形状与占位符形状image_shape=(100,28,28) placeholder_shape=(None 28, 28, 1)的匹配情况。但我不知道为什么我仍然不断收到此错误。谁能帮我吗?

ValueError: setting an array element with a sequence.

这是我的代码:

def main(argv=None):

X=tf.placeholder(dtype=tf.float32,shape=[None,28,28,1],name="input")
Y=tf.placeholder(dtype=tf.float32,shape=[None,n_class])

pred=CNN(X,weight,bias)
loss=Loss(pred,Y)
train_op=tf.train.AdamOptimizer(learning_rate=Learning_rate).minimize(loss)
correct_prediction=tf.equal(tf.argmax(pred,1),tf.argmax(Y,1))
accuracy=tf.reduce_mean(tf.cast(correct_prediction,tf.float32))
tf.summary.scalar("accuracy",accuracy)

init_op=tf.global_variables_initializer()
summary_op=tf.summary.merge_all()

with tf.Session() as sess:
    sess.run(init_op)
    writer=tf.summary.FileWriter("output",sess.graph)

    for epochs in range(max_epochs):
        batch_image,batch_label=get_next_batch(train_image,train_label,epochs)
        print(batch_image.shape)
        sess.run([train_op],feed_dict={X:batch_image,Y:batch_label})

        if epochs % display_step==0:
            train_loss,summary=sess.run([loss,summary_op],feed_dict={X:batch_image[1],Y:batch_label[1]})
            test_accuarcy,summary=sess.run([accuracy,summary_op],feed_dict={X:test_image,Y:test_label})
            writer.add_summary(summary,global_step=epochs)
            print("Training Loss: {:.9f}  Test Accuarcy: {}".format(train_loss,test_accuarcy))

    print("Finish Training......")

0 个答案:

没有答案