gaoxiaonan0001 2019-01-22 17:50 采纳率: 0%
浏览 12508

keras报错:All inputs to the layer should be tensors.

深度学习小白,初次使用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.

报错提示是:所有层的输入应该为张量,请问应该怎么修改呢?麻烦了!

  • 写回答

2条回答 默认 最新

  • 清爽的风 2019-09-04 16:03
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿