Keras TypeError:在建模多输入、多输出n时,模型的输出张量必须是Keras张量

2024-09-27 00:22:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个九2000维向量序列,作为2个双向lstms的o/p。我合并它们得到九个向量。在

我需要得到这些4000维向量的每一个,并将它们输入到共享的完全连接层中。 我该怎么做? 现在我正在重塑合并o/p,以提供到共享的完全连接层。但我不知道这是否需要?在

当我试图对整个网络进行建模以获取多个I/p并生成多个o/p时,我遇到了这个错误,如本文link

可以找到代码here。在

# we can then concatenate the two vectors:
N=3
merge_cv = merge([top_out, btm_out], mode='concat')#concat_axis=2 or -1 (last dim axis)
cv = Reshape((9,1, 4000))(merge_cv) # we want 9 vectors of dimension 4000 each for sharedfc_out below

#number of output classes per cell
n_classes = 80
sharedfc_out= Dense(output_dim=n_classes,input_dim=4000,activation='relu')
#partial counts
#pc = np.ndarray(shape=(1,n_classes), dtype=float) 
#cells_pc = np.array([[pc for j in range(N)] for i in range(N)])
outpc=[]

for i in range(N):
    for j in range(N):
        # cells_pc[i][j] = sharedfc_out(cv[N*i+j])
        outpc.append(sharedfc_out(cv[0][N*i+j]))

# out=merge(outpc,mode='concat')
# out2=Reshape(720)(out)

model = Model(input=cells_in, output=outpc)

bi=lstm o/p尺寸

^{pr2}$

对于最后一行,我得到了类型错误。在

TypeError                                 Traceback (most recent call last)
 in ()
----> 1 model = Model(input=cells_in, output=outpc)

/home/jkl/anaconda3/lib/python3.5/site-packages/keras/engine/topology.py in __init__(self, input, output, name)
   1814                 cls_name = self.__class__.__name__
   1815                 raise TypeError('Output tensors to a ' + cls_name + ' must be '
-> 1816                                 'Keras tensors. Found: ' + str(x))
   1817         # Build self.output_layers:
   1818         for x in self.outputs:

TypeError: Output tensors to a Model must be Keras tensors. Found: Tensor("Relu_9:0", shape=(1, 80), dtype=float32)

Tags: nameinselfforinputoutputrangemerge
1条回答
网友
1楼 · 发布于 2024-09-27 00:22:32

最后发现问题出在错误的列表切片上,最终将None作为一个层传递给一个列表,然后将其合并到一个输入中。经过修复,使切片一致-问题得到解决。在

相关问题 更多 >

    热门问题