深度学习小白,初次使用keras构建网络,遇到问题向各位大神请教:
from keras.models import Sequential
from keras.layers import Embedding
from keras.layers import Dense, Activation
from keras.layers import Concatenate
from keras.layers import Add
构建了一些嵌入层_
model_store = Embedding(1115, 10)
model_dow = Embedding(7, 6)
model_day = Embedding(31, 10)
model_month = Embedding(12, 6)
model_year = Embedding(3, 2)
model_promotion = Embedding(2, 1)
model_state = Embedding(12, 6)
将这些嵌入层连接起来
output_embeddings = [model_store, model_dow, model_day, model_month, model_year, model_promotion, model_state]
output_model = Concatenate()(output_embeddings)
运行报错:
ValueError Traceback (most recent call last)
D:\python\lib\site-packages\keras\engine\base_layer.py in assert_input_compatibility(self, inputs)
278 try:
--> 279 K.is_keras_tensor(x)
280 except ValueError:
D:\python\lib\site-packages\keras\backend\tensorflow_backend.py in is_keras_tensor(x)
473 raise ValueError('Unexpectedly found an instance of type ' +
. '
--> 474 str(type(x)) + '
475 'Expected a symbolic tensor instance.')
ValueError: Unexpectedly found an instance of type <class 'keras.layers.embeddings.Embedding'>
. Expected a symbolic tensor instance.
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
in
----> 1 output_model = Concatenate()(output_embeddings)
D:\python\lib\site-packages\keras\engine\base_layer.py in call(self, inputs, **kwargs)
412 # Raise exceptions in case the input is not compatible
413 # with the input_spec specified in the layer constructor.
--> 414 self.assert_input_compatibility(inputs)
415
416 # Collect input shapes to build layer.
D:\python\lib\site-packages\keras\engine\base_layer.py in assert_input_compatibility(self, inputs)
283 'Received type: ' +
284 str(type(x)) + '. Full input: ' +
--> 285 str(inputs) + '. All inputs to the layer '
286 'should be tensors.')
287
ValueError: Layer concatenate_5 was called with an input that isn't a symbolic tensor.
Received type: .
Full input: [, , , , , , ].
All inputs to the layer should be tensors.
报错提示是:所有层的输入应该为张量,请问应该怎么修改呢?麻烦了!