Python关闭不是将缩放器的值传递给Keras损耗函数
我使用Python闭合使我能够将其他参数(缩放器值)传递给KERAS自定义损耗函数。这是脚本:
@staticmethod
def sdec_loss(add_loss2):
def loss_function(y_true, y_pred):
print("add_loss2= ", add_loss2)
return losses.kullback_leibler_divergence(y_true, y_pred) - add_loss2
return loss_function
我在一个名为SDEC的类中定义了此Python闭合。然后,我从另一个类称其为以下内容:
self.DEC.loss = SDEC.sdec_loss( add_loss2 )
问题是在内部函数(即loss_function)中未接收缩放器(即add_loss2)的值。无论(ADD_LOSS2)变量所具有的任何值,打印语句输出为0。
I used python Closures to enable me to pass additional argument (a scaler value) to a Keras custom loss function. This is script:
@staticmethod
def sdec_loss(add_loss2):
def loss_function(y_true, y_pred):
print("add_loss2= ", add_loss2)
return losses.kullback_leibler_divergence(y_true, y_pred) - add_loss2
return loss_function
I defined this python closure in a class called SDEC. Then I called it from another class as the following:
self.DEC.loss = SDEC.sdec_loss( add_loss2 )
The problem is that the value of the scaler (i.e. add_loss2) is not received within the inner function (i.e. the loss_function). whatever value the (add_loss2) variable holds, the print statement output is 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论