Can I send callbacks to a KerasClassifier?

后端 未结 3 723
清歌不尽
清歌不尽 2020-12-31 06:11

I want the classifier to run faster and stop early if the patience reaches the number I set. In the following code it does 10 iterations of fitting the model.



        
3条回答
  •  一个人的身影
    2020-12-31 06:53

    Try:

    estimators.append(('mlp', 
                       KerasClassifier(build_fn=create_model2,
                                       nb_epoch=300,
                                       batch_size=16,
                                       verbose=0,
                                       callbacks=[list_of_callbacks])))
    

    where list_of_callbacks is a list of callbacks you want to apply. You could find details here. It's mentioned there that parameters fed to KerasClassifier could be legal fitting parameters.

    It's also worth to mention that if you are using multiple runs with GPUs there might be a problem due to several reported memory leaks especially when you are using theano. I also noticed that running multiple fits consequently may show results which seem to be not independent when using sklearn API.

    Edit:

    Try also:

    results = cross_val_score(pipeline, X, encoded_Y, cv=kfold, fit_params = {'mlp__callbacks': calls})
    

    Instead of putting callbacks list in a wrapper instantiation.

提交回复
热议问题