6

I am trying to record the status of each epochs used in Keras using callback feature of keras. This is the sample code of callback class

class TimingCallback():
    def __init__(self):
        self.logs=[]
    def on_epoch_begin(epoch, logs={}):
        self.starttime=time()
    def on_epoch_end(epoch, logs={}):
        self.logs.append(time()-self.starttime)

This is my model fit.

cb = TimingCallback()
model.fit(X, Y, epochs=150, batch_size=10, callbacks=[cb])

While executing i get the following error.

Error:

AttributeError: TimingCallback instance has no attribute 'set_model'

Can anyone help me to figure out why exactly this is happening?

1 Answer 1

9

set_model is a method defined in keras.callbacks.Callback. To write a custom callback, you'll have to subclass keras.callbacks.Callback. Otherwise, your callback will lack some necessary methods used by Keras internally.

Changing the first line into the following line should work.

class TimingCallback(keras.callbacks.Callback):
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.