小编Den*_* P.的帖子

检查输入时出错:预期dense_input 具有形状(21,) 但得到形状为(1,) 的数组

如何修复输入数组以满足输入形状?

我试图转输入数组,如所描述这里,但误差是相同的。

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)
Run Code Online (Sandbox Code Playgroud)

python machine-learning neural-network keras tensorflow

7
推荐指数
1
解决办法
8678
查看次数