2
$\begingroup$

I am trying to write my own custom metric functions in keras and I wanted to start with a test function so I implemented a f1_score function using sklearn, next I will need to customize the calculation of the metrics according to my evaluation metrics and therefore I want to set a breakpoint inside the custom metric function to further investigate some values and make sure that is being calculated as I am expecting and I have tried to simply set a breatpoint inside the function but the program never stops at the breakpoint, however, if I print something inside the function it gets printed after every batch (every time the function is called) which meant the function is being executed as expected. Here is my test callback function

# metrics call backs
def f1_macro(y_true, y_pred):
    y_true_array = np.squeeze(np.asarray(y_true))
    y_pred_array = np.round(np.squeeze(np.asarray(y_pred)))

    f1 = f1_score(y_true_array, y_pred_array, "macro")
    return f1

Here what I have tried with no success

tf.config.experimental_run_functions_eagerly(True)
tf.config.run_functions_eagerly(True)
tf.data.experimental.enable_debug_mode()

set the run_eagrly flag to true while compile

model.compile(..,run_eagerly=True)

Does anyone know how can I do that ? Thanks in advance

$\endgroup$

1 Answer 1

0
$\begingroup$

I found the solution, using the built-in breakpoint() function as FLAK-ZOSO mentioned here https://stackoverflow.com/questions/69062229/how-to-set-a-breakpoint-inside-a-custom-metric-function-in-keras?noredirect=1#comment122059117_69062229

$\endgroup$
1
  • $\begingroup$ Please add further details to expand on your answer, such as working code or documentation citations. $\endgroup$
    – Community Bot
    Sep 5, 2021 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.