【问题标题】:Keras: How to implement reordering for o/p of a layer in keras?Keras:如何在 keras 中实现层的 o/p 重新排序?
【发布时间】:2017-08-02 20:43:56
【问题描述】:

我有九个 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 层?以及怎么做?

【问题讨论】:

    标签: python neural-network deep-learning keras keras-layer


    【解决方案1】:

    尝试使用:

    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)
    

    【讨论】:

      猜你喜欢
      • 2021-12-18
      • 2019-09-03
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 2019-02-17
      • 1970-01-01
      • 2019-09-02
      • 1970-01-01
      相关资源
      最近更新 更多