在keras自定义损耗中使用层输出

2024-04-20 10:44:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在开发一个自定义的损失函数在Keras和我需要第一层输出。在

我怎样才能找回它?在

def custom_loss(y_true, y_pred):
    cross = K.mean(K.binary_crossentropy(y_true, y_pred), axis = 1)
    layer_output = model.get_layer_output(1) # this is what i'd like to use
    return cross  + perturb

Tags: 函数layertrueoutputdefcustommeankeras
1条回答
网友
1楼 · 发布于 2024-04-20 10:44:07

检查docs可以使用model.get_layer()方法检索层。然后可以传递所需的索引或传递图层的名称。在

在获得一个层之后,您可以通过使用layer.output属性轻松地获得其输出,如文档中的here所述。在

将两者结合,可以获得所需层的输出。在

相关问题 更多 >