Search code examples
pythonmachine-learningkerasdeep-learning

Get values of 'model.fit' keras API parameters


I am trying to get detailed information of the Kera sequential model using a customized callback function. I need to extract all values of the parameters set in model.fit() API such as batch_size, epochs, validation_split, etc. But I could not access them in Keras's callback. Do you have any idea how can I get these values automatically? I am using Python 3.10 and Keras 2.8.


Solution

  • After some research, I found out that I can access all these parameters by writing a Keras callback. Indeed, all the parameters that I needed are available in keras.callbacks class. Here is an example script

    class sample_calback(keras.callbacks.Callback):
        def __init__(self, model):
            super(sample_calback, self).__init__()
    

    When we use this callback in model.fit, parameters can be extracted from self.params dictionary. Hope this will help anybody who wants to do the same job.