Reputation: 501
I have a (time-expensive) operation that multiple metrics have in common. What would be the best way to share the operation result between the metrics avoiding the overhead of recalculating it each time?
Upvotes: 1
Views: 89
Reputation: 15023
You should create a special class to override tf.keras.callback.Callback()
(thus implement your own callback class) and calculate the metrics that you need by overriding the method on_epoch_end()
.
Then, you can calculate some of your metrics, say, on the validation set, and you thus manually ensure that if you calculate for example TP + FP
, you do use this sum to calculate the precision (TP / (TP + FP)
) rather than recalculating it.
Manually doing so ensures no additional/superfluous computations are made.
Upvotes: 2