[英]Keras - TypeError: Output tensors to a Model must be Keras tensors - while modelling multiple input , multiple output network
我有一個9個2000
維向量序列作為o / p來自2個雙向的lstms。 我正在合並它們以獲得9個4000 dim
向量。
我需要獲得這些4000維向量中的每一個並將它們中的每一個饋送到共享的完全連接層。 我怎樣才能做到這一點? 現在我正在重新整合合並o / p以提供給共享的完全連接層。 但我不知道是否需要這個?
當我嘗試對整個網絡建模以獲取多個i / p並產生多個o / p時,我收到此錯誤,如此鏈接中所述
代碼可以在這里找到。
# 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
>>> merge_cv.shape
TensorShape([Dimension(1), Dimension(None), Dimension(4000)])
>>> cv.shape
TensorShape([Dimension(None), Dimension(9), Dimension(1), Dimension(4000)])
對於最后一行,我遇到了類型錯誤。
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)
所以最后結果證明問題出現在錯誤的列表切片中,最終將None
作為一個層傳遞給一個列表然后合並到一個輸入中。 修復此問題並使切片保持一致 - 問題得以解決。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.