大家好,我希望一切都好
在LSTM上执行此代码时,我遇到了一个恼人的错误:
Your Layer or Model is in an invalid state. This can happen if you are interleaving estimator/non-estimator models or interleaving models/layers made in tf.compat.v1.Graph.as_default() with models/layers created outside of it. Converting a model to an estimator
以下代码如下:
def djmodel(Tx, LSTM_cell, densor, reshaper):
n_values = densor.units
# Get the number of the hidden state vector
n_a = LSTM_cell.units
# Define the input layer and specify the shape
X = Input(shape=(Tx, n_values))
# Define the initial hidden state a0 and initial cell state c0
# using `Input`
a0 = Input(shape=(n_a,), name='a0')
c0 = Input(shape=(n_a,), name='c0')
a = a0
outputs = []
for t in range(Tx):
x = Lambda(lambda x: X[:,t,:])(X)
x = reshaper(x)
a, _, c = LSTM_cell(x, initial_state=[a, c])
out = densor(a)
outputs.append(out)
model = Model(inputs=[X, a0, c0], outputs=outputs)
return model
model = djmodel(Tx=30, LSTM_cell=LSTM_cell, densor=densor, reshaper=reshaper)
opt = Adam(lr=0.01, beta_1=0.9, beta_2=0.999, decay=0.01)
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
model.summary()
m = 60
a0 = np.zeros((m, n_a))
c0 = np.zeros((m, n_a))
history = model.fit([X, a0, c0], list(Y), epochs=100, verbose=0)
错误正好发生在model.fit 由于某些原因,它不符合模型
我花了一个多星期的时间试图通过考试,但我一直不确定是什么原因导致了错误,希望得到一些关于如何修复错误的指导或帮助
先谢谢你
这一个对我有用:
相关问题 更多 >
编程相关推荐