Keras throws `'Tensor' object has no attribute '_keras_shape'` when splitting a layer output

后端 未结 1 864
别那么骄傲
别那么骄傲 2021-01-22 08:51

I have sentence embedding output X of a sentence pair of dimension 2*1*300. I want to split this output into two vectors of shape 1*300 to calculate i

相关标签:
1条回答
  • 2021-01-22 09:37

    Keras adds some info to tensors when they're processed in layers. Since you're splitting the tensor outside layers, it loses that info.

    The solution involves returning the split tensors from Lambda layers:

    x_A = Lambda(lambda x: x[:,0], output_shape=notNecessaryWithTensorflow)(x)
    x_B = Lambda(lambda x: x[:,1], output_shape=notNecessaryWithTensorflow)(x)
    x_A = Reshape((1,EMBEDDING_DIM))(x_A)
    x_B = Reshape((1,EMBEDDING_DIM))(x_B)
    
    0 讨论(0)
提交回复
热议问题