keras-cn icon indicating copy to clipboard operation
keras-cn copied to clipboard

keras如何利用callbacks获取模型分类结果向量?

Open dorbodwolf opened this issue 8 years ago • 3 comments

imported by from keras.callbacks import Plotter when I use callbacks in .fit()

model.fit(data, label, batch_size=32, nb_epoch=100, shuffle=True, validation_split=0.2, callbacks=[Plotter(show_plot_window=False, save_to_filepath="/tmp/last_plot.png")])

it's got ImportError who know why is it? I will be appreciate. by dorbodwolf-lanzhou

dorbodwolf avatar Oct 11 '16 02:10 dorbodwolf

@dorbodwolf I didn't see any callback called "Plotter", you must use pre-defined callbacks or define your own callback. If in latter case, pls show your code.

MoyanZitto avatar Oct 11 '16 04:10 MoyanZitto

@MoyanZitto yeah...You are right, it's a pre-defined callback by others, see it here By the way, I have uninstalled the Pinyin Input Method Editors, so I can only type in English. Another question: I want to let model to return classification results(model given class label of validation data or testing data) but I didn't find any trick in keras Model function API. Can I do it by callbacks?

here's my code of callbacks approach I tried:

"""
define a callback class, rewrite on_train_end function
"""
class recordClassficationResult(keras.callbacks.Callback):
    def on_train_end(self, logs={}):
        #do something to return classification results

my_result = recordClassficationResult()
model.fit(data, label, batch_size=32, nb_epoch=6, shuffle=True, validation_split=0.2, callbacks=[my_result])

dorbodwolf avatar Oct 11 '16 06:10 dorbodwolf

@dorbodwolf I've re-read the code about callback, and I'm sorry that for now there are no way to obtain validation data in callbacks thus we cannot manually run .predict after training.

perhaps you need to split validation set by yourself, then use .predict after training.

MoyanZitto avatar Oct 11 '16 12:10 MoyanZitto