Reputation: 185
I have defined a custom loss function in Keras as follows:
def loss_function_test(yTrue, yPred):
global i
i += 1
print("\n")
print("Loss Function:", i, " ----- ", yTrue, yPred)
print("\n")
res = k.sum(yTrue - yPred)
return res
and set it as follows:
model.compile(loss=loss_function_test,
optimizer='sgd',
metrics=['accuracy'])
The problem is checking the global i
and the print
function in the loss function code, I realize that the function is only called once in training when I call model.fit
. Even when I debug it, it is only called once. It seems that maybe the loss function is only called while compile
. Can anyone explain why?
Upvotes: 1
Views: 299