title: Checkpoint deep learning models in Keras
body: <p>I need help in implementing the checkpoint function in Keras. I am going to train a large dataset so in order to do that, first I trained a model using the iris flower dataset : <a href="http://machinelearningmastery.com/multi-class-classification-tutorial-keras-deep-learning-library/" rel="nofollow noreferrer">http://machinelearningmastery.com/multi-class-classification-tutorial-keras-deep-learning-library/</a></p>
  
  <p>since my own dataset is a lot similar to it only the difference is that my dataset is more bigger.</p>
  
  <p>For the checkpoint function : <a href="http://machinelearningmastery.com/check-point-deep-learning-models-keras/" rel="nofollow noreferrer">http://machinelearningmastery.com/check-point-deep-learning-models-keras/</a></p>
  
  <p>I understand the example using pima-indians dataset. 
  Now I am trying to implement the same checkpoint function in the iris-flower script. Here is what I tried so far.</p>
  
  <pre><code>import numpy
  from pandas import *
  from keras.models import Sequential
  from keras.layers import Dense
  from keras.wrappers.scikit_learn import KerasClassifier
  from keras.utils import np_utils
  from sklearn.model_selection import cross_val_score, KFold
  from sklearn.preprocessing import LabelEncoder
  from sklearn.pipeline import Pipeline
  from keras.callbacks import ModelCheckpoint
  
  seed = 7
  numpy.random.seed(seed)
  
  dataframe = read_csv("iris.csv", header=None)
  dataset = dataframe.values
  X = dataset[:,0:4].astype(float)
  Y = dataset[:,4]
  
  # encode class value as integers
  encoder = LabelEncoder()
  encoder.fit(Y)
  encoded_Y = encoder.transform(Y)
  dummy_y = np_utils.to_categorical(encoded_Y)
  
  def baseline_model():
      model = Sequential()
      model.add(Dense(4, input_dim=4, init='normal', activation='relu'))
      model.add(Dense(3, init='normal', activation='sigmoid'))
      model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
      return model
  
  filepath="weights-improvement-{epoch:02d}-{val_acc:.2f}.hdf5"
  checkpoint = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')
  callbacks_list = [checkpoint]
  
  estimator = KerasClassifier(build_fn=baseline_model, validation_split=0.33, nb_epoch=200, batch_size=5, callbacks=callbacks_list, verbose=0)
  kfold = KFold(n_splits=10, shuffle=True, random_state=seed)
  results = cross_val_score(estimator, X, dummy_y, cv=kfold)
  print("Baseline: %.2f%% (%.2f%%)" % (results.mean()*100, results.std()*100))
  </code></pre>
  
  <p>This script produced the following error. I don't know how to troubleshoot it or maybe my arrangement in the script is wrong.</p>
  
  <pre><code>RuntimeError: Cannot clone object &lt;keras.wrappers.scikit_learn.KerasClassifier object at 0x10e120fd0&gt;, as the constructor does not seem to set parameter callbacks
  </code></pre>
  
  <p>I hope somebody can help me with this. Thank you.</p>