Skip to content

Commit

Permalink
feat(Utils): Added utility function for parsing CSVLogger fitting fil…
Browse files Browse the repository at this point in the history
…e to fitting dictionary
  • Loading branch information
muellerdo committed May 29, 2022
1 parent 2200ed3 commit 32a43d1
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions aucmedi/utils/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# Library imports #
#-----------------------------------------------------#
from tensorflow.keras.callbacks import EarlyStopping
import pandas as pd

#-----------------------------------------------------#
# Custom Callbacks #
Expand Down Expand Up @@ -67,3 +68,26 @@ def __init__(self, monitor='val_loss', min_delta=0, patience=0, verbose=0,
def on_epoch_end(self, epoch, logs=None):
if epoch > self.start_epoch:
super(MinEpochEarlyStopping, self).on_epoch_end(epoch, logs)

#-----------------------------------------------------#
# Callback Utils #
#-----------------------------------------------------#
def csv_to_history(input_path):
""" Utility function for reading a CSV file from the
[CSVLogger](https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/CSVLogger)
Callback and return a History dictionary object.
Can be utilized in order to pass returned dictionary object to the
[evaluate_fitting()][aucmedi.evaluation.fitting] function of the AUCMEDI
[evaluation][aucmedi.evaluation] submodule.
Args:
input_path (str): Path to a CSV file generated by a CSVLogger Callback.
Returns:
history (dict): A history dictionary from a Keras history object which contains several logs.
"""
# Read logging data
dt = pd.read_csv(input_path, sep=",")
# Parse to dict and return results
return dt.to_dict(orient="list")

0 comments on commit 32a43d1

Please sign in to comment.