ValueError: Cannot feed value of shape (64, 200, 75) for Tensor 'TargetsData/Y:0', which has shape '(200, 75)'

ValueError: Cannot feed value of shape (64, 200, 75) for Tensor 'TargetsData/Y:0', which has shape '(200, 75)'

我知道这是一个愚蠢的问题,但我似乎无法弄明白。我输入一个 (?,200,75) 的 numpy 数组并得到这个错误:

ValueError: Cannot feed value of shape (64, 200, 75) for Tensor 'TargetsData/Y:0', which has shape '(200, 75)'

这是我的代码:

import numpy as np
import tflearn
print("loading features....")
features = np.load("features_xs.npy")
print("loading classes....")
classes = np.load("classes_xs.npy")

symbols = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'
,'q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U',
'V','W','X','Y','Z','1','2','3','4','5','6','7','8','9','0','.',',',
'!','?',':',';','\'','(',')','-','_',' ','"',]
num_symbols = len(symbols)

input_layer = tflearn.input_data(shape=[None, 200,num_symbols])
input_layer = tflearn.flatten(input_layer)
dense1 = tflearn.fully_connected(input_layer, 1000, activation='tanh',
                                 regularizer='L2', weight_decay=0.001)
dense2 = tflearn.fully_connected(dense1, 2000, activation='tanh',
                                 regularizer='L2', weight_decay=0.001)
dense2 = tflearn.fully_connected(dense2, 1000, activation='tanh',
                                 regularizer='L2', weight_decay=0.001)
dropout2 = tflearn.dropout(dense2, 0.8)
final = tflearn.fully_connected(dropout2, (200*num_symbols), activation='tanh')
reshape = tflearn.reshape(final, [200,num_symbols], name="Reshape")

Adam = tflearn.Adam(learning_rate=0.01)
net = tflearn.regression(reshape, optimizer=Adam,
                         loss='categorical_crossentropy')

# Training
model = tflearn.DNN(net, tensorboard_verbose=0)
model.fit(features, classes, n_epoch=1, show_metric=True, run_id="dense_model")
model.save("model")

num_symbols == 到 75 如果您想知道

我找不到解决方案,请帮助谢谢。

运行以下代码:

print(classes.shape)

您将得到 (64, 200, 75) 的输出。但是你的最后一层 reshape 需要 (200, 75) 的形状。您必须从 classes 变量中提供形状为 (200, 75) 的值才能解决错误。