【问题标题】:Create Keras / Tensorflow layer that computes 2D DCT创建计算 2D DCT 的 Keras / Tensorflow 层
【发布时间】:2020-02-10 13:21:41
【问题描述】:

我想在我的 CNN 中添加一个计算 de DCT 的层。我已经看到 tensorflow 只有 1D DCT。

如何在网络中间创建一个层,对一批图像执行 DCT。

【问题讨论】:

    标签: tensorflow keras keras-layer


    【解决方案1】:

    转换看起来像这样,您可以将其放置在模型中的任何位置,它会自动转换为操作层。或者,如果您愿意,可以将其包装在 Lambda 层中

    def dct_2d(
            feature_map,
            norm=None # can also be 'ortho'
    ):
        X1 = tf.signal.dct(feature_map, type=2, norm=norm)
        X1_t = tf.transpose(X1, perm=[0, 1, 3, 2])
        X2 = tf.signal.dct(X1_t, type=2, norm=norm)
        X2_t = tf.transpose(X2, perm=[0, 1, 3, 2])
        return X2_t
    

    请记住,在 tensorflow 中,DCT 始终应用于第 -1 轴。所以如果你有一个batch,H,W,channels的特征图,你想转换成batch,channels,H,W。只有这样,上面的转置才是正确的。

    【讨论】:

      猜你喜欢
      • 2015-09-20
      • 1970-01-01
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-25
      • 1970-01-01
      • 2019-07-29
      相关资源
      最近更新 更多