Python 在CNN训练期间使用numpy重塑图像阵列时出错

Python 在CNN训练期间使用numpy重塑图像阵列时出错,python,machine-learning,tensorflow,array-broadcasting,tflearn,Python,Machine Learning,Tensorflow,Array Broadcasting,Tflearn,我试图在一些图像上训练一个模型。但在培训过程中,我遇到了以下错误: ValueError: could not broadcast input array from shape (64,64,3) into shape (64,64) 我已使用tflearn.data\u utils image\u preload函数将所有图像调整为形状(64,64,3)。我不明白我做错了什么 这是我的密码: IMAGE_SIZE = 64 NUM_CHANNEL = 3 #Importing data X

我试图在一些图像上训练一个模型。但在培训过程中,我遇到了以下错误:

ValueError: could not broadcast input array from shape (64,64,3) into shape (64,64)
我已使用
tflearn.data\u utils image\u preload
函数将所有图像调整为形状(64,64,3)。我不明白我做错了什么

这是我的密码:

IMAGE_SIZE = 64
NUM_CHANNEL = 3

#Importing data
X_train, Y_train = image_preloader(TRAIN_DATA, image_shape=(IMAGE_SIZE, IMAGE_SIZE, NUM_CHANNEL),mode='file', categorical_labels=True,normalize=True)
X_test, Y_test = image_preloader(TEST_DATA, image_shape=(IMAGE_SIZE, IMAGE_SIZE, NUM_CHANNEL),mode='file', categorical_labels=True,normalize=True)

X = tf.placeholder(tf.float32,shape=[None, IMAGE_SIZE, IMAGE_SIZE, NUM_CHANNEL], name='input_image') 
#input class
Y_ = tf.placeholder(tf.float32,shape=[None, NUM_CLASS], name='input_class')
这是培训的主要环节:

previous_batch = 0
start_time = time.time()
for i in range(epoch):
    #batch wise training 
    if previous_batch >= len(X_train) : #total --> total number of training images
        previous_batch = 0    
    current_batch = previous_batch + batch_size
    if current_batch > len(X_train) :
        current_batch = len(X_train)
    print("Prev =", previous_batch, "Curr =", current_batch)    
    x_input = X_train[previous_batch : current_batch]
    print("x_input length =", len(x_input))

    x_images = np.reshape(np.array(x_input), [batch_size, IMAGE_SIZE, IMAGE_SIZE, NUM_CHANNEL])
    y_input = Y_train[previous_batch : current_batch]
    y_label = np.reshape(np.array(y_input), [batch_size, NUM_CLASS])

    previous_batch = previous_batch + batch_size
    _, loss = sess.run([train_step, cross_entropy], feed_dict = {X: x_images, Y_: y_label}) 
    if i % 500 == 0:
        n = 50 #number of test samples

        x_test_images = np.reshape(np.array(X_test[0 : n]), [n, IMAGE_SIZE, IMAGE_SIZE, NUM_CHANNEL])
        y_test_labels = np.reshape(np.array(Y_test[0 : n]), [n, NUM_CLASS])
        Accuracy = sess.run(accuracy, feed_dict = {X: x_test_images, Y_: y_test_labels})
        print("Iteration no : {}, Accuracy : {}, Loss : {}" .format(i, Accuracy, loss))
        saver.save(sess, save_path, global_step = i)
    elif i % 100 == 0:   
        print("Iteration no : {} Loss : {}" .format(i, loss))

saver.save(sess, save_path)
print("Time required = %f sec" % (time.time() - start_time))
我在代码行中遇到上述错误:

x_test_images = np.reshape(np.array(X_test[0 : n]), [n, IMAGE_SIZE, IMAGE_SIZE, NUM_CHANNEL])

请阅读。你的问题中需要有一个链接(不是外部链接)。@Cecilia:谢谢你的建议。我已经更新了问题。