Use layer output in keras custom loss
问题 I am developing a custom loss function in Keras and I need the first layer output. How can I retrieve it? 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 回答1: Checking the docs you can retrieve a layer by using the model.get_layer() method. You can then pass the desired index or well pass the name of the layer. After getting a layer you can easily