如何修复输入数组以满足输入形状?
我尝试转置输入数组,如上所述here https://stackoverflow.com/questions/50336110/valueerror-error-when-checking-expected-dense-1-input-to-have-shape-3-but,但错误是相同的。
ValueError:检查输入时出错:期望dense_input具有形状(21,)但得到形状为(1,)的数组
import tensorflow as tf
import numpy as np
model = tf.keras.models.Sequential([
tf.keras.layers.Dense(40, input_shape=(21,), activation=tf.nn.relu),
tf.keras.layers.Dropout(0.2),
tf.keras.layers.Dense(1, activation=tf.nn.softmax)
])
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['accuracy'])
arrTest1 = np.array([0.1,0.1,0.1,0.1,0.1,0.5,0.1,0.0,0.1,0.6,0.1,0.1,0.0,0.0,0.0,0.1,0.0,0.0,0.1,0.0,0.0])
scores = model.predict(arrTest1)
print(scores)