model.fit错误:InvalidArgumentError:无法挤压dim [2],预期尺寸为1,得到9 [Op:Squeeze]

时间:2019-04-27 07:47:48

标签: python tensorflow keras recurrent-neural-network tf.keras

尝试拟合模型进行训练时收到以下错误:无法压缩dim [2],预期尺寸为1,得到9 [Op:Squeeze]

模型在单个样本批次上运行,但是当我尝试拟合整个数据集时会抛出错误

key: string

每个批次输入具有以下形状(64,100,9) 我怀疑问题出在我将其弄平的地方。

batch_size = 64
vocab_size = 42
embedding_dim = 256
rnn_units = 1024
steps_per_epoch = examples_per_epoch//BATCH_SIZE

model = tf.keras.Sequential([


tf.keras.layers.Flatten(input_shape=(64,900),batch_input_shape=[batch_size, None]),        
tf.keras.layers.Embedding(vocab_size, embedding_dim, 
                          batch_input_shape=[batch_size, None]),
rnn(rnn_units,
    return_sequences=True, 
    recurrent_initializer='glorot_uniform',
    stateful=True),    
tf.keras.layers.Dense(vocab_size),

])

model.compile(
optimizer = tf.train.AdamOptimizer(),
loss = tf.losses.sparse_softmax_cross_entropy)



model.fit(dataset.repeat(), epochs=EPOCHS, steps_per_epoch=steps_per_epoch, callbacks=[checkpoint_callback])

任何建议将不胜感激,谢谢

0 个答案:

没有答案