Keras:如何在 keras 中实现层的 o/p 的重新排序?

Keras: How to implement reordering for o/p of a layer in keras?

我有九个 500 维向量作为 o/p 来自合并层和重塑层的组合:

...
N=3
merge_rf=merge(cells_rf,mode='concat')
rf_top = Reshape((N*N, 500))(merge_rf)
#proper reordering code here - TODO

...

>>> rf_top.shape 
TensorShape([Dimension(None), Dimension(9), Dimension(500)])

我需要使用已知映射

rf_top 中的这些 (9, 500) 昏暗向量重新排序
eg - (0,1,2,3,4,5,6,7,8) to -> (0,1,2,5,4,3,6,7,8) for rf_top

为此我应该使用哪个 keras 层?以及如何做?

尝试使用:

reorder_top = merge([Lambda(lambda x: x[:, index, :], 
    output_shape = (1, 500))(rf_top) for index in permutation], 
    mode='concat', concat_axis=1)

其中 permutation 是您要根据其排列图层的排列。这一层的输出是扁平化的,所以你应该reshape它:

reorder_top = Reshape ((N*N, 500))(reorder_top)