Path: blob/master/examples/keras_recipes/md/endpoint_layer_pattern.md
3508 views
Endpoint layer pattern
Author: fchollet
Date created: 2019/05/10
Last modified: 2023/11/22
Description: Demonstration of the "endpoint layer" pattern (layer that handles loss management).
Setup
Usage of endpoint layers in the Functional API
An "endpoint layer" has access to the model's targets, and creates arbitrary losses in call()
using self.add_loss()
and Metric.update_state()
. This enables you to define losses and metrics that don't match the usual signature fn(y_true, y_pred, sample_weight=None)
.
Note that you could have separate metrics for training and eval with this pattern.
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR I0000 00:00:1700705222.380735 3351467 device_compiler.h:186] Compiled cluster using XLA! This line is logged at most once for the lifetime of the process.
32/32 ━━━━━━━━━━━━━━━━━━━━ 2s 31ms/step - loss: 0.3663 Epoch 2/2 32/32 ━━━━━━━━━━━━━━━━━━━━ 0s 2ms/step - loss: 0.3627
<keras.src.callbacks.history.History at 0x7f13401b1e10>
<keras.src.callbacks.history.History at 0x7f132c1d1450>