![](/img/trans.png)
[英]ValueError: logits and labels must have the same shape ((None, 5) vs (None, 1))
[英]ValueError: logits and labels must have the same shape ((None, 2) vs (None, 1))
我正在與 LSTMS 合作,以預測我們(機器人)是否應該基於 2 個因素購買東西。 So my X consists of an numpy array consisting of separate numpy arrays each with a numpy array of 2. Since that is confusing it looks like np.array(np.array(np.array([item,item]),np.array ([item,item])),np.array(np.array([item,item]),np.array([item,item])))
我的 y 值是一個包含 0 和 1 列表的 numpy 數組。 其中一個樣本是
[[1]
[0]
[0]
...
[0]]
這是我的 model
model = Sequential()
model.add(LSTM(128,input_shape=(30,2),return_sequences=True))
model.add(Dropout(0.1))
model.add(LSTM(128,return_sequences=True))
model.add(Dropout(0.2))
model.add(LSTM(128))
model.add(Dropout(0.1))
model.add(BatchNormalization())
model.add(Flatten())
model.add(Dense(64,activation='relu'))
model.add(Dense(2,activation='softmax'))
model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
model.fit(seqs,buy_sell,epochs=200,callbacks=[tensboard])
和我的回溯
ValueError: logits and labels must have the same shape ((None, 2) vs (None, 1))
我正在考慮重塑我的 X/y,但這不會影響 model。 我將如何解決這個問題?
添加到我的評論中,如果您出於任何原因想堅持使用softmax
激活(將來您可能會有更多類),然后像這樣修改最后一行代碼:
model.fit(seqs, tf.keras.utils.to_categorical(buy_sell, num_classes=2), epochs=200, callbacks=[tensboard])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.