Python ValueError:输入不为';t是符号张量
我是python新手,正在从事一个图像处理项目,并构建了以下模型。我把错误贴在模型下面 在我的研究中,我发现了一些关于这个错误的答案: 上面的问题是连接2个模型而不是连接2个层 在keras示例中,连接2个层,但1个层是输入层。我想了解如何连接2个常规层,并将连接的层用作一系列层中的一个层。与初始模型类似的概念Python ValueError:输入不为';t是符号张量,python,keras-layer,Python,Keras Layer,我是python新手,正在从事一个图像处理项目,并构建了以下模型。我把错误贴在模型下面 在我的研究中,我发现了一些关于这个错误的答案: 上面的问题是连接2个模型而不是连接2个层 在keras示例中,连接2个层,但1个层是输入层。我想了解如何连接2个常规层,并将连接的层用作一系列层中的一个层。与初始模型类似的概念 input / | \ a1 b1 c1 | | | a2 b2 c2 \ | / concatenate / | \ d1
input
/ | \
a1 b1 c1
| | |
a2 b2 c2
\ | /
concatenate
/ | \
d1 e1 f1
| | |
d2 e2 f2
\ | /
output
以上是我的最终目标:)
错误:
Traceback (most recent call last):
K.is_keras_tensor(x)
raise ValueError('Unexpectedly found an instance of type `' +
str(type(x)) + '`. '
ValueError: Unexpectedly found an instance of type `<class 'keras.layers.merge.Concatenate'>`. Expected a symbolic tensor instance.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-194-ebff784b774c>", line 1, in <module>
in_ly2_cv_1n1 = Conv2D(32, kernel_size=(1, 1), activation='relu', padding='same')(filt_concat1)
self.assert_input_compatibility(inputs)
str(inputs) + '. All inputs to the layer '
ValueError: Layer conv2d_41 was called with an input that isn't a symbolic tensor. Received type: <class 'keras.layers.merge.Concatenate'>. Full input: [<keras.layers.merge.Concatenate object at 0x1cee082b0>]. All inputs to the layer should be tensors.
回溯(最近一次呼叫最后一次):
K.is_keras_张量(x)
raise VALUERROR('意外发现类型为`'的实例+
str(类型(x))+'`'
ValueError:意外发现类型为“%1”的实例。应为符号张量实例。
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
exec(代码对象、self.user\u全局、self.user\n)
文件“”,第1行,在
在cov2d(32,内核大小=(1,1),activation='relu',padding='same')(filt\u concat1)
self.assert\u输入\u兼容性(输入)
str(输入)+'。层的所有输入'
ValueError:调用层conv2d_41时使用的输入不是符号张量。接收的类型:。完整输入:[]。层的所有输入都应该是张量。
我无法重建您的问题。您的代码对我来说运行良好。
尝试更新keras,然后再次运行。
如果您使用蟒蛇,请执行以下操作:
conda update --all
conda -n root update conda
我认为您需要
连接(axis=-1)([tensor_1,tensor_2])
对@thepartofspeech answers()进行进一步解释
来自keras关于连接层的文档()
keras.layers.Concatenate(轴=-1)
连接输入列表的层
它接受一个张量列表作为输入,除连接轴外,所有张量的形状都相同,并返回一个张量,即所有输入的连接
在这种情况下,层应该直接在连接层上使用
axis=-1
选项调用,后跟输入张量,例如
filt_concat1=串联(轴=-1)([in_ly1_mxcv_1n1,in_ly1_cv_5n5,in_ly1_cv_3n3,k31])
注意:我没有尝试过使用超过2个输入张量,但是在2个输入的情况下,它是有效的
我希望这能有所帮助。谢谢你的回答,内奥米,我用的不是蟒蛇,我用的是PyCharm。你能详细说明一下吗?
conda update --all
conda -n root update conda