How to get the number of steps until a certain accuracy in keras?

3

I want to see how many steps does it take for my model to reach a certain accuracy.Say 90 percent on cifar10.How can I get this info from the keras model ?

EDIT: accuracy in each epoch is accessible in history object fit() returns,but im looking for accuracy in each step

Solution:

I made a callback object that keeps loss in each step

import pickle
from tensorflow.keras.callbacks import Callback

class LossHistory(Callback):
    def __init__(self,path='',name=''):
        super(Callback, self).__init__()
        self.path = path
        self.name=name
        self.accuracy = []
        self.losses=[]
    
    def on_batch_end(self, batch, logs={}):
        self.accuracy.append(logs.get('accuracy'))
        self.losses.append(logs.get('loss'))
    
        history_={}
        history_['accuracy']=self.accuracy
        history_['loss']=self.losses
    
        with open(self.path+self.name+'_history.pkl', 'wb') as f:
            pickle.dump(history_,f)

Moeinh77

Posted 2019-08-20T14:11:34.580

Reputation: 103

Answers

0

When you train the model using the .fit() call, it actually returns an object called history. Train the model using history = model.fit(x_train, y_train...) instead and then once training is complete, you can access the history.history dictionary to see this kind of info.

Refer to https://machinelearningmastery.com/display-deep-learning-model-training-history-in-keras/ for more information

Dan Scally

Posted 2019-08-20T14:11:34.580

Reputation: 1 574