keras连接mysql_在keras中使用常量向量连接输入

在尝试使用Keras 2.0.5和Theano后端时,作者遇到一个问题:在函数API中将常量张量与输入合并时,导致`ValueError`。错误表明输入不是符号张量。示例代码中,作者创建了一个输入层a,一个带有常量变量的输入层a1,然后尝试通过`concatenate`函数将它们连接。在修改`x`列表后,错误发生,因为这影响了已连接层的历史记录。解决方案可能是确保在模型构建过程中不直接修改输入历史记录。
摘要由CSDN通过智能技术生成

我试图在keras-2函数API中使用常量张量连接我的输入。在我真正的问题中,常量取决于设置中的一些参数,但我认为下面的示例显示了我得到的错误。

from keras.layers import*

from keras.models import *

from keras import backend as K

import numpy as np

a = Input(shape=(10, 5))

a1 = Input(tensor=K.variable(np.ones((10, 5))))

x = [a, a1] # x = [a, a] works fine

b = concatenate(x, 1)

x += [b] # This changes b._keras_history[0].input

b = concatenate(x, 1)

model = Model(a, b)我得到的错误是:

ValueError Traceback (most recent call last)

~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/engine/topology.py in assert_input_compatibility(self, inputs)

418 try:

--> 419 K.is_keras_tensor(x)

420 except ValueError:

~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/backend/theano_backend.py in is_keras_tensor(x)

198 T.sharedvar.TensorSharedVariable)):

--> 199 raise ValueError('Unexpectedly found an instance of type `' + str(type(x)) + '`. '

200 'Expected a symbolic tensor instance.')

ValueError: Unexpectedly found an instance of type ``. Expected a symbolic tensor instance.

During handling of the above exception, another exception occurred:

ValueError Traceback (most recent call last)

in ()

5 a1 = Input(tensor=K.variable(np.ones((10, 5))))

6 x = [a, a1]

----> 7 b = concatenate(x, 1)

8 x += [b] # This changes b._keras_history[0].input

9 b = concatenate(x, 1)

~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/layers/merge.py in concatenate(inputs, axis, **kwargs)

506 A tensor, the concatenation of the inputs alongside axis `axis`.

507 """

--> 508 return Concatenate(axis=axis, **kwargs)(inputs)

509

510

~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/engine/topology.py in __call__(self, inputs, **kwargs)

550 # Raise exceptions in case the input is not compatible

551 # with the input_spec specified in the layer constructor.

--> 552 self.assert_input_compatibility(inputs)

553

554 # Collect input shapes to build layer.

~/miniconda3/envs/ds_tools/lib/python3.6/site-packages/keras/engine/topology.py in assert_input_compatibility(self, inputs)

423 'Received type: ' +

424 str(type(x)) + '. Full input: ' +

--> 425 str(inputs) + '. All inputs to the layer '

426 'should be tensors.')

427

ValueError: Layer concatenate_2 was called with an input that isn't a symbolic tensor. Received type: . Full input: [concatenate_1/input_3, concatenate_1/variable]. All inputs to the layer should be tensors.我使用theano后端运行keras版本2.0.5,使用的是版本0.10.0dev1。任何有关错误的想法或更完整的拼接方法?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值