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

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 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题