好的,所以我正在尝试将 keras 作为项目的一部分,但出现以下错误,我似乎无法解决:
ValueError: Error when checking input: expected input_1 to have shape (205087,) but got array with shape (1,)
我的代码如下:
import tensorflow as tf
import numpy as np
from tensorflow.keras.layers import Input, Dense, Concatenate
from tensorflow.keras.models import Model
def iterdata():
while(True):
for d in data: #data is already defined in my script
val=tf.keras.utils.to_categorical(d, num_classes=vocab_size) #this is the one_hot vector that causes troubles
yield val, 0
word = Input(shape=(vocab_size,))
encode = Dense(1, activation=None)
encoded = shared_encode(word)
model = Model(inputs=word, outputs=encoded)
model.compile(loss='mean_squared_error',
optimizer='rmsprop',
metrics=['accuracy'])
H = model.fit_generator(iterdata(),
epochs=10,
steps_per_epoch=10) #according to the Traceback, error happens while running this line
跑步 :
for d in iterdata():
print(d[0].shape)
正确打印(205087,)
所以我不知道该怎么处理它,我确实尝试过屈服np.asarray([val])
,但仍然遇到同样的错误。关于如何解决这个问题的任何想法?