![](/img/trans.png)
[英]How do I implement CNN using Functional API model and resolve '_keras_shape' error in keras layers
[英]I tried to create model in tensorflow 2.x using functional API, but got LSTM layers incompatible error
錯誤讀取:
Input 0 of layer lstm_28 is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: [None, None, 15, 12]
在 LSTM 層中,輸入tf.nn.embedding_lookup(embedding, neighbor)
的形狀 =(15,12),一個None
是批量大小,它的大小是怎么來的 [None, None, 15,12]? 如何處理這個錯誤? 下面是我創建的虛擬 model。
def create_model(embedding, embedding_dim, samp_size):
node = Input(shape=(None,), dtype=tf.int64)
neighbor = Input(shape=(None, samp_size), dtype=tf.int64)
label = Input(shape=(None,), dtype=tf.int64)
cell = LSTMCell(embedding_dim,)
_,h,c = LSTM(embedding_size, return_sequences=True, return_state=True)(tf.nn.embedding_lookup(embedding, neighbor))
predict_info = tf.squeeze(Dense(1, activation='relu'))(h)
return h
node_size = 1000
embedding_dim = 12
sampling_size = 15
embedding = tf.random.uniform([node_size, embedding_dim])
model = create_model (embedding, embedding_dim, sampling_size)
當使用 Keras 功能 API 時,不要將 None 用於批處理維度。 例如,如果您的輸入尺寸為 (batch_size, image_w, image_h, image_channels),請執行以下操作:
inp = tf.keras.Input(shape=(IMG_W, IMG_H, IMG_CH))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.