为什么我必须调用model.predict(x)而不是model(x)? [英] Why do I have to call model.predict(x) instead of model(x)?
本文介绍了为什么我必须调用model.predict(x)而不是model(x)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下keras模型:
I have the following keras model:
def model_1(vocab_size, output_dim, batch_input_dims, rnn_units, input_shape_LSTM, name='model_1'):
model = Sequential(name=name)
model.add(Embedding(input_dim=vocab_size+1, output_dim=output_dim, mask_zero=True, batch_input_shape=batch_input_dims))
model.add(LSTM(units=rnn_units, input_shape=input_shape_LSTM,
stateful=True,
return_sequences=True,
recurrent_initializer='glorot_uniform',
recurrent_activation='sigmoid'))
model.add(Dense(units=vocab_size))
return model
然后我得到向量x_和y_的给定值:
I then have the vector x_ and y_ given by:
x_, y_ = get_batches(X, y, batch_size)
x_shape: (32, 200000)
y_ shape: (32, 200000)
现在,我不明白为什么打电话给我
Now, I do not understand why if I call:
model.predict(x_)
我得到了预期的预测数组.
I get the predicted array as expected.
相反,如果我打电话给我
Instead, if I call:
model(x_)
出现以下错误:
ValueError: Layer model_1 was called with an input that isn't a symbolic tensor. Received type: <class 'numpy.ndarray'>. Full input: [array([[ 0, 0, 0, ..., 21839, 21841, 9579],
[ 0, 0, 0, ..., 1, 1, 23012],
[ 0, 0, 0, ..., 246, 9832, 9832],
...,
[ 0, 0, 0, ..., 24827, 24867, 24868],
[ 0, 0, 0, ..., 22448, 22426, 22426],
[ 0, 0, 0, ..., 1, 1, 1]])]. All inputs to the layer should be tensors.
有人可以解释我为什么吗?我对这个主题提出了一些建议性的问题,但没有找到答案.
Can someone explain me why? I red the suggested questions for this topic and I didn't find the answear...
推荐答案
查看全文