我得到了一個由 432 個批次組成的資料集,每個批次 24 個點。整個資料集的形狀:(432, 24)
舉個例子,這將是一批:
array([917, 15, 829, 87, 693, 71, 627, 359, 770, 303, 667, 367, 754,
359, 532, 39, 683, 407, 333, 551, 516, 31, 675, 39])
與形狀 (24,)
我正在用這些資訊喂養 Keras 模型。沒有問題。當我嘗試使用具有相同形狀 (24,) 的新資料進行預測時:
array([176, 71, 152, 63, 200, 71, 120, 87, 128, 87, 216, 103, 248,
126, 144, 150, 128, 206, 192, 206, 112, 277, 216, 269])
我的型號:
model = keras.Sequential([
keras.layers.Flatten(batch_input_shape=(None,24)),
keras.layers.Dense(64, activation=tf.nn.relu),
keras.layers.Dense(2, activation=tf.nn.sigmoid),
])
model.compile(optimizer='adam',
loss=tf.losses.categorical_crossentropy,
metrics=['accuracy'])
引發的錯誤:
ValueError: Input 0 of layer dense_24 is incompatible with the layer: expected axis -1 of input shape to have value 24 but received input with shape (None, 1)

uj5u.com熱心網友回復:
也許嘗試為您的資料樣本添加一個維度,然后將您的資料new_data輸入到您的模型中以進行預測:
import numpy as np
new_data= np.array([176, 71, 152, 63, 200, 71, 120, 87, 128, 87, 216, 103, 248,
126, 144, 150, 128, 206, 192, 206, 112, 277, 216, 269])
new_data= np.expand_dims(new_data, axis=0)
prediction = model.predict(new_data)
print(prediction)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/323193.html
