错误读取:
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的大小的?如何处理这个错误?下面是我创建的虚拟模型。
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)发布于 2020-07-25 11:11:14
使用Keras functional API时,请勿将批处理维包括为None。例如,如果您的输入是维度(batch_size、image_w、image_h、image_channels),则如下所示:
inp = tf.keras.Input(shape=(IMG_W, IMG_H, IMG_CH))https://stackoverflow.com/questions/63083607
复制相似问题