微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

应用 scipy stats 函数作为 Keras 神经网络中的一层

如何解决应用 scipy stats 函数作为 Keras 神经网络中的一层

我想在 Keras 神经网络中应用一个 scipy stats 函数作为一个层,如下所示:

from scipy import stats

class BoxCox(layers.Layer):

    def call(self,inputs):
        return stats.Boxcox(inputs)

# part of usage in model
x1 = layers.Dense(81)(x)
x1 = BoxCox()(x1)
x1 = layers.Dropout(0.25)(x1)

stats函数不接受张量存在问题。例如,错误信息是

NotImplementedError: Cannot convert a symbolic Tensor (activation_12/IdentityN:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call,which is not supported

有什么办法可以在神经网络中运行这样的函数作为层吗?

非常感谢帮助。谢谢!

解决方法

层必须支持梯度的反向传播。只有 tensorflow 函数支持它。您不能使用其他功能。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。