python - 如何在 Keras 中实现 1-sigmoid?

标签 python machine-learning keras deep-learning gated-recurrent-unit

因为我想实现一个类似于GRU更新门的结构:

ht = (1-zt)ht-1 + ztht

我试图用这些代码来实现它,但它不起作用。我确定问题出在以下代码中:

one = K.ones(shape=(1, len, 128))
zt=Subtract([one,zt])
temp_conv2=multiply([reset_conv,zt])
output=Add([temp_conv1,temp_conv2])

我有以下错误:

AttributeError:'Tensor' object has no attribute '_keras_history'

我已经尝试过其他一些方法,例如使用 Lambda 层,但它不起作用。

最佳答案

one 不是 Keras 张量,因此您会收到该错误。您可以将其包装在 Lambda 层中:

zt = Lambda(lambda x: Subtract([K.ones(shape=(1, len, 128)), x]))(zt)

即使你也不需要构造那个张量。只需使用 1-x:

zt = Lambda(lambda x: 1-x)(zt)

它将自动广播,并且减法将按元素进行。

关于python - 如何在 Keras 中实现 1-sigmoid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53503856/

相关文章:

python - 更新 Django 对象

python - Python 中 numpy.random.rand 与 numpy.random.randn 之间的区别

python - 图表中 X 轴上的可变间距

python - 堆叠分类器 : IndexError while fitting the data

tensorflow - 如何在 TensorFlow 中创建多个自定义 AUC 指标,每个输出一个?

python - 神经网络将所有内容分类为一类,在不平衡数据集上召回率=1

Python 断言等于生成器

image - 如何根据图像中的模式信息为图像提供分值?

machine-learning - Python 中随机梯度下降代码的分解

python - 提高 DNN 模型的准确性