gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 15:56:49 25 4
gpt4 key购买 nike

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

...
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)

关于python - Keras:如何在 keras 中实现对层的 o/p 的重新排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42753378/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com