python - 在 Keras 神经网络中应用 scipy stats 函数作为层
问题描述
我想在 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 函数支持它。您不能使用其他功能。
推荐阅读
- mongodb - 带有猫鼬或 SQL 的 MongoDB
- java - Java 线程 - 按顺序调用线程
- python - tkinter中图论程序的Python“删除”类ID
- angular - 指令中带有 HostListener 的 FormArray
- php - 在 DriverException.php 第 33 行找不到 Laravel 5.3 接口 Throwable
- php - 为每个项目选择子集
- python - 如何基于“最新”相关模型优化排序
- jquery - 如何根据点击切换项目?
- reactjs - 如何在下一个js中生成构建文件
- android - 使用意图将图像共享到 applock 保险库