【问题标题】:How to enforce a probability distribution on intermediate layer features?如何对中间层特征强制执行概率分布?
【发布时间】:2019-09-13 09:22:52
【问题描述】:

我有一个 CNN-LSTM 架构。现在,我想对中间层的特征实施概率分布,比如混合正态分布。我如何在 Keras 中做到这一点?

我看到了 keras 的 MDN 实现 (https://github.com/cpmpercussion/keras-mdn-layer)。但这要求它应该用作网络的最后一层。另外,我查看了 tensorflow_probability,但我不确定是否可以为此使用 tensorflow_probability 层。

enc.add(LSTM(units=64,activation='tanh',return_sequences=False))

# probability layer
enc.add(tfpl.MixtureNormal(num_classes,[64]))

enc.add(Dense(units=num_classes,activation='softmax'))

当我尝试上面的代码时,它给了我一个错误如下:

tensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found.

  (0) Invalid argument: Number of ways to split should evenly divide the split dimension, but got split_dim 2 (size = 15) and num_split 2
     [[{{node mixture_normal/MixtureSameFamily/independent_normal/IndependentNormal/split}}]]
     [[metrics/categorical_accuracy/Identity/_251]]

  (1) Invalid argument: Number of ways to split should evenly divide the split dimension, but got split_dim 2 (size = 15) and num_split 2
     [[{{node mixture_normal/MixtureSameFamily/independent_normal/IndependentNormal/split}}]]

【问题讨论】:

    标签: tensorflow keras deep-learning tensorflow-probability


    【解决方案1】:

    如果您不需要严格执行分配而是惩罚分歧,您可以考虑使用KLDivergenceRegularizeruse_exact=False

    请注意,大多数 Keras 层都接受 activity_regularizer arg,例如 https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense

    【讨论】:

    • 感谢您的回复。我会试试这个。我看到了一个名为 KLDivergenceAddLoss 的类。它是一个层,而 KLDivergenceRegularizer 是一个可以应用于层的活动正则化器。有什么不同?我可以使用它们中的任何一个来解决我的问题吗?
    • 我尝试了你的建议。但是,我收到了一个错误,这里有详细说明。 github.com/tensorflow/probability/issues/561
    猜你喜欢
    • 1970-01-01
    • 2022-06-27
    • 1970-01-01
    • 2016-04-29
    • 1970-01-01
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多