问题描述
我想在 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)
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 函数支持它。您不能使用其他功能。