Plot loss history

2,510 views
Skip to first unread message

mostaf...@gmail.com

unread,
Aug 24, 2015, 3:05:11 PM8/24/15
to Keras-users
I am trying to plot the loss history. However, when I do:

    net1_log= net1.fit(X_train, Y_train, nb_epoch=3, batch_size=16, show_accuracy=True, callbacks=[History])

I get: 

   NameError: name 'History' is not defined

What should I do?

Al

unread,
Aug 25, 2015, 10:42:32 AM8/25/15
to Keras-users
Do you have:


from keras.callbacks import Callback



and:


history = LossHistory()


Al

unread,
Aug 25, 2015, 10:43:41 AM8/25/15
to Keras-users
I forgot one part:


class LossHistory(Callback):


    def on_train_begin(self, logs={}):


        self.losses = []


    def on_batch_end(self, batch, logs={}):


        self.losses.append(float(logs.get('loss')))




On Monday, August 24, 2015 at 12:05:11 PM UTC-7, Mostapha Benhenda wrote:

Mostapha Benhenda

unread,
Aug 26, 2015, 5:13:08 AM8/26/15
to Keras-users
is this part necessary?


there is already:

class History(Callback):

how can I use it?

Eric Nichols

unread,
Aug 26, 2015, 1:35:05 PM8/26/15
to Mostapha Benhenda, Keras-users
I also was using a locally-defined LossHistory() class in my own work. But the History class looks great; you still need to instantiate an object of that class though. I believe something like this will work:

history = History()
model.fit(...., callbacks=[history])

# And then something like
print history.history
print history.totals



--
You received this message because you are subscribed to the Google Groups "Keras-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keras-users...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/keras-users/2d04be81-5847-4bd6-a7c7-b2e1c8dfce0d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Mostapha Benhenda

unread,
Aug 26, 2015, 5:39:36 PM8/26/15
to Keras-users

thanks, this worked:

from keras.callbacks import History
history = History()
model.fit(X_train, Y_train, nb_epoch=5, batch_size=16, callbacks=[history])


print history.history

Reply all
Reply to author
Forward
0 new messages